akhauriyash/Code-Regression huggingface dataset:
#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;

const int N=3e5+5;

ll a[N],k,n;

int main()
{ios_base::sync_with_stdio(false);
cin>>n>>k;
rep(i,0,n-1)cin>>a[i];
sort(a,a+n);
reverse(a,a+n);
ll ans=0;
rep(i,k,n-1)
{
	ans+=a[i];
}
ol(ans);
return 0;
}



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

#define ll long long
#define ull unsigned long long
#define mod 998244353
#define INF 1 << 30
#define MAX (1 << 20)
#define NINF (-(1 << 30))
#define triplet pair<pair<int, int>, int>

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

    bool x;

    cin >> x;

    cout << (!x) << endl;

    return 0;
}


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

int main () {
  int a, b;
  cin >> a >> b;
  a = a % 2;
  b = b % 2;
  if (( a == 0 || b == 0 )) {
    cout << "Even" << endl;
  }
  else {
    cout << "Odd" << endl;
  }
}


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

int main()
{
  int N;
  cin >> N;
  int d[N] = {};
  for (int i = 0; i < N; ++i)
  {
    cin >> d[i];
  }

  int ans = 1;
  sort(d, d + N);
  for (int i = 0; i < N - 1; ++i)
  {
    if (d[i] < d[i + 1])
    {
      ans++;
    }
  }
  cout << ans << endl;
}

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


int main() {
  
  int N,D;
  cin >> N >> D;

  vector<vector<int>> X(N,vector<int> (D));
  for(int i = 0;i < N;i++) {
      for(int j = 0;j < D;j++) {
          cin >> X.at(i).at(j);
      }
  }
    int ans = 0;
  for(int i = 0;i < N - 1;i++) {
      for(int j = i + 1;j < N;j++) {

          double dis,sum = 0;
        for(int k = 0;k < D;k++) {
            sum += (X.at(i).at(k) - X.at(j).at(k)) * (X.at(i).at(k) - X.at(j).at(k));
        }

          dis = sqrt(sum);
          if(dis - (int)dis == 0) ans++;
      }
  }

    cout << ans << endl;
  

  
}



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

const string YES = "Yes";
const string NO = "No";

void solve(long long H, long long N, std::vector<long long> A){
    ll sum = accumulate(A.begin(), A.end(),0LL);
    if(sum < H){
        cout<<NO<<endl;
    }else{
        cout<<YES<<endl;
    }
}

int main(){
    long long H;
    scanf("%lld",&H);
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(H, N, std::move(A));
    return 0;
}


Measured memory_bytes: 1024
import math

N = int(input())

x_min = math.floor(N / 1.08)
x_max = (N + 1) / 1.08

x_list = [x_min, x_min + 1]
for x in x_list:
    if math.floor(x * 1.08) == N:
        print(x)
        exit()
print(':(')

Measured memory_bytes: 3060
#include <iostream>
#include <deque>
using namespace std;
typedef long long int ll;
deque<ll>A;
void push(ll a, ll b) {
	if (a == 0) A.push_front(b);
	else A.push_back(b);
}
void randomaccess(ll p) {
	cout << A.at(p) << endl;
}
void pop(ll d) {
	if (d == 0) A.pop_front();
	else A.pop_back();
}
int main() {
	ll Q; cin >> Q;
	ll x, d;
	for (ll i = 0; i < Q; i++) {
		cin >> x;
		if (x == 0) {
			ll b; cin >> d >> b;
			push(d, b);
		}
		else if (x == 1) {
			cin >> d;
			randomaccess(d);
		}
		else {
			cin >> d;
			pop(d);
		}
	}
}


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

using namespace std;
typedef long long LL;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<pair<int, int>> v;
    int cnt = 1, mx = 0;
    for(int i = 0; i < n; i++){
        int d1, d2;
        cin >> d1 >> d2;
        v.push_back(make_pair(d1, d2));
        if(i > 0 && v[i].first == v[i].second && v[i-1].first == v[i-1].second){
            cnt++;
            mx = max(mx, cnt);
        }
        else cnt = 0;
    }
    if(mx+1 >= 3) cout << "Yes";
    else cout << "No";
    return 0;
}

Measured memory_bytes: 3652
import collections
import itertools
import numpy as np
import sys
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

def gcd(a,b):
    while b % a:
        a,b = b, a % b
    return a

A,B,K = IL()

cnt = 0
i = min(A,B)
while True:
    if A%i==0 and B%i==0:
        cnt += 1
    if cnt == K:
        print(i)
        break
    i -= 1


