akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

using namespace std;

int main(){
    int a,b;
    cin >> a >> b;
    
    int sum = a + b;
    int diff = a - b;
    int muni = a * b;
    
    if(sum >= diff && sum >= muni) {
        cout << sum << endl;
    }
    else if(diff >= sum && diff >= muni) {
        cout << diff << endl;
    }
    else if(muni >= diff && muni >= sum) {
        cout << muni << endl;
    }
}

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

int main()
{
    int K, S, cnt = 0;
    cin >> K >> S;
    for (int x = 0; x <= K; x++) {
        for (int y = 0; y <= K; y++) {
            int z = S - x - y;
            if (z >= 0 && z <= K) cnt++;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public class Main
{

  public static void main(String[] args) throws IOException
  {
    BufferedReader r = new BufferedReader(new InputStreamReader(System.in), 1);
    String[] sl = r.readLine().split("[\\s]+");
    int N = Integer.parseInt(sl[0]);
    int H = Integer.parseInt(sl[1]);

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

    for(int i = 0; i < N; i++)
    {
      sl = r.readLine().split("[\\s]+");
      a[i] = Integer.parseInt(sl[0]);
      b[i] = Integer.parseInt(sl[1]);
    }


   int mainw = 0;
    for(int i = 0; i < N; i++)
    {
      if(mainw < a[i])
      {
        mainw = a[i];
      }
    }

    List<Integer> li = new ArrayList<Integer>();
    for(int i = 0; i < N; i++)
    {
      if(mainw < b[i])
      {
        li.add(b[i]);
      }
    }

    Collections.sort(li);

    int dam = 0;
    int count = 0;
    for(int i = li.size() - 1; 0 <= i; i--)
    {
      dam += li.get(i);
      count++;
      if(H <= dam)
      {
        break;
      }
    }

    if(dam < H)
    {
      count += (H - dam + mainw - 1) / mainw;
    }

    System.out.println(count);


  }

}


Measured memory_bytes: 92884
n,m = map(int,input().split())
s = input().rstrip()
mod = 10**9+7
if s.count("R") == 0 or s.count("B") == 0:
  dp = [[0 for i in range(2)] for j in range(n)]
  dp[0][0] = 1
  dp[0][1] = 1
  for i in range(1,n):
    dp[i][0] = (dp[i-1][0]+dp[i-1][1])%mod
    dp[i][1] = dp[i-1][0]
  print((dp[n-1][0]+dp[n-2][1])%mod)
  exit()
if n%2:
  print(0)
  exit()
x = s[0]
flg = 1
cnt = 0
ncnt = 0
for i in range(m):
  if s[i] == x:
    cnt += 1
  elif flg == 1:
    flg = 0
    ncnt = cnt
    cnt = 0
  else:
    if cnt%2:
      ncnt = min(ncnt,cnt)
    cnt = 0
if ncnt == 1:
  print(2)
  exit()
y = ncnt//2
dp = [[0 for i in range(2)] for j in range(n//2)]
dp[0][0] = 1
dp[0][1] = 1
for i in range(1,n//2):
  dp[i][0] = dp[i-1][0]+dp[i-1][1]
  if i<y:
    dp[i][1] = dp[i-1][0]+dp[i-1][1]
  elif i == y:
    dp[i][1] = sum([dp[j][0] for j in range(y)])
  else:
    dp[i][1] = dp[i-1][1]+dp[i-1][0]-dp[i-y-1][0]
  dp[i][0] %= mod
  dp[i][1] %= mod
ans = dp[-1][0]+dp[-1][1]
for j in range(1,y+1):
  if n//2-(y+j)-2 >= 0:
    ans = (ans-(dp[n//2-(y+j)-2][0])*(y+1-j))%mod
  elif n//2-(y+j) == 1:
    ans -= y+1-j
print(2*ans%mod)

Measured memory_bytes: 33504
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>
#include <numeric>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>

using ll = long long int;
using ul = unsigned long long int;
const ll LL_MAX (1LL<<60);
const ll MOD (1000000007);

#define rep(i,s,e) for(ll i=(s); i<(e); i++) 

using namespace std;

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

    ll n;
    cin >> n;
    if (n%2==1)
        cout << n/2 + 1 << endl;
    else
        cout << n/2 << endl;
    return 0;
}


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

#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()

//#define int long long
using namespace std;
const int INF = 2e9;
const int MOD = 1e9 + 7;
const int MB = 60;

void solve() {
	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}

	vector<bool> dp(k + 1);
	for (int i = 1; i <= k; i++) {
		for (int j = 0; j < n; j++) {
			if (i - a[j] >= 0 && !dp[i - a[j]]) dp[i] = true;
		}
	}

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

signed main() {
	/*
	freopen("search.in", "r", stdin);
	freopen("search.out", "w", stdout);
	*/
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	cout << fixed;
	cout.precision(12);
	solve();
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define eps (1e-8)

int N,M;
double L;
double P[100],T[100],V[100];
double a[100][100],b[100][100];

double mem[100][100];
double ncr(int n,int r){
  if(mem[n][r]!=-1.0)return mem[n][r];
  r=min(r,n-r);
  double res=1.0;
  for(int i=0;i<r;i++){
    res=res*(double)(n-i);
    res=res/(double)(i+1);
  }
  return mem[n][r]=res;
}

double solve(int x){
  if(V[x]<eps)return 0;
  
  double res=0;
  for(int i=0;i<=M;i++){
    double p=a[x][i];
    double d=b[x][i];
    for(int j=0;j<N;j++){
      if(x==j)continue;
      if(V[j]<eps){
        continue;
      }
      double sum=0;
      for(int k=0;k<=M;k++){
        if(b[j][k]<d+eps)continue;
        sum+=a[j][k];
      }
      p*=sum;
    }
    res+=p;
  }
  return res;
}

int main(){
  for(int i=0;i<100;i++)
    for(int j=0;j<100;j++)
      mem[i][j]=-1.0;
  
  cin>>N>>M>>L;
  for(int i=0;i<N;i++){
    cin>>P[i]>>T[i]>>V[i];
    if(V[i]<eps)continue;

    double p=P[i]/100.0;
    double q=1.0-p;
    for(int j=0;j<=M;j++){
      a[i][j]=ncr(M,j)*pow(p,j)*pow(q,M-j);
      b[i][j]=L/V[i]+T[i]*j;
      //cout<<a[i][j]<<' '<<b[i][j]<<endl;
    }
    //cout<<endl;
  }
  for(int i=0;i<N;i++){
    printf("%.10f\n",solve(i));
  }
  return 0;
}

Measured memory_bytes: 1484
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
    int n;
    int a[15000] = {0};
    while(scanf("%d",&n),n){
    int ans = 0;
    a[0] = 1;
    a[1] = 1;
    a[2] = 2;
    for(int i = 3;i <= n; i++){
        a[i] = a[i-1] + a[i-2] + a[i-3];
    }
    ans = a[n]/3650;
    printf("%d\n",ans+1);
    }
    return 0;
}

Measured memory_bytes: 1252
import math
a, b, h, m  = map(int, input().split())
theta = (h * 60 * 0.5+ m * 0.5) % 360 - (h * 60 * 6 + m * 6) % 360

if theta > 180:
    theta = 360 - theta

ab = math.sqrt(a**2+b**2-2*a*b*math.cos(math.radians(theta)))
print(ab)

Measured memory_bytes: 9432
#include <cstdio>
#include <cstring>
const int maxn=1e5+10;
char s[maxn];
int main() {
    scanf("%s",s);
    int len=strlen(s);
    int a,b;
    a=b=-1;
    if (len==1) {
        puts("1 1");
        return 0;
    }
    if (len==2 && s[0]==s[1]) {
        puts("1 2");
        return 0;
    }
    for (int i=2;i<len;i++) {
        if (s[i]==s[i-1]||s[i]==s[i-2]) {
            a=i-2+1;
            b=i+1;
            break;
        }
    }
    printf("%d %d\n", a,b);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
#include <set>
#include <unordered_map>

using namespace std;

const int maxn=2e5+5;

int n;
bool ms[maxn];
int sol[maxn];

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	string s;
	cin >> s;
	n=s.size();
	for(int i=0; i<n; i++){
		if(s[i]=='R'){
			ms[i]=1;
		}
		else{
			ms[i]=0;
		}
	}
	int ci;
	bool p=0;
	int prosli=0;
	int br;
	for(int i=0; i<n; i++){
		if(!ms[i] && ms[i-1]){
			br=i-prosli-1;
			ci=i-1;
			p=1;
			sol[ci]=br/2+1;
			sol[ci+1]=round((double)br/2)+1;
		}
		else if(p && ms[i]){
			p=0;
			prosli=i;
		}
		else if(p && !ms[i]){
			sol[ci+((i-ci)%2)]++;
		}
	}
	for(int i=0; i<n; i++){
		cout << sol[i] << " ";
	}
	cout << '\n';
	return 0;
}

Measured memory_bytes: 1232
#include<iostream>
#define N 200000
#define MOD 1000000007
using namespace std;
int a[N+1];
int n;
int f(int x)
{
	int sum = 0;
	for(int i = 0; i < n; i++)
		sum += (x-a[i])*(x-a[i]);
	return sum;
}
int main()
{
	cin >> n;
	int sum = 0;
	for(int i = 0; i < n; i++)
		cin >> a[i], sum += a[i];
	cout<<min(f(sum/n),f(sum/n+1))<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long
#define LD long double
#define pb push_back
#define mp make_pair
#define ss(x) (int) x.size()
#define fi first
#define se second
#define cat(x) cerr << #x << " = " << x << endl
#define rep2(i, j, n) for (LL i = j; i <= n; ++i)
#define rep(i, j, n) for (int i = j; i <= n; ++i)
#define per(i, j, n) for (int i = n; j <= i; --i)
#define boost cin.tie(0);ios_base::sync_with_stdio(0);
#define all(x) x.begin(), x.end()

using namespace std;

int n;

int main() {		
	scanf ("%d", &n);
	vector <int> v(2 * n);
	for (int &x : v) scanf ("%d", &x);
	sort(all(v));
	reverse(all(v));
	int ans = 0;
	rep(i, 0, 2 * n - 1)	
		if (i & 1) ans += v[i];
	printf ("%d ", ans);
	
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1LL << 60;
const int MAX = 1000000010;
const ll MOD = 1000000007;

int main() {
    int a, b; cin >> a >> b;
    cout << a * b << endl;
    return 0;
}

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

int main() {
  string S,T;
  cin >> S >> T;
  int s=0;
  for (int i=0;i<S.size();i++){
    if (S.at(i)==T.at(i))
      s++;
  }
  if (s == S.size())
    cout << "Yes" <<endl;
  else
    cout << "No" << endl;
}


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

int main() {
  string a,b,c;
  //char a,b,c;
  cin >> a >> b >> c;
  
  cout << a.at(0) << b.at(0) << c.at(0) << endl;
  //cout <<a<<b<<c<<endl;
}


Measured memory_bytes: 256
#pragma GCC target ("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,s,f) for(int i=s;i<f;i++)
#define INF 1000000000000000000
#define MOD 1000000007
typedef pair<int, int> P;

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

bool prime(int n) {
    for (int i = 2; i <= sqrt(n); i++) {
        if (n % i == 0)return false;
    }
    return n != 1;
}
int gcd(int x, int y) {
    if (y == 0)return x;
    return gcd(y, x % y);
}
int lcm(int x, int y) {
    return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
    if (p == 0) return 1;
    if (p % 2 == 0) {
        int t = mod_pow(n, p / 2, m);
        return (t * t) % m;
    }
    return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    long long d = extGCD(b, a % b, y, x);
    y -= a / b * x;
    return d;
}
int modinv(int a, int m) {
    int b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
int digit(int x) {
    int cnt = 0;
    while (x > 0) {
        cnt += x % 10;
        x /= 10;
    }
    return cnt;
}
int read() {
    int tmp;
    cin >> tmp;
    return tmp;
}
int xor128() {
    static int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    int t = (x xor (x << 11));
    x = y; y = z; z = w;
    return (w = (w xor (w >> 19)) xor (t xor (t >> 8)));
}
map<int, int> factaring(int x) {
    map<int, int>ans;
    int now = 2;
    while (now * now <= x) {
        if (x % now == 0) {
            x /= now;
            ans[now]++;
        }
        else now++;
    }
    if (x != 1) ans[x]++;
    return ans;
}
int comb(int n, int k) {
    k = min(k, n - k);
    int x = 1, y = 1;
    rep(i, k) {
        y *= i + 1;
        y %= MOD;
    }
    for (int i = n - k + 1; i <= n; i++) {
        x *= i;
        x %= MOD;
    }
    return x * modinv(y, MOD) % MOD;
}

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

    int n;
    set<int>se;
    cin >> n;

    int a = 1;
    while (a * a <= n - 1) {
        if ((n - 1) % a == 0) {
            se.insert(a);
            se.insert((n - 1) / a);
        }
        a++;
    }

    se.insert(n);
    a = 2;

    while (a * a <= n) {
        if (n % a == 0) {
            int x = n;
            while (x % a == 0) x /= a;
            if (x % a == 1) se.insert(a);

            x = n;
            a = n / a;
            while (x % a == 0) x /= a;
            if (x % a == 1) se.insert(a);
            a = n / a;
        }
        a++;
    }

    cout << se.size() - 1 << endl;

    return 0;
}


Measured memory_bytes: 256
#define George_Plover
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <queue>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <vector>
#include <iostream>
#include <iomanip>
#include <algorithm>
#define MAXN 1001
#define MAXM 600001
#define MOD 100000007
#define EPS (1e-8)
#define LL long long
using namespace std;
int n,m;
bool vis[200][200];
int main()
{
    string s;
    cin>>s;
    if(s=="ABC")
        cout<<"ARC"<<endl;
    else
        cout<<"ABC"<<endl;
    return 0;
}


Measured memory_bytes: 3592
#include <iostream>
#include <fstream>
#include <cstdlib>
#include <math.h>
#include <utility>
#include <algorithm>
#include <functional>
#include <vector>
#include <numeric>
#include <bits/stdc++.h>

#define int long long

struct edge {
    int to;
    int cost;
};

using namespace std;
using vi = vector<int>;
using vii = vector<vector<int>>;
using vb = vector<bool>;
using qi = queue<int>;
using P = pair<int, int>;
using graph = vector<vector<edge>>;
// using graph = vector<vector<int>>;


#define FOR(i, a, b) for (int i = a; i < (b); i++)
#define REP(i,n) for(int i=0;i<n;i++)
#define delim(i, n) cout << (i == n-1 ? "\n" : " ");

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

const int inf = 1LL << 60;
// const int inf = 100000000;
const int mod = 1000000007;

const int maxn =  2e4;
int w, h;
vii used(50, vi (50));
vii table(50, vi (50));

vi dx = {-1, 0, 0, 1};
vi dy = {0, -1, 1, 0};


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

    cin >> h >> w;
    REP(i, h) {
        REP(j, w) {
            char tmp; cin >> tmp;
            if (tmp == '.') table[j][i] = 0;
            else table[j][i] = 1;
        }
    }

    int cnt = 0;
    REP(i, h) {
        REP(j, w) {
            if (table[j][i] == 0) cnt++;
        }
    }

    queue<pair<P, int>> que;
    que.push(pair<P, int>(P(0,0), 1));
    used[0][0] = 1;
    int ret = 0;
    while(!que.empty()) {
        pair<P, int> p = que.front();
        que.pop();
        int x = p.first.first;
        int y = p.first.second;
        REP(i, 4) {
            int nx = x + dx[i];
            int ny = y + dy[i];
            if (nx < 0 || ny < 0 || nx >= w || ny >= h || used[nx][ny] == 1 || table[nx][ny] == 1) continue;
            if (nx == w-1 && ny == h-1) ret = p.second+1;
            que.push(pair<P, int>(P(nx, ny), p.second+1));
            used[nx][ny] = 1;
        }
        if (ret != 0) break;
    }
    if (ret == 0) cnt = -1;
    else cnt -= ret;
    cout << std::fixed << std::setprecision(10) << cnt << "\n";
}

Measured memory_bytes: 3704
#include <iostream>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <cmath>
#define INF 100000000000
#define MOD 1000000007
#define ll long long int
using namespace std;

int main(){
   int N; cin>>N;
   set < pair <string,int> > box;
   vector <string> site;
   vector <int> point;
   vector <int> order;order.resize(N);

   for(int i=0;i<N;i++){
       string s; cin>>s;
       int p; cin>>p;
       site.push_back(s);
       point.push_back(p);

       box.insert(make_pair(s,-p));
   }

   int cnt = 0;

   for(auto itr = box.begin();itr != box.end();itr++){
       cnt++;
       string nows = (*itr).first;
       int nowp = (*itr).second;

       for(int j=0;j<N;j++){
           if(point[j] == -nowp) order[j] = cnt;
       }


   }

   for(int i=1;i<=N;i++){
       for(int j=0;j<N;j++){
           if(order[j] == i) cout<<j+1<<endl;
       }
      
   }
    return 0;
}



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

# define x first
# define y second
# define mp make_pair
// everything goes according to my plan
# define pb push_back
# define sz(a) (int)(a.size())
# define vec vector
// shimkenttin kyzdary, dzyn, dzyn, dzyn...
# define y1    Y_U_NO_y1
# define left  Y_U_NO_left
# define right Y_U_NO_right

# ifdef Local
# define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
# else
# define debug(...) (__VA_ARGS__)
# define cerr if(0)cout
# endif

using namespace std;

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

const int Mod = (int)1e9 + 7;
const int MX = 1073741822;
const ll MXLL = 4e18;
const int Sz = 1110111;
// a pinch of soul
inline void Read_rap () {
  ios_base :: sync_with_stdio(0);
  cin.tie(0); cout.tie(0);
}
inline void randomizer3000 () {
  unsigned int seed;
  asm ("rdtsc" : "=A"(seed));
  srand (seed);
}
void files (string problem) {
  if (fopen ((problem + ".in").c_str(),"r")) {
    freopen ((problem + ".in").c_str(),"r",stdin);
    freopen ((problem + ".out").c_str(),"w",stdout);
  }
}
void localInput(const char in[] = "s") {
  if (fopen (in, "r")) {
    freopen (in, "r", stdin);
  }
  else
    cerr << "Warning: Input file not found" << endl;
}
string s;
       
ll ans = 0;

int main()
{
  # ifdef Local
    //localInput();
  # endif
  Read_rap();
  cin >> s;    

  int cnt = 0;
  for (int i = sz(s) - 1; i >= 0; i--) {
    if (s[i] == 'B')
      ans += cnt;
    else
      cnt++;
  }       
  cout << ans;

  return 0;
}






// Coded by Z..


Measured memory_bytes: 720
house = [[[0]*10 for i in range(3)] for j in range(4)]

n = int(input())
for i in range(n):
    data = list(map(int, input().split()))
    house[data[0]-1][data[1]-1][data[2]-1] += data[3]
    
for i in range(4):
    for j in range(3):
        print('',' '.join(list(map(str,house[i][j]))))
    if i!=3: print('####################')

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

ll pow_(ll a, ll b) {
	if(b == 0)
		return 1;
	ll p = pow_(a, b/2);
	if(b&1)
		return p*p*a;
	else
		return p*p;
}

int main() {
	ll n;
	cin >> n;
	ll lo = log(n)/log(2);
	cout << pow_(2, lo+1) - 1 << endl;
	return 0;
}

Measured memory_bytes: 256
// Problem : A - A?C
// Contest : AtCoder - AtCoder Beginner Contest 166
// URL : https://atcoder.jp/contests/abc166/tasks/abc166_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

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


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

    string s;
    cin >> s;
    if (s[1] == 'B') cout << "ARC\n";
    else cout << "ABC\n";
    
    return 0;
}


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

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

    int res = 1001001001;
    int ave[2] = {sum / N, sum < 0 ? sum / N - 1 : sum / N + 1};
    for(int t=0; t<2; ++t) {
        int cost = 0;
        for(int i=0; i<N; ++i) {
            cost += (A[i] - ave[t]) * (A[i] - ave[t]);
        }
        res = min(res, cost);
    }
    cout << res << endl;
}

Measured memory_bytes: 256
var n:longint;
    i:longint;
    a,num:array[0..500000]of int64;
    max,max2,x:int64;
procedure qs(l,r:longint);
var i,j,m,t:longint;
begin
  i:=l;
  j:=r;
  m:=a[(l+r)>>1];
  repeat
    while a[i]>m do inc(i);
    while a[j]<m do dec(j);
    if i<=j then
    begin
      t:=a[i];a[i]:=a[j];a[j]:=t;
      inc(i);
      dec(j);
    end;
  until i>j;
  if l<j then qs(l,j);
  if i<r then qs(i,r);
end;
begin
  read(n);
  for i:=1 to n do
  begin
    read(a[i]);
    num[i]:=1;
  end;
  qs(1,n);
  for i:=1 to n do
  if a[i]=a[i-1] then inc(num[i],num[i-1]);
  for i:=1 to n do
  if num[i]>=4 then
  begin
    if x=0 then x:=a[i]*a[i];
  end else
  if num[i]>=2 then
  begin
    if max=0 then max:=a[i] else
    if (max2=0)and(a[i]<>max) then max2:=a[i];
  end;
  if x>max*max2 then writeln(x) else
  writeln(max*max2);
end.



Measured memory_bytes: 4992
H, W = map(int, input().split())
A = [list(map(int, input().split())) for _ in range(H)]
B = [list(map(int, input().split())) for _ in range(H)]

arr = [set() for _ in range(W)]
arr[0].add(0)
for y in range(H):
    nextarr = [set() for _ in range(W)]
    Ay = A[y]
    By = B[y]
    dh = H - y - 1
    for x in range(W):
        nextset = nextarr[x]
        d = Ay[x] - By[x]
        dw = W - x - 1
        lim = (dh + dw + 1) * 160
        if x >= 1:
            arr[x] |= nextarr[x-1]
        for n in arr[x]:
            if abs(n+d) <= lim:
                nextset.add(abs(n+d))
            if abs(n-d) <= lim:
                nextset.add(abs(n-d))
    arr = nextarr
print(min([abs(d) for d in arr[-1]]))

Measured memory_bytes: 156936
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pi 3.141592653589793238
#define eb emplace_back
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define zip(i,a,b) for(int i=a;i<b;i++)
#define rzip(i,a,b) for(int i=a;i>=b;i--)
#define ll unsigned int
#define test int t;cin>>t; while(t--)
#define um unordered_map
#define en '\n'
#define us unordered_set
typedef pair<int, int>     pii;
typedef pair<char, int>    pci;
typedef pair<char, char>   pcc;
typedef vector<pii>       vii;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define INF (1e18+5)
#define inf (1e9+5)
#define mod 1000000007


void __print(int x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
// You should only debug a pair of simple data types. For example,
// the debug won't work if one of pair's elements is collection type
// (std::vector, std::map, std::set...).
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif


// bool check_prime(int n)  return whether a number is prime or not O(sqrt(N));
// int BE(int x,int n,int m)  return x^n%m; O(logN);
// void sieve()  from number 1-1000001 saare prime store kar lega  in bool is_prime[1000001] array
// vector<int> z_array(string s)  return vector which is Z-array of string s;
// vector<int> lps(string s)      return vector which is lps array of string s;
// int power(int x,int n) return x^n; O(logN);
// using_ordered_set (template for using ordered set , replace first 2 lines of this page with this code..);


int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	if (fopen("input.txt", "r"))
	{
		freopen ("input.txt" , "r" , stdin);
		freopen ("output.txt" , "w" , stdout);
	}
#endif
	//_______________________________-code starts-_______________________________________________

	string s;
	cin >> s;
	int ans = 0;
	zip(i, 0, sz(s))
	{
		ans = (ans + (s[i] - '0')) % 9;
	}
	if (ans == 0)
		cout << "Yes" << en;
	else
		cout << "No" << en;

	return 0;
}




Measured memory_bytes: 3764
alfa = [chr(i) for i in range(65, 65+26)]
H,W = (int(i) for i in input().split())
X = []
for i in range(H):
    tmp = [str(i) for i in input().split()]
    X.append(tmp)
check = 0
h = 0
w = 0
for i in range(H):
    for j in range(W):
        if X[i][j] == 'snuke':
            check = 1
            h = i + 1
            w = alfa[j]
print(w + str(h))


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

int main() {
  int N;
  string str;
  cin >> N >> str;
  if (N == 0) {
    cout << str << endl;
    return 0;
  }
  for (char c : str) {
    if (c + N > 'Z') {
      char b = 'A' + c + N - 'Z' - 1;
      cout << b;
    } else {
      char n = c + N;
      cout << n;
    }
  }
  cout << endl;
}

Measured memory_bytes: 256
#ifdef DEBUG
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;

typedef long double ld;

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

#define sz(x) ((int) (x).size())
#define TASK "text"

const int inf = (int) 1.01e9;
const long long infll = (long long) 1.01e18;
const ld eps = 1e-9;
const ld pi = acos((ld) -1);

#ifdef DEBUG
mt19937 mrand(300); 
#else
mt19937 mrand(chrono::steady_clock::now().time_since_epoch().count()); 
#endif

int rnd(int x) {
  return mrand() % x;
}

void precalc() {
}

const int maxn = (int) 1e5 + 5;
int n, k;
vector<int> p, q;

bool read() {
  if (scanf("%d%d", &n, &k) < 2) {
    return false;
  }
  k--;
  p.resize(n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &p[i]);
    p[i]--;
  }
  q.resize(n);
  for (int i = 0; i < n; i++) {
    scanf("%d", &q[i]);
    q[i]--;
  }
  return true;
}

vector<int> inv(const vector<int> &p) {
  vector<int> q(n);
  for (int i = 0; i < n; i++) {
    q[p[i]] = i;
  }
  return q;
}

vector<int> mul(const vector<int> &a, const vector<int> &b) {
  vector<int> c(n);
  for (int i = 0; i < n; i++) {
    c[i] = a[b[i]];
  }
  return c;
}

vector<int> powPerm(vector<int> p, int k) {
  vector<int> res(n);
  for (int i = 0; i < n; i++) {
    res[i] = i;
  }
  while (k) {
    if (k & 1) {
      res = mul(res, p);
    }
    k >>= 1;
    p = mul(p, p);
  }
  return res;
}

void printAns(const vector<int> &p) {
  for (int i = 0; i < n; i++) {
    printf("%d ", p[i] + 1);
  }
  printf("\n");
}

void solve() {
  if (k == 0) {
    printAns(p);
    return;
  }
  if (k == 1) {
    printAns(q);
    return;
  }
  if (k == 2) {
    printAns(mul(q, inv(p)));
    return;
  }
  vector<int> a;
  {
    int x = k / 3;
    a = powPerm(mul(mul(q, inv(p)), mul(inv(q), p)), x / 2);
    if (x & 1) {
      a = mul(a, mul(mul(q, inv(p)), inv(q)));
    } else {
      a = mul(a, q);
    }
  }
  vector<int> b;
  {
    int x = (k - 3) / 6;
    b = powPerm(mul(mul(inv(p), q), mul(p, inv(q))), x);
    int y = (k - 3) % 6;
    if (y == 1) {
      b = mul(mul(p, inv(q)), b);
    } else if (y == 2) {
      b = mul(mul(mul(p, p), inv(q)), b);
    } else if (y == 3) {
      b = mul(mul(p, inv(q)), b);
    } else if (y == 4) {
      b = mul(mul(mul(inv(p), q), mul(p, inv(q))), b);
    } else if (y == 5) {
      b = mul(mul(mul(mul(inv(p), inv(p)), q), mul(p, inv(q))), b);
    }
  }
  printAns(mul(a, b));
}

int main() {
  precalc();
#ifdef DEBUG
  assert(freopen(TASK ".in", "r", stdin));
  assert(freopen(TASK ".out", "w", stdout));
#endif
  while (read()) {
    solve();
#ifdef DEBUG
    eprintf("Time %.2f\n", (double) clock() / CLOCKS_PER_SEC);
#endif
  }
  return 0;
}


Measured memory_bytes: 5288
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 1LL << 60;

vector<bool> seen;
int ans = 0;

void dfs(Graph &G, int v){
    seen[v] = true;
    int test = 0;
    rep(i, seen.size())if(seen[i] == true) test++;
    if(test == seen.size())ans++;
    for(auto x: G[v]){
        if(seen[x] == true)continue;
        dfs(G, x);
        seen[x] = false;
    }
}

int main(){
    int N, M;
    cin >> N >> M;
    Graph g(N);
    rep(i, M){
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    seen.assign(N, false);
    dfs(g, 0);
    cout << ans << endl;

}


Measured memory_bytes: 256
# input
n, m = map(int, input().split())
X = sorted(list(map(int, input().split())))

X_diff = []
for i in range(m - 1):
    X_diff.append(X[i + 1] - X[i]) 

X_diff = sorted(X_diff)

ans = 0
for i in range(m - n):
    ans += X_diff[i]

print(ans)

Measured memory_bytes: 13968
#include<iostream>

using namespace std;

char map[110][110];
int s_x,s_y,loop;

void serch(int x,int y)
{
	if(map[x][y]=='1')
	{
		loop=1;
		return ;
	}
	if(map[x][y]=='.')
	{
		s_x=x;
		s_y=y;
		return ;
	}
	if(map[x][y]=='>')
	{
		map[x][y]='1';
		serch(x,y+1);
	}
	else if(map[x][y]=='<')
	{
		map[x][y]='1';
		serch(x,y-1);
	}
	else if(map[x][y]=='v')
	{
		map[x][y]='1';
		serch(x+1,y);
	}
	else if(map[x][y]=='^')
	{
		map[x][y]='1';
		serch(x-1,y);
	}
	return ;
}

int main()
{
	int w,h;
	int i,j;
	
	for(;;)
	{
		loop=0;
		cin >> w >> h ;
		if(w==0 && h==0)
			break;
		for(i=0;i<w;i++)
		{
			for(j=0;j<h;j++)
			{
				cin >> map[i][j] ;
			}
		}
		
		serch(0,0);
		
		if(loop==1)
			cout << "LOOP" << endl;
		else
			cout << s_y << " " << s_x << endl;
	}
}

Measured memory_bytes: 0
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<cmath>
#include<cstring>
#include<set>
#include<climits>
#include<deque>
#include<iomanip>
#include<utility>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define all(a) a.begin(),a.end()
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define size(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
#define S 21 
llfor;
const ll mod=1000000007;
/*pi*/const double pi=acos(-1);
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll ans=1;rep(i,0,n){ans*=x;ans%=mod;}return ans;}
/*階乗*/ll fact(ll x){ll ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)*fact(n-r)/fact(r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
/*Fibonacci数列*/ll fib(ll x){ll fibo[x+10];fibo[0]=1;fibo[1]=1;fibo[2]=1;rep(i,3,x+1)fibo[i]=fibo[i-1]+fibo[i-2];return fibo[x];}
/*桁数*/ll dig(ll n){ll d=1,tmp=n;while(tmp/10>0){tmp/=10;d++;}return d;}
/*行列のコピー*/void matcpy(ll a[S][S],ll b[S][S]){ll t=i;rep(i,0,S)rep(j,0,S)b[i][j]=a[i][j];/*(aをbに)*/i=t;}
/*行列のリセット*/void matrst(ll a[S][S]){ll t=i;rep(i,0,S)rep(j,0,S)a[i][j]=0;i=t;}
/*行列の2乗*/void matpow(ll a[S][S]){ll ans[S][S];matrst(ans);ll t=i,k;rep(i,0,S)rep(j,0,S)rep(k,0,S)ans[i][j]+=a[i][k]*a[k][j];matcpy(ans,a);i=t;}
/*行列の乗算*/void matmul(ll a[S][S],ll b[S][S], ll as[S][S]){ll t=i,k;matrst(as);rep(i,0,S)rep(j,0,S)rep(k,0,S)as[i][j]+=a[i][k]*b[k][j];i=t;}
//ll ans=0;
////////////////////////////////////////////////////////////
int main(){
 string t;
 sc(t);
 char c;
 ll n=t.length();
 ll cnt=0,ans=n+10,res=0,tmp;
 bool flag;
 rep(i,0,26){
  c='a'+i;
  cnt=0;tmp=0;res=0;
  flag=false;
  rep(j,0,n){
   if(t[j]==c){ 
    if(tmp<cnt)tmp=cnt;
    cnt=max(cnt,tmp);  
    res=max(res,n-j-1);
    flag=true;
   // cout<<"* "<<c<<" "<<j<<" "<<cnt<<" "<<tmp<<" "<<ans<<endl;
    cnt=0;
   }
   else{
    flag=false;
    cnt++;
   // cout<<c<<" "<<j<<" "<<cnt<<" "<<ans<<endl;
   }
  }
  if(tmp<cnt)tmp=cnt;
  ans=min(ans,tmp);
  if(cnt==0&&tmp==0)ans=0;
 }
 pr(ans);
 /*
 whbrjpjyhsr y w l q j x d b r b a o m n w
 012345678910111213141516171819202122232425
 */
return 0;}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define loope(i,a,b) for(ll i=a;i<=b;i++)
#define test() ull t;cin>>t;while(t--)
#define pll pair<ll,ll>
#define puu pair<ull,ull>
#define f first
#define s second
#define pb push_back
#define mkp make_pair
#define ins insert
#define Vint vector<int>
#define Vll vector<ll>
#define Vull vector<ull>
#define nl cout<<endl
#define sp cout<<" "
#define MOD 1000000007
#define all(x) x.begin(),x.end()

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


ll dist[1005][1005];


void initialize(ll r,ll c){
	loop(i,0,r){
		loop(j,0,c){
			dist[i][j] = INT_MAX;
		}
	}
}

void bfs10(vector<vector<char>> v,ll s1,ll s2){
	dist[s1][s2] = 0;
	deque<pair<ll,ll>> dq;
	dq.push_front(mkp(s1,s2));
	ll r = v.size();
	ll c = v[0].size();
	while(!dq.empty()){
		pll p = dq.front();
		dq.pop_front();
		ll x = p.f;
		ll y = p.s;
		for(int i = 0;i<4;i++){
			ll x1 = x+dx[i];
			ll y1 = y+dy[i];
			if(x1<0||x1>r-1||y1<0 || y1>c-1)
				continue;
			if(v[x1][y1]=='.' && dist[x1][y1]>dist[x][y]){
				dist[x1][y1] = dist[x][y];
				dq.push_front(mkp(x1,y1));
			}
		}

		loop(i,-2,3){
			loop(j,-2,3){
				ll x1 = x + i;
				ll y1 = y + j;
				if(x1<0||x1>r-1||y1<0 || y1>c-1)
					continue;
				if(v[x1][y1]=='.' && dist[x1][y1]>dist[x][y]){
					dist[x1][y1] = dist[x][y]+1;
					dq.push_back(mkp(x1,y1));
				}		
			}
		}
	}
}

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

	ll r,c;
	ll s1,s2,f1,f2;
	cin>>r>>c>>s1>>s2>>f1>>f2;
	initialize(r+2,c+2);

	vector<vector<char>> v(r,vector<char>(c));

	loop(i,0,r){
		loop(j,0,c){
			cin>>v[i][j];
		}
	}

	bfs10(v,s1-1,s2-1);
	if(dist[f1-1][f2-1]==INT_MAX)
		cout<<-1;
	else
		cout<<dist[f1-1][f2-1];
}

Measured memory_bytes: 14772
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
#include <map>
#include<iomanip>
using namespace std;
using P = pair<int, int>;
using PP = pair<P, int>;
int MOD = 1000000007;


int N;
string S;

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

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))

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

L = [0]
g = 0
for i in range(N-1):
    g = gcd(g, A[i])
    L.append(g)

R = []
g = 0
for i in range(N-1):
    g = gcd(g, A[N-1-i])
    R.append(g)
R.reverse()
R.append(0)

ans = 0
for i in range(N):
    ans = max(ans, gcd(L[i],R[i]))

print(ans)


Measured memory_bytes: 14524
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#define dlog(str) cout << "====" << str << endl;
#else
#define dlog(str)
#endif
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define FOR(i, s, e) for(int i = s, i##_l = (e); i < i##_l; i++)
#define LLI long long int
#define _min(a,b) ((a<b)?a:b)
#define _max(a,b) ((a<b)?b:a)
#define chmax(a, b) a = _max(a, b)
#define chmin(a, b) a = _min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define pm(a) ((a)?1:-1)
#define SORT(v) sort(v.begin(),v.end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380


int main()
{
	cout << fixed << setprecision(10);
	LLI n, k;
	cin >> n >> k;
	vector<LLI> h(n);
	REP(i, n)
	{
		cin >> h[i];
	}
	RSORT(h);

	LLI ans = 0;
	for (int i = k; i < n; i++)
	{
		ans += h[i];
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ios ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define pll pair <long long,long long>
#define f first
#define s second
#define ll long long
using namespace std;
int main () {
	ios;
	ll n;
	cin>>n;
	ll a[n+1][4],d[n+1][4],us[n+1];
	for (int k=1;k<=n;k++) {
		for (int j=1;j<=3;j++) cin>>a[k][j];
	}
	d[1][1]=a[1][1];
	d[1][2]=a[1][2];
	d[1][3]=a[1][3];
	for (int k=2;k<=n;k++) {
		d[k][1]=max(d[k-1][2],d[k-1][3])+a[k][1];
		d[k][2]=max(d[k-1][3],d[k-1][1])+a[k][2];
		d[k][3]=max(d[k-1][1],d[k-1][2])+a[k][3];
	}
	cout<<max(d[n][1],max(d[n][2],d[n][3]));
	return 0;
}



Measured memory_bytes: 6528
#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;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;}
#define fore(i,a,b) for(ll i=(ll)(a);i<=(ll)(b);++i)
#define rep(i,n) fore(i,0,(n)-1)
#define all(x) (x).begin(),(x).end()

void solve(long long n, long long m, std::vector<long long> a){
    rep(i,n)a[i]--;
    vl sum1(2*m+5),sumM(2*m+5);
    rep(i,n-1){
        ll from=a[i],to=a[i+1];
        if(a[i]>a[i+1])to+=m;
        sum1[from+2]++;
        sum1[to+1]--;
        sumM[to+1]-=to-from-1;
    }

    rep(i,2*m)sum1[i+1]+=sum1[i];
    rep(i,2*m)sum1[i]+=sumM[i];
    rep(i,2*m)sum1[i+1]+=sum1[i];

    ll ma=0;
    rep(i,m){
        chmax(ma,sum1[i]+sum1[i+m]);
    }

    ll ans=0;
    rep(i,n-1){
        ll tmp=a[i+1]-a[i];
        if(tmp<0)tmp+=m;
        ans+=tmp;
    }
    ans-=ma;
    cout<<ans<<endl;
}

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


Measured memory_bytes: 4096
fun main(args: Array<String>) {
  val (h, w, k) = readLine()!!.split(" ").map { it.toInt() }
  for (y in 0..h) {
    for (x in 0..w) {
      if (y * (w - x) + (h - y) * x == k) {
        println("Yes")
        return
      }
    }
  }
  println("No")
}


Measured memory_bytes: 36076
#include<stdio.h>
#define N 101
#define INFTY 100000


int min(int, int);

int main(){
  unsigned int m[N][N];
  int n, p[N];
  int i, j, k,l;
  scanf("%d",&n);
  for(i=1;i<=n;i++)
    scanf("%d%d",&p[i-1],&p[i]);

  for(i=1;i<=n;i++)
    m[i][i]=0;
  
  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
    j=i+l-1;
    m[i][j]=INFTY;
    for(k=i;k<=j-1;k++)
      m[i][j]=min(m[i][j],m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
    }
  }
  printf("%d\n",m[1][n]);
  
  return 0;
}

int min(int x, int y)
{
  if(y<x) return y;
  return x;
}



Measured memory_bytes: 2108
from collections import deque
def main():
    s = deque(list(input()))
    q = int(input())
    r = 1
    for _ in range(q):
        n, *fc = input().split()
        if n == "1":
            r *= -1
        else:
            f, c = fc
            f = 1 if f == "1" else -1
            if f*r == 1:
                s.appendleft(c)
            else:
                s.append(c)
    print("".join(list(s)[::r]))

if __name__ == "__main__":
    main()

Measured memory_bytes: 76008
/*  
    Talkin' to myself and feelin' old
    Sometimes I'd like to quit, nothin' ever seems to fit
    Hangin' around, nothin' to do but frown
    Rainy days and Mondays always get me down
    _________________________
    _________________________
    936 Hours of Solitude
    Quarantine_Day : 39
*/

#include<bits/stdc++.h>

using namespace std;

typedef long long int       ll;
typedef vector<int>         vi;
typedef vector<ll>          vl;
typedef pair<int, int>      pii;
typedef pair<ll, ll>		pll;

#define pb(n)           push_back(n)
#define GSORT(v)        sort(v.begin(), v.end(), greater<int>())
#define SORT(v)         sort(v.begin(), v.end());
#define REV(v)          reverse(v.begin(), v.end());
#define db(a)           cout<<#a<<" = "<<a<<endl;
#define FIN             freopen("in.txt","r",stdin);
#define FOUT            freopen("out.txt","w",stdout);
#define REP(i,n)        for(int i = (int)(0); i < (int)(n); i++)
#define FOR(i, a, b)    for(int i = (int)a; i <= (int)b; i++)    

#define MAX 90

bool issqr(int n){
    int sq = sqrt(n);
    return (sq * sq) == n;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    string a, b; cin>>a>>b;
    string s = a + b;

    stringstream ss(s);
    int n; ss>>n;
    cout<<(issqr(n)?"Yes\n":"No\n");
    
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define LL long long
#define endl '\n'
using namespace std;
const LL MOD = 1e9+7;
const LL INF = 1e9+7;


int main(){

	int n;
	cin>>n;
	int ans = 0;
	map<int,int> mp;
	while(n--){
		int x;
		cin>>x;
		if(mp[x] == 0)mp[x] = 1;
		else mp[x] = 0;
	}
	for(auto it : mp){
		if(it.second == 1)ans++;
	}
	cout<<ans<<endl;
	return 0;
	
}


Measured memory_bytes: 4992
alpha_small_ = [chr(i) for i in range(97, 97+26)] #アルファベッドの小文字

n = int(input())
ans = []
def solve(now,i):
    if len(now) == n:
        ans.append(now)
        return
    for j in range(i+1):
        solve(now+alpha_small_[j],max(i,j+1))

solve("a",1)


for x in sorted(ans):
    print(x)

Measured memory_bytes: 13560
import sys
input = sys.stdin.readline


def main():
    N = int(input())
    carry = 0
    ans = 0
    for i in range(N):
        x = int(input())
        if carry and x > 0:
            ans += 1  # carry を優先して処理
            d, m = divmod(x - 1, 2)
            ans += d
            carry = m
        else:
            d, m = divmod(x, 2)
            ans += d
            carry = m
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
//----------------------------------------------------------------------
#include <bits/stdc++.h>
#include <cstddef>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
//----------------------------------------------------------------------

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;


ll lcm( ll a, ll b ) {
    return a / __gcd(a, b) * b;
}

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

    ll ans = 0;
    rep(i, n) {
        ans +=  a[i] - 1;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
function main(input) {
  var n = input[0]-0;
  var list = [];
  for(var i=1;i<=n;i++){
    list.push(input[i].split(" ").map(v=>v-0));
  }
  var dismap = {};
  for(var i=0;i<n;i++){
    for(var j=i+1;j<n;j++){
      dismap[j + "_" + i] = dismap[i + "_" + j] = distance(list[i], list[j]);
    }
  }
  var checklist = allpth(n);
  var sum = 0;
  for(var i=0;i<checklist.length;i++){
    sum += calcSum(dismap, checklist[i]);
  }
  console.log(sum/checklist.length);
}

function calcSum(dismap, list){
  var sum = 0;
  for(var i=1;i<list.length;i++){
    sum += dismap[list[i-1] + "_" + list[i]];
  }
  return sum;
}
function distance(a,b){
  return Math.sqrt(Math.pow(a[0]-b[0], 2) + Math.pow(a[1]-b[1], 2));
}

function allpth(n){
  var list = [];
  if(n==1) return [[0]];
  var baseList = allpth(n-1);
  for(var i=0;i<n;i++){
    for(var j=0;j<baseList.length;j++){
      var tmp = baseList[j].concat();
      tmp.splice(i,0,n-1);
      list.push(tmp);
    }
  }
  return list;
}

main(require('fs').readFileSync('/dev/stdin', 'utf8').split("\n"))


Measured memory_bytes: 51404
# solution

data = input()

qwe = int(input())

dic = set()

for i in range(len(data)):
    for j in range(qwe):
        if i+j+1 <= len(data):
            dic.add(data[i:i+j+1])
di = list(dic)
di.sort()
print(di[qwe-1])

Measured memory_bytes: 4464
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define ff first
#define ss second
#define mp make_pair
#define pp pair<ll,ll>
#define vi vector<pair<pp,pp> >
#define pq_min priority_queue<ll,vector<ll>,greater<ll>>
#define pq_max priority_queue<ll>
#define f(i,a,b) for(ll i=a;i<b;i++)
#define r(i,a,b) for(ll i=a;i>=b;i--)
#define precision(x,d) cout<<fixed<<setprecision(d)<<x
#define fill(a,b) memset((a),(b),sizeof((a)))
#define ld long double
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
typedef pair<pp,pp> ppll;
const ll mod=1e9+7;
const ll N=2e18 + 5;

ll power(ll a,ll b,ll p)
{
    a=a%p;
    ll ans=1;
    while(b>0)
    {
        if(b%2==1)
        {
            ans=(ans*a)%p;
        }
        b=b/2;
        a=(a*a)%p;
    }
    return ans;
}

 
int main()
{
    fast;
    ll n,x,y;
    cin>>n>>x>>y;
    map<ll,ll> p;
    for(ll i=1;i<=n;i++)
    {
        for(ll j=i+1;j<=n;j++)
        {
            if(x>=i && y<=j)
            {
                p[(x-i) + (j-y) + 1]++;
            }
            else if((i<=x && j<=x) || (i>=y && j>=y))
            {
                p[(j-i)]++;
            }
            else
            {
                ll z=abs(i-x);
                ll d=abs(j-y);
                ll h=min(z+d+1,(j-i));
                p[h]++;
            }
        }
    }
    for(ll i=1;i<=n-1;i++)
    {
        cout<<p[i]<<endl;
    }



    /*ll h=y-x;
    for(ll i=1;i<h;i++)
    {
        if(i==1)
        {
            cout<<n<<endl;
        }
        else
        {
            ll g=(n-i);
            ll d;
            if(x - (i-1)>=1)
            {
                d=i;
            }
            else
            {
                d = (x-1)+1;
            }
            ll m;
            if(y + (i-1) <= n )
            {
                m = i;
            }
            else
            {
                m = (n-y)+1;
            }
            cout<<min(d,m)+g<<endl;
        }
    }
    for(ll i=h;i<=(n-1);i++)
    {

    }*/
}

Measured memory_bytes: 384
N = int(input())

task = []
for i in range(N):
	task.append([int(x) for x in input().split()])

task.sort(key = lambda x: x[1])

sum = 0
for i in range(N):
	sum += task[i][0]
	if sum > task[i][1]:
		print('No')
		break
	elif i == N - 1:
		print('Yes')

Measured memory_bytes: 41172
#pragma region
#include <bits/stdc++.h>
using namespace std;
inline void ci(void){
  return;
}
template <typename First, typename... Rest>
void ci(First& first, Rest&... rest){
  cin >> first;
  ci(rest...);
  return;
}
inline void co(void){
  cout << "\n";
  return;
}
template <typename First, typename... Rest>
void co(First first, Rest... rest){
  cout << first << " ";
  co(rest...);
  return;
}
#define ll long long
#define ld long double
#define st string
#define dl double
#define wh while
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define tp tuple
#define sc second
#define ve vector
#define tos to_string
#define len length
#define repi(i, m, n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i, n) repi(i, 0, n)
#define sz(v) ((int)(v).size()) 
#define ea(i, n) for(auto&& i: n)
#define so(n) sort(n.begin(), n.end())
#define sp(n) cout << fixed << setprecision(n)
#pragma endregion
// abs 絶対値, rtsq ルート, pow(a, n) aのn乗

int main() {
  int N, b = 1000000000;
  ci(N);
  ve<int> X(N);
  rep(i, N){
    ci(X.at(i));
  }
  rep(i, 100){
    int a = 0;
    rep(j, N){
      a += pow(X.at(j) - i, 2);
    }
    b = min(b, a);
  }
  co(b);
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int M = sc.nextInt();
        int[] X = new int[M];
        for (int i = 0; i < M; i++) {
            X[i] = sc.nextInt();
        }
        sc.close();

        if (N >= M) {
            System.out.println(0);
            System.exit(0);
        } else {
            Arrays.sort(X);
            int[] dist = new int[M - 1];
            for (int i = 0; i < M - 1; i++) {
                dist[i] = X[i + 1] - X[i];
            }
            Arrays.sort(dist);
            int sum = 0;
            for (int i = 0; i < M - N; i++) {
                sum += dist[i];
            }
            System.out.println(sum);
        }
    }
}


Measured memory_bytes: 50560