Measured memory_bytes: 12496
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n,m;
	cin>>n>>m;
	string s[n];
	for(int i=0;i<n;i++)
	{
		cin>>s[i];
	}
	for(int i=0;i<n;i++)
	{
		int p=s[i].find(".");
		//cout<<p<<endl;
		if(p==-1)	continue;
		if(i==0)
		{
			for(int k=p;k<m;k++)
			{
				if(s[i][k]!='.')	continue;
				p=k; 
				int f=-1;
				for(int j=i+1;j<n;j++)
				{
					if(!(s[j][p]=='.'||s[j][p]=='1'))
					{
						f=1;
						break;
					}
				}
				if(f==-1)
				{
					for(int j=0;j<n;j++)
					{
						s[j][p]='1';
					}
				}
			}
		}
		p=0;
		for(int j=0;j<m;j++)
		{
			if(!(s[i][j]=='1'||s[i][j]=='.'))
			{
				p=-1;
				break;
			}
		}
		if(p!=-1&&(s[i][0]=='.'||s[i][0]=='1'))
		{
			for(int j=0;j<m;j++)
			{
				s[i][j]='1';
			}
		}
	}
	for(int i=0;i<n;i++)
	{
		int u=0;
		for(int j=0;j<m;j++)
		{
			if(s[i][j]!='1')
			{
				u++;
				cout<<s[i][j];
			}
		}
		if(u!=0)	cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> P;
const int maxn = 100050;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const ll linf = 7e18;
ll power(ll x, ll y)
{
    ll ans = 1;
    while (y)
    {
        if (y & 1)
            ans = ans * x % mod;
        x = x * x % mod;
        y >>= 1;
    }
    return ans;
}

ll gcd(ll x, ll y)
{
    if (x % y == 0)
        return y;
    return gcd(y, x % y);
}

unordered_map<ll, ll> mp;
vector<P> v;
ll a, b, c, d;

ll dfs(ll x)
{
    if (mp.find(x) != mp.end())
        return mp[x];
    //cout << x << "\n";
    ll res = linf;
    if (ld(d) * ld(x) < res)
        res = d * x;
    for (auto p : v)
    {
        ll num = p.first, cost = p.second;
        res = min(res, dfs(x / num) + cost + d * (x % num));
        if (x % num != 0)
            res = min(res, dfs(x / num + 1) + cost + d * (num - x % num));
    }
    return mp[x] = res;
}

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int t;
    cin >> t;
    while (t--)
    {
        ll n;
        cin >> n >> a >> b >> c >> d;
        mp.clear();
        v.clear();
        v.push_back(P(2, a));
        v.push_back(P(3, b));
        v.push_back(P(5, c));
        mp[0] = 0;
        mp[1] = d;
        cout << dfs(n) << "\n";
    }
    return 0;
}


Measured memory_bytes: 4008
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <sstream>
#include <climits>
#include <cfloat>
#include <complex>

const double Eps = 1e-8;
const double PI = 4*atan(1.0);
double to_radian(double degree)
{
	return degree*PI/180;
}
using namespace std;

int main()
{
	const double Radius = 6378.1;
	double a[2], b[2];
	while (scanf("%lf %lf %lf %lf", a, b, a+1, b+1), *b >= 0)
	{
		double x[2], y[2], z[2];
		for (int i = 0; i < 2; ++i)
		{
			a[i] = to_radian(a[i]);
			b[i] = to_radian(b[i]);
			x[i] = cos(a[i])*cos(b[i]);
			y[i] = cos(a[i])*sin(b[i]);
			z[i] = sin(a[i]);
		}
		double cs = (x[0]*x[1]+y[0]*y[1]+z[0]*z[1]);
		double angle = acos(cs);
		double ans = Radius * angle + 0.5 + Eps;

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

	return 0;
}

Measured memory_bytes: 0
import sys
from collections import deque  # 双方向キュー
from collections import defaultdict  # 初期化済み辞書
from heapq import heapify, heappush, heappop, heappushpop  # プライオリティキュー
from bisect import bisect_left, bisect_right  # 二分探索
#import numpy as np  # 1.8.2
#import scipy  # 0.13.3
#sys.setrecursionlimit(int(1e+6))
s2nn = lambda s: [int(c) for c in s.split(' ')]
ss2nn = lambda ss: [int(s) for s in ss]
ss2nnn = lambda ss: [s2nn(s) for s in ss]
i2s = lambda: sys.stdin.readline().rstrip()
i2n = lambda: int(i2s())
i2nn = lambda: s2nn(i2s())
ii2ss = lambda n: [sys.stdin.readline().rstrip() for _ in range(n)]
ii2sss = lambda n: [list(sys.stdin.readline().rstrip()) for _ in range(n)]
ii2nn = lambda n: ss2nn(ii2ss(n))
ii2nnn = lambda n: ss2nnn(ii2ss(n))
MOD = int(1e+9) + 7

def main():
    N = i2n()
    A = i2nn()
    A.sort()
    n = 0
    for i in range(1, N, 2):
        t = A[i-1] + A[i]
        if t < 0:
            t = -t
        n += t
    if N % 2 == 1:
        n += A[-1]
    print(n)

main()


Measured memory_bytes: 59740
#include<iostream>
using namespace std;
#define MAX 100000

typedef struct Process_ {
  char name[10];
  int tm;
} Process;


int head, tail;
Process P[MAX];

void enqueue(Process pc) {
  P[tail] = pc;
  tail = (tail+1)%MAX;
}

Process dequeue() {
  Process pc = P[head];
  head = (head+1)%MAX;
  return pc;
}

int min(int a, int b) {
  if (a<b) {
    return a;
  } else {
    return b;
  }
}

int main() {
  int N, qt, a;
  Process q;
  int elapse = 0;

  cin >> N >> qt;
  for (int i=0; i<N; i++) {
    cin >> P[i].name >> P[i].tm;
  }
  head = 0;
  tail = N;

  while (head != tail) {
    q = dequeue();
    a = min(q.tm, qt);
    q.tm = q.tm - a;
    elapse += a;
    if (q.tm>0) {
      enqueue(q);
    } else {
      cout << q.name << " " << elapse << endl;
    }
  }


  return 0;

}



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

int main(){
    int i,j,flag=0,n,h[21];
    int ans=1;

    cin >> n;

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

    for (i = 1; i < n; i++){

        for (j = i-1; j >= 0; j--){
            if(h[i]<h[j]){
                flag=0;
                break;
            }
            flag=1;
        }
        if (flag){
            ans++;
        }
        
    }
    
    cout << ans  <<endl;
    return 0;
}


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

char s[N];
int t[256];
ll cev;

int main() {

  scanf("%s",s+1);
  int n=strlen(s+1);
  for(int i=1;i<=n;i++) {
    t[s[i]-'a']++;
  }
  ll cev=1ll*n*(n-1)/2+1;
  for(int i=0;i<26;i++) {
    cev-=1ll*t[i]*(t[i]-1)/2;
  }
  printf("%lld",cev);

}


Measured memory_bytes: 384
#!/usr/bin/env python
# coding: utf-8

# In[40]:


K = int(input())


# In[44]:


if K%2 == 0 or K%5 == 0:
    print(-1)
else:
    if K%7 == 0:
        L = 9*K//7
    else:
        L = 9*K
    ans = -1
    tmp = 0
    for i in range(1,K+1):
        if (10*tmp+9)%L == 0:
            ans = i
            break
        else:
            tmp = (10*tmp+9)%L
    print(ans)


# In[ ]:






Measured memory_bytes: 62972
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
using namespace std;

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

const double PI=acos(-1.0);

int N;
void input()
{
    cin>>N;
}

void solve()
{
    map<int,int> M;
    for(int x=1;x*x<=N;++x){
        for(int y=1;y*y<=N;++y){
            for(int z=1;z*z<=N;++z){
                M[x*x+y*y+z*z+x*y+y*z+z*x]++;
            }
        }
    }
    for(int i=1;i<=N;++i){
        cout<<M[i]<<endl;
    }
}

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

Measured memory_bytes: 5392
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		var sc = new Scanner(System.in);
		var n = sc.nextInt();
		var v = new int[n][3];
		for (var i = 0; i < n; i++) {
			v[i][0] = sc.nextInt();
			v[i][1] = sc.nextInt();
			v[i][2] = sc.nextInt();
		}
		sc.close();

		for (var i = 0; i <= 101 * 101; i++) {
			var x = i / 101;
			var y = i % 101;
			var h = Integer.MAX_VALUE;
			for (var j = 0; j < n; j++) {
				h = Math.min(h, Math.abs(v[j][0] - x) + Math.abs(v[j][1] - y) + v[j][2]);
			}
			for (var j = 0; j < n; j++) {
				if (v[j][2] != Math.max(h - Math.abs(v[j][0] - x) - Math.abs(v[j][1] - y), 0)) {
					h = 0;
					break;
				}
			}
			if (h > 0) {
				System.out.printf("%d %d %d\r\n", x, y, h);
				break;
			}
		}
	}
}

Measured memory_bytes: 36980
x=int(input())
 
if x<100:
	print("0")
	exit()

while 1:
	tm=(str(x)[-2:])
	if int(tm) > 5:
		x-=105
	else:
		print("1")
		exit()
		
	if x<100:
		print("0")
		exit()

Measured memory_bytes: 3060
import java.lang.reflect.Array;
import java.util.*;

/**
 * Created by Santa.
 */
public class Main {

  static int N;
  static int K;
  static long Q;
  static int A;
  static long B;
  static long C;
  // static int[][] map;
  static double min = 9999999;
  static long ans = 0;

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

    int N = scanner.nextInt();
    int[][] map = new int[N][3];

    map[0][0] = scanner.nextInt();
    map[0][1] = scanner.nextInt();
    map[0][2] = scanner.nextInt();

    for (int i = 1; i < N; i++) {
      int temp = scanner.nextInt();
      map[i][0] = Math.max(map[i - 1][1] + temp, map[i - 1][2] + temp);

      temp = scanner.nextInt();
      map[i][1] = Math.max(map[i - 1][0] + temp, map[i - 1][2] + temp);

      temp = scanner.nextInt();
      map[i][2] = Math.max(map[i - 1][0] + temp, map[i - 1][1] + temp);
    }

    int max;
    max = Math.max(map[N - 1][0], map[N - 1][1]);
    max = Math.max(map[N - 1][2], max);
    System.out.println(max);

  }
}


Measured memory_bytes: 97360
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>

using namespace std;


void solve() {
    int N; cin >> N;
    vector<int> v(N);

    for (int i = 0; i < N - 1; i++) {
        int a; cin >> a;
        a--;
        v[a]++;
    }

    for (int i = 0; i < N; i++) {
        cout << v[i] << endl;
    }
}


int main() {
    solve();
    return 0;
}

Measured memory_bytes: 3976
#include<iostream>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
using namespace std;

int main(){
	int n,x;
	cin>>n>>x;
	int m[n];
	int ans=n,num=10000;
	rep(i,n){
		cin>>m[i];
		x-=m[i];
		if(m[i]<num)num=m[i];
	}
	cout<<ans+x/num<<endl;
	return 0;
}

Measured memory_bytes: 256
var inputRaw = require('fs').readFileSync('/dev/stdin', 'utf8')
var rows = inputRaw.trim().split('\n');
var row1 = rows[0].split(' ').map(Number);
var N = row1[0];
var W = row1[1];
var list = rows.slice(1).map(r => r.split(' ').map(Number));
var dp = Array.from({ length: N + 1 }, _ => Array(W + 1).fill(0));

function solve() {

  for (var i = 0; i < N; i++) {
    for (var j = 0; j <= W; j++) {
      if (list[i][0] <= j) {
        var a = dp[i][j - list[i][0]] + list[i][1];
        var b = dp[i][j];
        dp[i + 1][j] = Math.max(a, b);
      } else {
        dp[i + 1][j] = dp[i][j];
      }
    }
  }
  return dp[N][W];
}

console.log(solve());


Measured memory_bytes: 187036
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int h,n;
  cin >>h >>n;
  vi a(n);
  int sumA = 0;
  rep(i,n) cin >> a[i];
  rep(i,n) sumA+=a[i];

  if(h <= sumA)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 640
//#pragma GCC optimize ("-O3","unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define pb(a) push_back
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), n)
#define ub(v,n) upper_bound(v.begin(), v.end(), n)
#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")

template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7; const int MAX = 200020;
const double pi = acos(-1); const double EPS = 1e-12;
const ll INF = 2e18;


void solve() {
	string S; cin >> S;
	map<string, int>mp;
	mp["SUN"] = 0;
	mp["MON"] = 1;
	mp["TUE"] = 2;
	mp["WED"] = 3;
	mp["THU"] = 4;
	mp["FRI"] = 5;
	mp["SAT"] = 6;
	int ans = 7-mp[S];
	print(ans);
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//test();
	solve();
}

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

int main(void){
  ll n, k;
  cin >> n >> k;
  vector<vector<ll>> s(n);
  REP(i, n){
    ll t, d;
    cin >> t >> d;
    s[t-1].emplace_back(d);
  }
  REP(i, n){
    sort(ALLr(s[i]));
    if(s[i].empty()) s[i].emplace_back(-INF);
  }
  sort(ALL(s), [&](vector<ll> a, vector<ll> b){return a[0] > b[0];});         
  
  ll cur = 0;
  priority_queue<ll> q;
  REP(i, k){
    cur += s[i][0];
    FOR(j, 1, s[i].size()) q.push(s[i][j]);
  }
  FOR(i, k, n) REP(j, s[i].size()) q.push(s[i][j]);

  ll ans = cur + k*k;
  FORr(i, k, 0){
    ll v = s[i][0];
    ll w = q.top();
    if(v < w){
      q.pop();
      cur += w;
      cur -= v;
      q.push(v);
    }
    chmax(ans, cur + (ll)i*i);
  }

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

Measured memory_bytes: 8696
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>
#include <string>
#define rep(i, n) for (int i = 0; i < n; i++) 

using namespace std;

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

    while (1) {
        c -= b;
        if (c <= 0) {
            cout << "Yes" << endl;
            break;
        }
        a -= d;
        if (a <= 0) {
            cout << "No" << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 3588
//ΔARC090A
#include<iostream>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef long long LL;
typedef double DB;
int n,a[111][111];
int main()
{
	int i,j;
	cin>>n;
	for(i=1;i<=2;i=i+1)
		for(j=1;j<=n;j=j+1)
			cin>>a[i][j],a[i][j]+=max(a[i][j-1],a[i-1][j]);
	cout<<a[2][n]<<endl;
	return 0;
}

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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

    char s[123123];
    Scs(s);
    int N = strlen(s);
    int cnt[26] = {};
    for_each(s,s+N,[&](char c){cnt[c-'a']++;});
    auto it = find(cnt,cnt+26,0);
    if( it == cnt+26 ) printf ("None\n" );
    else printf ("%c\n", 'a' + (it-cnt) );

    return 0;
}



Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s,ans = "";
	cin >> s;
	for(int i= 0;i<s.length();i+=2){
		ans+=s[i];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 576
using System;
using System.Collections.Generic;
using System.Text;

namespace AtCoder.ABC._14X._142
{
    class A
    {
        public static void Main()
        {
            double d = double.Parse(Console.ReadLine());
            int a = (int)d;
            Console.WriteLine((a+1)/2/ d);

    }
    }
}


Measured memory_bytes: 27604
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define yesno(flg) if(flg){cout<<"YES"<<endl;}else{cout<<"NO"<<endl;}
#define MAX_N 1002
#define i197 1000000007

using namespace std;

typedef long long ll;
typedef pair<int,ll> Pil;
typedef pair<int,int> Pi;
typedef pair<double,Pi> Pdi;
typedef pair<ll,int>Pli;
typedef pair<ll,ll> Pl;
typedef pair<Pil,ll> P2;
const ll INF=1000000000000000001;
const int inf=1000000000;
//struct edge{int to,cost;};
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
struct Road{double cost;int a,b;};

int main(){

	int a,b;
	cin>>a>>b;
	if(b%a==0)cout<<a+b<<endl;
	if(b%a>0)cout<<b-a<<endl;

	return 0;
}


Measured memory_bytes: 256
import Control.Applicative
import Control.Monad
import Data.List

main = do
  [n,m] <- map read.words<$>getLine
  unless (n == 0 && m == 0) $ do
    ans <- replicateM n $ map read.words<$>getLine
    putStrLn.unwords.map (show.fst).sortBy (\x y -> compare (snd y) (snd x)).addUp $ ans
    main

addUp :: [[Int]] -> [(Int, Int)]
addUp = zip [1..].foldl1 (zipWith (+))

Measured memory_bytes: 17444
#include<stdio.h>
int main(){
  int n;
  scanf("%d",&n);
  int a[n],b[n];
  for(int i = 0;i < n;i++){
    scanf("%d",&a[i]);
    a[i]--;
    if(a[i] > i){
      printf("-1\n");
      return 0;
    }
  }
  for(int i = 0;i < n;i++){
    for(int j = i;j > a[i];j--){
      b[j] = b[j - 1];
    }
    b[a[i]] = a[i];
  }
  for(int i = 0;i < n;i++){
    printf("%d\n",b[i] + 1);
  }
  return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder.Abc
{
    class A_160Coffee
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 文字列の入力
            string S = Console.ReadLine();
            string result = "";
            if (S.Substring(2,1) == S.Substring(3,1) && S.Substring(4,1) == S.Substring(5,1))
            {
                result = "Yes";
            }
            else
            {
                result = "No";
            }

            Console.WriteLine(result);

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 25788
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define int long long
#define pb push_back
#define eb emplace_back
#define mp make_pair
const int MOD=1e9+7;
const int INF=1e15;

signed main(){
    string S;cin>>S;
    int N=S.size();
    vector<vector<int>>dp(N+1,vector<int>(13,0));
    REPS(i,N){
        int d=S[i-1]-'0';
        if(i==1){
            if(S[0]!='?')dp[1][d]++;
            else{
                REP(i,10)dp[1][i]++;
            }
        }
        else{
            if(S[i-1]!='?'){
                REP(j,13){
                    dp[i][(j*10+d)%13]+=dp[i-1][j];
                    dp[i][(j*10+d)%13]%=MOD;
                }
            }
            else{
                REP(dz,10){
                    REP(j,13){
                        dp[i][(j*10+dz)%13]+=dp[i-1][j];
                        dp[i][(j*10+dz)%13]%=MOD;
                    }
                }
            }  
        }
    }
    cout<<dp[N][5]<<endl;
}

Measured memory_bytes: 13696
//q4.cpp

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#define debug(x) cerr << #x << " = " << x << endl;


#define mod 1000000007 //1e9+7
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 100010

int sum[20][SIZE] = {};
int cc[20] = {};
int dp[1 << 20];

int main(){
  int n,m;
  int a;
  
  scanf("%d%d",&n,&m);

  for(int i=1;i<=n;i++){
    scanf("%d",&a);
    a--;
    sum[a][i]++;
    cc[a]++;
  }

  for(int i=0;i<n;i++){
    for(int j=0;j<m;j++)
      sum[j][i+1] += sum[j][i];
  }

  for(int i=0;i<(1<<m);i++){
    dp[i] = -INF;
  }
  dp[0] = 0;
  
  for(int i=0;i<(1<<m);i++){
    int l = 0,r;

    for(int j=0;j<m;j++){
      if((i>>j) & 1) l += cc[j];
    }

    for(int j=0;j<m;j++){
      if((i>>j) & 1) continue;

      r = l + cc[j];
      
      int add = sum[j][r] - sum[j][l];

      dp[(1 << j)+i] = max(dp[(1<<j)+i], dp[i]+add);
    }
  }

  printf("%d\n",n - dp[(1<<m)-1]);
  
  return 0;
}

Measured memory_bytes: 15072
#include <bits/stdc++.h>
#include <unordered_map> 
using namespace std; 
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define PI1 3.14159265358979311599796346854418516159057617187500

typedef long long int ll;  
ll MOD = 1e9 + 7;


int main() 
{ 
    FIO
    int t;
    t = 1;
    while(t--)
    {
        int n;
        cin >> n;

        if((n%10)==2 || (n%10)==4 || (n%10)==5 || (n%10)==7 || (n%10)==9)
        {
            cout << "hon" << endl;
        }
        else if((n%10)==0 ||(n%10)==1 ||(n%10)==6 ||(n%10)==8)
        {
            cout << "pon" << endl;
        }
        else
        {
            cout << "bon" << endl;
        }
    }
    return 0; 
}

Measured memory_bytes: 3632
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<vector>
#include<array>
#include<string>
#include<stack>
#include<queue>
#include<algorithm>
#include<cassert>
#include<functional>
#include<random>
#define int long long
#define REP(i, a, b) for (long long i = (long long)(a); i < (long long)(b); i++)
#define rep(i, a) REP(i, 0, a)
#define EACH(i, a) for (auto i: a)
#define ITR(x, a) for (auto x = a.begin(); x != a.end(); x++)
#define ALL(a) (a.begin()), (a.end())
#define HAS(a, x) (a.find(x) != a.end())
#define mp(x,y) make_pair((x),(y))
using namespace std;

template<int MAX>class Eratosthenes {
private:
	const int LENGTH = (MAX / 64) + 1;
	const long long one = 1;
	vector<long long>isPrimeTable;

public:
	Eratosthenes() :isPrimeTable(LENGTH, 0) {
		vector<long long>isKnownTable(LENGTH, 0);
		for (int i = 2; i <= MAX; i++)
		{
			if (!(isKnownTable[i / 64] & (one << (i % 64)))) {
				isKnownTable[i / 64] |= (one << (i % 64));
				isPrimeTable[i / 64] |= (one << (i % 64));
				for (int j = i * 2; j <= MAX; j += i) {
					isKnownTable[j / 64] |= (one << (j % 64));
				}
			}
		}
	}
	bool isPrime(const int num) {
		return (isPrimeTable[num / 64] & (one << (num % 64))) ? true : false;
	}
};

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

	Eratosthenes<2155>E;

	vector<int>cube;
	rep(i, 2155)if(E.isPrime(i))cube.push_back(i*i*i);

	int N;
	cin >> N;
	map<int, int>ms;
	int answer = 0;
	rep(i, N){
		int X;
		cin >> X;
		for (int j = 0; j < cube.size() && cube[j] <= X; j++)while (X % cube[j] == 0)X /= cube[j];
		if (X == 1)answer = 1;
		else{
			auto itr = ms.find(X);
			if (itr == ms.end())ms[X] = 1;
			else ms[X]++;
		}
	}

	ITR(x, ms){
		int X = x->first*x->first;
		for (int j = 0; j < cube.size() && cube[j] <= X; j++)while (X % cube[j] == 0)X /= cube[j];
		auto itr = ms.find(X);
		if (itr == ms.end())answer += x->second;
		else{
			answer += max(x->second, itr->second);
			ms.erase(itr);
		}
	}
	cout << answer << endl;

}

Measured memory_bytes: 6528
import java.util.Scanner;

class Main {

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

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

		int num = r * 100 + g * 10 + b;
		boolean ans = num % 4 == 0;

		if(ans){
			System.out.println("YES");
		}else{
			System.out.println("NO");
		}
		

	}

}


Measured memory_bytes: 20948
while True:
    n, r = map(int, raw_input().split())

    if n == 0 and r == 0:
        break

    Cards = range(n, 0, -1)

    for i in range(r):
        p, c = map(int, raw_input().split())
        Cards = Cards[p-1:p-1+c] + Cards[:p-1] + Cards[p-1+c:]

    print Cards[0]



Measured memory_bytes: 4648
#include <bits/stdc++.h>
using namespace std;
template<class t> inline t read(t &x){
	x=0;char c=getchar();bool f=0;
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f) x=-x;return  x;
}
template<class t> inline void write(t x){
	if(x<0){putchar('-'),write(-x);}
	else{if(x>9)write(x/10);putchar('0'+x%10);}
}

#include <tr1/unordered_map>

const int N=2e5+5;
int n,k,s[N];
long long ans;
tr1::unordered_map<int,queue<int> > mp;

signed main(){
	read(n);read(k);
	for(int i=1,x;i<=n;i++){
		read(x);
		x%=k;
		s[i]=(s[i-1]+x)%k;
	}
	mp[0].push(0);
	for(int i=1;i<=n;i++){
		int now=s[i]-i;
		now=(now%k+k)%k;
		while(!mp[now].empty()&&i-mp[now].front()>=k) mp[now].pop();
		ans+=mp[now].size();
		mp[now].push(i);
	}
	write(ans);
}


Measured memory_bytes: 143688
s = input()
L = [str(i % 2) for i in range(len(s))]
start0 = "".join(L)
start1 = "".join(L[1:])
if len(s) % 2 == 0:
    start1 += "0"
else:
    start1 += "1"
count_start0 = 0
count_start1 = 0

for i in range(len(s)):
    if s[i] != start0[i]:
        count_start0 += 1

for i in range(len(s)):
    if s[i] != start1[i]:
        count_start1 += 1
print(min(count_start0,count_start1))




Measured memory_bytes: 10356
def main():
    n, w = map(int, input().split())
    w1, v1 = map(int, input().split())
    values = [[] for _ in range(4)]
    values[0].append(v1)
    for _ in range(n - 1):
        wi, vi = map(int, input().split())
        values[wi - w1].append(vi)
    for i in range(4):
        values[i].sort(reverse=True)
    prefix = [[0] for _ in range(4)]
    for i in range(4):
        for j in range(len(values[i])):
            prefix[i].append(prefix[i][-1] + values[i][j])
    max_ans = 0
    tot_val = [0] * 4
    tot_weights = [0] * 4
    for i in range(min(len(values[0]), w // w1) + 1):
        tot_val[0] = prefix[0][i]
        tot_weights[0] = w1 * i
        for j in range(min(len(values[1]), w // (w1 + 1)) + 1):
            tot_val[1] = tot_val[0] + prefix[1][j]
            tot_weights[1] = tot_weights[0] + (w1 + 1) * j
            if tot_weights[1] > w:
                break
            for k in range(min(len(values[2]), w // (w1 + 2)) + 1):
                tot_val[2] = tot_val[1] + prefix[2][k]
                tot_weights[2] = tot_weights[1] + k * (w1 + 2)
                if tot_weights[2] > w:
                    break
                diff = w - tot_weights[2]
                min_select = min(diff // (w1 + 3), len(values[3]))
                tot_val[3] = tot_val[2] + prefix[3][min_select]
                tot_weights[3] = tot_weights[2] + min_select * (w1 + 3)
                max_ans = max(max_ans, tot_val[3])
    print(max_ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
N, x = map(int, input().split())
a = list(map(int, input().split()))
cnt = 0
for i in range(1, N):
    tmp = a[i - 1] + a[i]
    if tmp > x:
        if tmp - x > a[i]:
            a[i - 1] = tmp - a[i] - x
            a[i] = 0
        else:
            a[i] = a[i] - (tmp - x)
        cnt += tmp - x

print(cnt)

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

using namespace std;

class DisjointSet {
private:
	vector<int> rank, size, p;
	int num = 0;
public:
	DisjointSet() {}
	DisjointSet(int n) {
		rank.assign(n, 0);
		size.assign(n, 1);
		p.assign(n, 0);
		for (int i = 0; i < n; i++) p[i] = i;
	}

	bool same(int x, int y) {
		return root(x) == root(y);
	}

	void unite(int x, int y) {
		x = root(x), y = root(y);
		if (x == y) return;
		if (rank[x] > rank[y]) {
			p[y] = x;
			size[x] += size[y];
		} else {
			p[x] = y;
			size[y] += size[x];
			if (rank[x] == rank[y]) rank[y]++;
		}
	}

	int root(int x) {
		return p[x]==x?x:p[x]=root(p[x]);
	}
};

int main() {
	int N,M; cin >> N >> M;
	DisjointSet dj(N+M);
	for(int i=0;i<N;++i) {
		int K; cin >> K;
		while(K--) {
			int L; cin >> L;
			dj.unite(i,N+L-1);
		}
	}
	int i;
	for(i=0;i<N;++i) if(!dj.same(i,(i+1)%N)) break;
	if(i==N) cout << "YES" << endl;
	else cout << "NO" << endl;
	
	return 0;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
typedef long long ll; 
using namespace std;
int a[200010];
ll sum;
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i];
    sort(a,a+n);
    if(n>1)
        sum+=a[n-1];
    int k=n-2;
    n=n-2;
    while(n>=2)
    {
        sum=sum+2*a[k--];
        n=n-2;
    }
    if(n==1)
        sum+=a[k];
    cout<<sum<<endl;
    return 0;
}


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

int main()
{
  int s;
  cin >> s;
  vector<int> S;
  S.push_back(s);

  int one = 0;

  while (one < 2)
  {
    if (s % 2 == 0)
    {
      s /= 2;
    }
    else
    {
      s = (3 * s) + 1;
    }
    S.push_back(s);

    if (s == 1)
    {
      one++;
    }
  }

  for (int i = 0; i < S.size() - 1; i++)
  {
    for (int j = i + 1; j < S.size(); j++)
    {
      if (S[i] == S[j])
      {
        cout << j + 1 << endl;
        return 0;
      }
    }
  }
}


Measured memory_bytes: 3600
// 

#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <ios>
#include <iomanip>
#include <string>
#include <numeric>

using namespace std;
int N;

bool isASD(int *p) {
    int tmp = p[0];
    for (int i = 1; i < N; i++) {
        if (tmp > p[i]) {
            return false;
        }
        tmp = p[i];
    }
    return true;
}

int main() {
    cin >> N;
    int p[N];
    for (int i = 0; i < N; i++) {
        cin >> p[i];
    }

    if (isASD(p)) {
        cout << "YES" << endl;
        return 0;
    }

    for (int i = 0; i < N - 1; i++) {
        for (int j = i + 1; j < N; j++) {
            if (p[i] > p[j]) {
                int p_i = p[i];
                int p_j = p[j];

                p[i] = p_j;
                p[j] = p_i;

                if (isASD(p)) {
                    cout << "YES" << endl;
                    return 0;
                }
                p[i] = p_i;
                p[j] = p_j;
            }
        }
    }

    cout << "NO" << endl;

    return 0;
}


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

int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    std::vector<std::vector<bool>> graph(n, std::vector<bool>(n, true));
    for (int i = 0; i < n; i++)
        graph[i][i] = false;
    for (int i = 0, u, v; i < m; i++) {
        scanf("%d%d", &u, &v);
        --u, --v;
        graph[u][v] = graph[v][u] = false;
    }
    std::vector<bool> color(n), vis(n), dp(n + 1);
    dp[0] = true;
    bool flag = true;
    for (int i = 0; i < n && flag; i++) {
        if (vis[i]) continue;
        bool is_bipartite = true;
        std::queue<int> q({i});
        vis[i] = true;
        int count[2] = {};
        for (; !q.empty(); q.pop()) {
            int u = q.front();
            count[color[u]]++;
            for (int v = 0; v < n; v++) {
                if (not graph[u][v]) continue;
                if (vis[v] && color[v] == color[u])
                    is_bipartite = false;
                else if (not vis[v]) {
                    color[v] = 1 ^ color[u];
                    vis[v] = true;
                    q.push(v);
                }
            }
        }
        std::vector<bool> dp2(n + 1);
        for (int j = 0; j <= n; j++) {
            if (not dp[j]) continue;
            dp2[j + count[0]] = true;
            dp2[j + count[1]] = true;
        }
        dp.swap(dp2);
        if (not is_bipartite)
            flag = false;
    }
    if (not flag)
        puts("-1");
    else {
        int ans = INT_MAX;
        for (int i = 0; i <= n; i++) {
            if (not dp[i]) continue;
            ans = std::min(ans, i * (i - 1) / 2 + (n - i) * (n - i - 1) / 2);
        }
        printf("%d\n", ans);
    }
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

ll N;
ll A[100010];
ll r = 0;
ll gcdL[100010] = {};
ll gcdR[100010] = {};

ll ans = 0;

ll gcd(ll a, ll b)
{
	if (a < b) swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}

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

	gcdL[0] = A[N - 1];
	//後ろからN-1個のgcdLを求める
	for (int i = 1; i < N; i++)
	{
		gcdL[i] = gcd(gcdL[i - 1], A[N - 1 - i]);
	}
	//左側からのgcd求めた

	gcdR[0] = A[0];
	for (int i = 1; i < N; i++)
	{
		gcdR[i] = gcd(gcdR[i - 1], A[i]);
	}

	for (int i = 0; i < N; i++)
	{
		if (i - 1 < 0)
		{
			ans = max(ans, gcdL[N - 1 - 1]);
			continue;
		}
		else if (i + 1 > N - 1)
		{
			ans = max(ans, gcdR[N - 1 - 1]);
			continue;
		}

		ans = max(ans, gcd(gcdR[i - 1], gcdL[N - 1 - (i + 1)]));
	}

	cout << ans << endl;
}

Measured memory_bytes: 2560
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<time.h>
#define ll long long
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
ll cnt[26];
signed main() {
	ll n, ans = 1;
	string s;
	cin >> n >> s;
	rep(i, s.size())cnt[s[i] - 'a']++;
	rep(i, 26) {
		ans *= (cnt[i] + 1);
		ans %= 1000000007;
	}
	if (ans == 0)cout << 1000000006 << endl;
	else cout << ans - 1 << endl;
	getchar(); getchar(); return 0;
}

Measured memory_bytes: 512
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
typedef vector<int> vi;
typedef long long ll;



int main(){
    int N,a[110],cnt=0,st=0;
    cin>>N;
    rep(i,0,N)cin>>a[i];
    rep(i,0,102){
        rep(i,0,N){
            if(a[i]!=0){
                st=1;
                a[i]--;
            }
            else if(st==1&&a[i]==0){
                st=0;
                cnt++;
            }
        }
        if(st==1){
            st=0;
            cnt++;
        }
    }
    cout<<cnt<<endl;
}






Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <functional>
#include "math.h"
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define VI vector<int>
#define debug(x) cout<<#x<<": "<<x<<endl
#define DEBUG(x) cout<<#x<<": "<<x<<endl
string s;




string notx;
string notx_r;
int main()
{

	cin >> s;
	REP(i,s.length()){
		if(s[i]!='x')
			notx.push_back(s[i]);
	}

	RREP(i,notx.length()){
		notx_r.push_back(notx[i]);
	}

	if(notx != notx_r){
		cout << -1;
		return 0;
	}
	int count = 0;
	int x1=0,x2=0;
	int head=0,tail=s.length()-1;
	int ans = 0;

	while(count< ceil((double)notx.size()/2)){
		while(s[head]=='x'){
			x1++;
			head++;
		}
		while(s[tail]=='x'){
			x2++;
			tail--;
		}
		ans += abs(x1-x2);
		x1 = 0;
		x2 = 0;
		head++;
		tail--;
		count++;
	}
	cout << ans << endl;
}



Measured memory_bytes: 640
#include<bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<int,int>
#define I vector<int>
#define S set<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())
class Edge{
public:
    int from,to,value;
    Edge(int a,int b,int c){
        from = a;
        to = b;
        value = c;
    }
    Edge(int a,int b){
        from = a;
        to = b;
    }
};
int main(){
    CIN(H);CIN(W);
    V<string> vec;
    REP(a,H){
        string w;cin >> w;
        vec.pb(w);
    }
    bool ans = true;
    for(int a = 0;a < H;a++){
        for(int b = 0;b < W;b++){
            if(vec.at(a).at(b)=='#'){
                bool result = true;
                if(a-1>=0){
                    if(vec.at(a-1).at(b)=='#'){
                        result=false;
                    }
                }
                if(a+1<H){
                    if(vec.at(a+1).at(b)=='#'){
                        result = false;
                    }
                }
                if(b-1>=0){
                    if(vec.at(a).at(b-1)=='#'){
                        result= false;
                    }
                }
                if(b+1<W){
                    if(vec.at(a).at(b+1)=='#'){
                        result= false;
                    }
                }
                if(result){
                    ans=false;
                }
            }
        }
    }
    Yes(ans);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
const int N=100010;
using namespace std;
ll n,a,b;
int main()
{
    scanf("%lld%lld%lld",&n,&a,&b);
    ll mx=b*(n-1)+a;
    ll mn=a*(n-1)+b;
    if(n==1&&a!=b||a>b) puts("0");
    else if(n==1&&a==b) puts("1");
    else printf("%lld\n",mx-mn+1);
}


Measured memory_bytes: 256
n,m = gets.split().map(&:to_i)

x = []
for i in 1..n do
    ab = gets.split().map(&:to_i)
    x << ab
end

x = x.sort_by{|e| e.first}

sum = 0
ans = 0
x.each do |xi|
    sum += xi[1]
    ans += xi[0]*xi[1]
    if sum >= m then
        ans -= xi[0]*(sum-m)
        break
    end
end

p ans

Measured memory_bytes: 12664
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

class Program
{
	static void Main(string[] args)
	{
		double R = double.Parse(Console.ReadLine());
		double G = double.Parse(Console.ReadLine());
		Console.WriteLine(2 * G - R);
	}
}

Measured memory_bytes: 11220
n,k = map(int, input().split())

if k%2 == 1: # kが奇数の場合
  x = 0
  for i in range(1,n+1):
    if i%k == 0: x += 1 # kで割り切れる値の数をカウント
  print(x**3) # 組み合わせ分増える
else: # kが偶数の場合
  x = 0
  for i in range(1, n+1):
    if i % k == 0: x += 1 # kで割り切れる値の数をカウント
  y = 0
  for i in range(1, n+1):
    if i % k == k//2: y += 1 # k//2で割り切れる値の数をカウント
  print(x**3 + y**3) # 組み合わせ分増える

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

using ll = long long;
using ld = long double;
using pii = pair<int, int>;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))

int dx4[4] = {1,0,-1,0}, dy4[4] = {0,1,0,-1};


int main()
{
    ll n,m,ans=0;
    cin>>n>>m;
    vector<ll> a(n);
    priority_queue<ll> pq;
    for (int i = 0; i < n; i++)
    {
        cin>>a[i];
        pq.emplace(a[i]);
    }
    for (int i = 0; i < m; i++)
    {
        ll top = pq.top();
        pq.pop();
        top/=2;
        pq.push(top);
    }
    for (int i = 0; i < n; i++)
    {
        ll top = pq.top();
        pq.pop();
        ans+=top;
    }
    
    cout<<ans<<endl;

    return 0;
}

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

int main() {
  int n, m, cnt, ans = 0;
  vector<string> ns, ms;
  string temp;

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> temp;
    ns.push_back(temp);
  }

  cin >> m;
  for (int i = 0; i < m; i++) {
    cin >> temp;
    ms.push_back(temp);
  }

  for (int i = 0; i < n - 1; i++) {
    cnt = 1;
    if (ns[i] == ".") continue;
    for (int j = i + 1; j < n; j++) {
      if (ns[i] == ns[j]) {
        cnt++;
        ns[j] = ".";
      }
    }
    for (int j = 0; j < m; j++) {
      if (ns[i] == ms[j]) cnt--;
    }
    if (cnt > ans) ans = cnt;
  }

  cout << ans;

  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
int ch1[110]={0},ch2[110]={0},a,b,c,d, ans=0;
scanf("%d%d%d%d", &a,&b,&c,&d);
ans = ((b-a)+(d-c)-abs(a-c)-abs(b-d)) / 2;
if(ans<0) ans=0;
printf("%d\n",ans);
return 0;
}

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

int main()
{
	int n=1, count = 0;
	int a[10000];
	while (cin >> n) {
		for (int i = 0; i < n; i++) {
			cin >> a[i];
		}
		int sum = 0, max = -100000;
		for (int ai = 0; ai < n; ai++) {
			sum = 0;
			for (int bi = ai; bi < n; bi++) {
				sum = sum + a[bi];
				if (sum > max) {
					max = sum;
				}
			}
		}
		if (n == 0)
			break;
		cout << max << endl;
	}
}

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

#define ll long long
#define ld double

using namespace std;


int main()
{
	ll x, n, num;
	cin >> x >> n;
	vector<ll> a(101, 1);
	for (int i = 0; i < n; i++) {
		cin >> num;
		a[num] = 0;
	}

	num = -1;
	for (int i = 0; i <= 101; i++) {
		if (abs(x - num) > abs(x - i) && a[i]) num = i;
	}

	cout << num;

}

Measured memory_bytes: 3652