akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>

using namespace std;

int main()
{
  	int N, M;
  	cin >> N;
  	vector<string> s(N);
  	for(int i = 0; i < N; i++){
      	cin >> s.at(i);
    }
  	cin >> M;
  	vector<string> t(M);
  	for(int i = 0; i < M; i++){
      	cin >> t.at(i);
    }
  	int a = 0;
  	for(int i = 0; i < N; i++){
      	int b = 0;
      	for(int j = 0; j < N; j++){
          	if(s.at(j) == s.at(i)){
              	b++;
            }
        }
      	for(int j = 0; j < M; j++){
          	if(t.at(j) == s.at(i)){
              	b--;
            }
        }
      	if(a < b){
          	a = b;
        }
    }
  	cout << a;
  	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define Graph vector<vector<int>>;
#define iterG(next_v, G, v) for(auto next_v : G[v]
int main(){
    int k, n;
    vector<int> a;
    cin >> k>> n;
    int tmp;
    rep(i, n){
        cin >> tmp;
        a.push_back(tmp);
    }
    int maxlen = 0;
    rep(i, n-1){
        maxlen = max(maxlen, a[i+1] - a[i]);
    }
    maxlen = max(maxlen, a[0] + k - a[n-1]);
    cout << k - maxlen << endl;
    return 0;
}



Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6+5;
vector<long long> vec[30];
long long id[30], cur, l = -1;
int main()
{
	string s, t;
	cin >> s >> t;
	long long n = s.size();
	for(int i=0; i<s.size(); i++) vec[s[i]-'a'].push_back(i);
	for(int i=0; i<t.size(); i++)
	{
		long long c = t[i]-'a';
		if(vec[c].empty()) return cout << -1 << endl, 0;
		if(vec[c].back() <= l) cur++, l = -1;
		l = *upper_bound(vec[c].begin(), vec[c].end(), l);
	}
	cout << cur*n+l+1 << endl;
}
	


Measured memory_bytes: 1724
import Foundation

let number = readLine()!.componentsSeparatedByString(" ")
let days = [Character](readLine()!.characters)

let N = Int(number[0])!
let K = Int(number[1])!
let C = Int(number[2])!

func greedyDays(days: [Character], rest: Int, work: Int, isLeft: Bool) -> [Int] {
    var notWork = rest
    var result: [Int] = []
    var i = isLeft ? 0 : days.count - 1
    while (isLeft && i < days.count) || (!isLeft && i >= 0) {
        if result.count == work {
	        break
        }
        if days[i] == "o" && notWork >= rest {
            result.append(i+1)
            notWork = 0
        } else {
            notWork += 1
        }
        i += isLeft ? 1 : -1
    }
    return isLeft ? result : result.reverse()
}

var left: [Int] = greedyDays(days, rest: C, work: K, isLeft: true)
var right: [Int] = greedyDays(days, rest: C, work: K, isLeft: false)

if left.count == K && right.count == K { 
    for i in 0..<left.count {
      if left[i] == right[i] {
        print(left[i])
      }
    }
}

Measured memory_bytes: 9048
////////////////////////////////////////////////////////////////////
// This source code is for Visual Studio
////////////////////////////////////////////////////////////////////
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <sstream>
#include <iterator>
#include <stack>
#include <functional>
#include <iomanip>
#include <string>
#include <cstring>
#include <deque>
#include <math.h>
#include <assert.h>

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

using namespace std;

typedef long long ll;
typedef uint32_t u32;
typedef uint64_t u64;

// main function
int main()
{
	ll N = 0;
	ll ans = 0;

	cin >> N;
	map<ll, ll> A;
	map<ll, ll>::iterator itr;
	Rep(i, N) {
		ll tmp = 0;
		cin >> tmp;
		A[tmp]++;
	}

	ll even = 0;
	ll odd = 0;
	for (itr = A.begin(); itr != A.end(); itr++) {
		if (itr->second % 2 == 0) {
			even++;
		}
		else {
			odd++;
		}
	}
	ans += odd;
	ans += even - even % 2;

	cout << ans << endl;

	return 0;
}


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

struct frame_data {
  int H;
  int W;
};

int main () {
  
  int H,W;
  std::vector<frame_data> v;

  do {
    std::cin >> H >> W;
    v.push_back({H,W});
  } while (H != 0 && W != 0);

  for(int i = 0; i < v.size(); i++){

    for(int h_num = 0; h_num < v[i].H; h_num++){

      for(int w_num = 0; w_num < v[i].W; w_num++){
        if(h_num == 0 || h_num == v[i].H - 1)
          std::cout << '#';
        else if (w_num ==0 || w_num == v[i].W - 1)
          std::cout << '#';
        else
          std::cout << '.';
      }
      std::cout << std::endl;
    }

    if(i != v.size() - 1)
      std::cout << std::endl;
  }

  return 0;
}



Measured memory_bytes: 3116
#define _CRT_SECURE_NO_WARNINGS

#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>

//for
#define REP(i,n) for(int i=0,i##_len=(int)(n);i<i##_len;i++)
#define REPS(i,n) for(int i=1,i##_len=(int)(n);i<=i##_len;i++)
#define RREP(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define RREPS(i,n) for(int i=(int)(n);i>0;i--)
#define SREP(i,s,n) for(int i=(int)(s),i##_len=(int)(n);i<i##_len;i++)

//printf
#define PRINTD(d) printf("%d\n",(d))

//memset
#define m0(s) memset(s,0,sizeof(s))
#define ml(s) memset(s,63,sizeof(s))
#define fill(s,c) memset(s,c,sizeof(s))

#define INF 1e9

typedef long long ll;
int diff[4][2] = {
	{ 0, -1 },
	{ -1, 0 },
	{ 1, 0 },
	{ 0, 1 },
};

int Min(int a, int b) {
	return (a)<(b) ? (a) : (b);
}
int Max(int a, int b) {
	return (a) > (b) ? (a) : (b);
}
void Swap(int *a, int *b) {
	int tmp = *a;
	*a = *b;
	*b = tmp;
}

int main() {
	int n, k;
	scanf("%d %d", &n, &k);
	int s = k + 1;
	ll ans = 0;
	SREP(i, s, n+1) {
		ans += (ll)(i - k)*(n / i);
		if (n%i > 0) {
			if (k == 0) {
				ans += n%i;
			}
			else {
				if(n%i - (k - 1)>0)ans += n%i - (k - 1);
			}
		}
	}
	printf("%lld\n", ans);
}

Measured memory_bytes: 128
#include<iostream>
#include<string>
using namespace std;
int main()
{
	string a, b;
	cin >> a >> b;
	int t = a.length();
	for (int i = 0; i < t; i++)
	{
		int ch = 0;
		for (int y = 0; y < t; y++)
		{
			if (a[(i + y) % t] == b[y])
				ch++;
		}
		if (ch == t)
		{
			puts("Yes");
			return 0;
		}
	}
	puts("No");
}

Measured memory_bytes: 256
#include<stdio.h>

int main() {
	int a, b;
	int d, r;
	double f;
	scanf("%d %d", &a, &b);
	d = a / b;
	r = a % b;
	f = (double)a / (double)b;
	printf("%d %d %lf\n", d, r, f);
	return 0;
}


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

using namespace std;

#define ll long long int
#define vi vector<int>
#define prec fixed<<precision(10)
#define mod 1000000007
#define set(x) __builtin_popcount(x)
#define ffs(x) __builtin_ffs(x)

vector<int> graph[100001];
vector<int> vis1(100001,0);
vector<int> col(100001,0);
map<pair<int,int>,int> mp;
void dfs(int src){
	vis1[src]=1;
	for(auto child: graph[src]){
		if(vis1[child]!=1){
			if((mp[make_pair(child,src)])%2==1)
			 col[child]=1-col[src];
			else col[child]=col[src];
			dfs(child);
		}
	}
}


int main(){
col[1]=1;
	int e;
	cin >> e;
	int a;
	for(int i=0;i<e-1;i++){
		int c,d,k;
		cin >> c >> d >> k;
		graph[c].push_back(d);
		graph[d].push_back(c);
		mp[make_pair(c,d)]=k;
		mp[make_pair(d,c)]=k;
	}
 	dfs(1);
 	for(int i=1;i<=e;i++)cout << col[i] <<'\n';
 }


Measured memory_bytes: 23552
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;

#define BIAS 20000
bool ab[BIAS * 2];
bool bc[BIAS * 2];
bool ca[BIAS * 2];

void init(const string& S, const string& T, bool *M) {
  for (int i = 0; i < S.size(); i++) {
    for (int j = 0; j < T.size(); j++) {
      if (S[i] != '?' && T[j] != '?' && S[i] != T[j]) {
        M[i-j+BIAS] = true;
      }
    }
  }
}
int main() {
  ios::sync_with_stdio(false);
  string A, B, C;
  cin >> A >> B >> C;

  init(A, B, ab);
  init(B, C, bc);
  init(C, A, ca);
  int la = A.size();
  int lb = B.size();
  int lc = C.size();
  int a = 0;
  int ret = la + lb + lc;
  for (int b = -4000; b <= 4000; b++) {
    for (int c = -4000; c <= 4000; c++) {
      if (ab[b-a+BIAS] || bc[c-b+BIAS] || ca[a-c+BIAS]) continue;
      int L = min(a, min(b, c));
      int R = max(a + la, max(b + lb, c + lc));
      ret = min(ret, R - L);
    }
  }
  cout << ret << endl;
}

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

int main() {
  int N;
  cin >> N;
  
  vector<string> s(N);
  for (int i=0; i<N; i++) {
  	cin >> s.at(i);
  }
  
  int M;
  cin >> M;
  
  vector<string> t(M);
  for (int i=0; i<M; i++) {
  	cin >> t.at(i);
  }
  
  int ans = 0;
  
  for (int i=0; i<N; i++) {
    int X = 0;
  	string word = s.at(i);
    for (int j=i; j<N; j++) {
    	if (s.at(j) == word) {
	      X++;
        }
    }
    for (int j=0; j<M; j++) {
    	if (t.at(j) == word){
          X--;
        }
    }
    if (ans < X) {
      ans = X;
    }
  }
  
  if (ans < 0) {
    ans = 0;
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	string s;
	cin>>s;
	for(size_t i=0;i<s.length()-2;i++){
		if(islower(s[i])&&islower(s[i+1])&&islower(s[i+2])){
			cout<<s[i]<<s[i+1]<<s[i+2];
			break;
		}
	}
}


Measured memory_bytes: 3652
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;
import java.util.Scanner;

//String With Rings
public class Main{

	List<Integer>[] e;
	int res;
	boolean[] v;
	
	void dfs(int k, int d){
		res = Math.max(res, d);
		for(int x:e[k])if(!v[x]){
			v[x] = true;
			dfs(x, d+1);
			v[x] = false;
		}
	}
	
	@SuppressWarnings("unchecked")
	void run(){
		Scanner sc = new Scanner(System.in);
		Random rand = new Random(1334259345907L);
		for(;;){
			int n = sc.nextInt();
			if(n==0)break;
			e = new List[101];
			for(int i=1;i<101;i++)e[i]=new ArrayList<Integer>();
			boolean[] u = new boolean[101];
			while(n--!=0){
				int a = sc.nextInt(), b = sc.nextInt();
				u[a] = u[b] = true;
				e[a].add(b); e[b].add(a);
			}
			v = new boolean[101];
			res = 0;
			int[] a = new int[100];
			int id = 0;
			for(int i=1;i<101;i++)if(!e[i].isEmpty())a[id++] = i;
			//開始点を全部試すとつらいからN/3個だけランダムにチョイスして絞るという迷走っぷり
			for(int i=0;i<=id/3;i++){
				Arrays.fill(v, false);
				int s = rand.nextInt(id);
				v[a[s]] = true;
				dfs(a[s], 1);
			}
			System.out.println(res);
		}
	}

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

Measured memory_bytes: 13000
//Code by Mukul Totla
#include<bits/stdc++.h>
using namespace std;
#define ll long long
void sublime(){ 
	  #ifndef ONLINE_JUDGE 
    freopen ("input.txt", "r", stdin);
    freopen ("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);
      }
	
int main()
{   
   //sublime();
  	  ll n,i;
	   cin>>n;
	   ll a[n+1],b[n+1],c[n+1];
	   for(i=1; i<=n; i++)
	    cin>>a[i]>>b[i]>>c[i]; 

	   ll dp[n+1][3];
	   memset(dp,0,sizeof(dp));

	   dp[1][0]=a[1];
	   dp[1][1]=b[1];
	   dp[1][2]=c[1];
	   
	   for(i=2; i<=n; i++)
	   {
	   	 dp[i][0]=a[i]+max(dp[i-1][1],dp[i-1][2]);
	   	 dp[i][1]=b[i]+max(dp[i-1][0],dp[i-1][2]);
	   	 dp[i][2]=c[i]+max(dp[i-1][0],dp[i-1][1]);
	   }
	   ll ans=max(dp[n][0],max(dp[n][1], dp[n][2]));
	   cout<<ans;
	return 0;
}

Measured memory_bytes: 8248
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
#include<fstream>
#include<set>
using namespace std;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = (int)(a); i < (int)(b); i++)
#define out(str) cout << str << endl
#define ALL(a) (a).begin(),(a).end()
#define INF (1<<29)

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

ll gcd(ll a, ll b) {
  return b != 0 ? gcd(b, a % b) : a;
}

ll A,B,g,ans;

int main(){
    cin>>A>>B;
    g = gcd(A,B);
    repi(i,2,sqrt(1e12)+1){
        if(g%i==0){
            ans++;
            while(g%i==0)g/=i;
        }
    }
    if(g>sqrt(1e12))ans++;
    out(ans+1);

}


Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, const char * argv[]) {
    
    int i,a[26]={0};
    
    char str[1200];
    
    while (scanf("%s",str) != EOF) {
            for (i = 0; str[i] != '\0'; i++) {
                if (str[i] >= 'A' && str[i] <= 'Z') {
                    str[i] += 32;
                }
                a[str[i]-'a']++;
            }
        }
    
    for (i = 0; i < 26; i++) {
        printf("%c : %d\n",i+'a',a[i]);
    }
    return 0;
}

Measured memory_bytes: 540
// URL: https://atcoder.jp/contests/abc131/tasks/abc131_a

import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.string;

version(unittest) {} else
void main()
{
  string s; io.getV(s);
  io.putB(s[0] == s[1] || s[1] == s[2] || s[2] == s[3], "Bad", "Good");
}

auto io = IO();

struct IO
{
  import std.algorithm, std.conv, std.format, std.range, std.stdio, std.traits;

  dchar[] buf;
  auto sp = (new dchar[](0)).splitter;
  int precision = 10;
  string delimiter = " ";

  void nextLine()
  {
    stdin.readln(buf);
    sp = buf.splitter;
  }

  auto get(T)(ref T v)
  {
    if (sp.empty) nextLine();
    v = sp.front.to!T;
    sp.popFront();
  }

  auto getV(T...)(ref T v)
  {
    foreach (ref w; v) get(w);
  }

  auto getA(T)(size_t n, ref T v)
  {
    v = new T(n);
    foreach (ref w; v) get(w);
  }

  auto getC(T...)(size_t n, ref T v)
  {
    foreach (ref w; v)
      w = new typeof(w)(n);
    foreach (i; 0..n)
      foreach (ref w; v) get(w[i]);
  }

  auto getM(T)(size_t r, size_t c, T v)
  {
    v = new T(r, c);
    foreach (ref w; v) getA(c, w);
  }

  auto putA(T)(T v)
  {
    static if (isInputRange!T && hasLength!T && !isSomeString!T) {
      foreach (i, w; v) {
	putA(w);
	if (i < v.length - 1) write(delimiter);
      }
    } else if (isFloatingPoint!T) {
      writef(format("%%.%df", precision), v);
    } else {
      write(v);
    }
  }

  auto put(T...)(T v)
  {
    foreach (i, w; v) {
      putA(w);
      if (i < v.length - 1) write(delimiter);
    }
    writeln;
  }

  auto putB(S, T)(bool c, S t, T f)
  {
    if (c)
      put(t);
    else
      put(f);
  }
}


Measured memory_bytes: 256
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
constexpr int MOD = 1000000007;
constexpr int INF = 2000000000;

int Par[100000];   //???
int Rank[100000];  //??¨?????±???

//n????´???§?????????
void init(int n) {
	for (int i = 0; i < n; i++) {
		Par[i] = i;
		Rank[i] = 0;
	}
}

//??¨??????????±???????
int find(int x) {
	if (Par[x] == x) {
		return x;
	}
	else {
		return Par[x] = find(Par[x]);
	}
}

//x??¨y????±??????????????????????
void unite(int  x, int y) {
	x = find(x);
	y = find(y);
	if (x == y) return;
	if (Rank[x] < Rank[y]) {
		Par[x] = y;
	}
	else {
		Par[y] = x;
		if (Rank[x] == Rank[y])Rank[x]++;
	}
}

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

int main() {
	int n, q;
	std::cin >> n >> q;
	init(n);
	int a, b, c;
	for (int i = 0; i < q; i++) {
		std::cin >> a >> b >> c;
		if (a == 0) {
			unite(b, c);
		}
		else {
			std::cout << (same(b, c) ? 1 : 0) << std::endl;
		}
	}
}

Measured memory_bytes: 3180
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 1e9;
// const int MOD = 1e9 + 7;

template <int mod>
struct ModInt {
    int val;
    ModInt() : val(0) {}
    ModInt(long long x) : val(x >= 0 ? x % mod : (mod - (-x) % mod) % mod) {}
    int getmod() { return mod; }
    ModInt &operator+=(const ModInt &p) {
        if ((val += p.val) >= mod) {
            val -= mod;
        }
        return *this;
    }
    ModInt &operator-=(const ModInt &p) {
        if ((val += mod - p.val) >= mod) {
            val -= mod;
        }
        return *this;
    }
    ModInt &operator*=(const ModInt &p) {
        val = (int)(1LL * val * p.val % mod);
        return *this;
    }
    ModInt &operator/=(const ModInt &p) {
        *this *= p.inverse();
        return *this;
    }
    ModInt operator-() const { return ModInt(-val); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
    bool operator==(const ModInt &p) const { return val == p.val; }
    bool operator!=(const ModInt &p) const { return val != p.val; }
    ModInt inverse() const {
        int a = val, b = mod, u = 1, v = 0, t;
        while (b > 0) {
            t = a / b;
            swap(a -= t * b, b);
            swap(u -= t * v, v);
        }
        return ModInt(u);
    }
    ModInt pow(long long n) const {
        ModInt ret(1), mul(val);
        while (n > 0) {
            if (n & 1) ret *= mul;
            mul *= mul;
            n >>= 1;
        }
        return ret;
    }
    friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.val; }
    friend istream &operator>>(istream &is, ModInt &a) {
        long long t;
        is >> t;
        a = ModInt<mod>(t);
        return (is);
    }
    static int get_mod() { return mod; }
};
const int MOD = 998244353;  // if inv is needed, this shold be prime.
using modint = ModInt<MOD>;

modint dp[3005][6005];
int main() {
    int N, S;
    cin >> N >> S;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A.at(i);
    }

    for (int i = 0; i < N; i++) {
        dp[i + 1][0] += 1;
        dp[i + 1][A[i]] += 1;
        for (int s = 0; s <= S; s++) {
            dp[i + 1][s] += dp[i][s] * 2;
            dp[i + 1][s + A[i]] += dp[i][s];
        }
    }

    cout << dp[N][S] << endl;
}


Measured memory_bytes: 74112
s=input()
for i in range(1,len(s)):
    s1=s[0:len(s)-i]
    if len(s1)%2!=0:
        continue

    s2=s1[0:len(s1)//2]
    s3=s1[len(s1)//2:len(s1)]
    if s2==s3:
        print(len(s1))
        exit()

Measured memory_bytes: 3060
<?php
  list($n) = explode(" ", trim(fgets(STDIN)));
  $a = explode(" ", trim(fgets(STDIN)));

  $ans = [];
  for ($i=0; $i<$n; $i++) {
    $ans[]=0;
  }

  for ($i=0; $i<$n-1; $i++){
    $ans[$a[$i]-1]++;
  }

  for ($i=0; $i<$n; $i++) {
    echo $ans[$i].PHP_EOL;
  }

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


int main(){
    int N; cin >> N;
    vector<int> prime_table;
    int mod=pow(10,9)+7;

    vector<int> List(N+1, true);
    int i=2;
    while(i*i<=N){
        if(List[i]){
            int j=2*i;
            while(j<=N){
                List[j]=false;
                j+=i;
            }
        }
        i++;
    }

    for(int j=2; j<=N; j++){
        if(List[j]) prime_table.push_back(j);
    }

    long long ans=1;

    for(int i=0; i<prime_table.size(); i++){
        int prime=prime_table[i];
        int cnt=0;
        for(int j=2; j<=N; j++){
            int a=j;
            while(a%prime==0){
                a/=prime;
                cnt++;
            }
        }
        ans=(ans*(cnt+1))%mod;
        
    }

    cout << ans << endl;
    

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
using namespace std;
 
int main() {
  ll a, b, cnt=1, ans=1;
  cin >> a >> b;
  if(b > a)swap(a, b);
  vector<ll> ret;
  for(ll i = 1; i*i <= a; i++){
    if(a % i == 0){
      if(b % i == 0)ret.push_back(i);
      if(i * i != a && b % (a/i) == 0)ret.push_back(a/i);
    }
  }
  sort(all(ret));
  for(ll i = 1; i < ret.size(); i++){
    if(__gcd(cnt, ret.at(i)) == 1) {
      cnt*=ret.at(i);
      ans++;
    }
  }
  cout << ans;
}

Measured memory_bytes: 384
//Awwawa! Dis cold yis ratten buy waxberry!
#include <bits/stdc++.h>
#define ll long long
#define maxn 5005 /*rem*/
#define mod 1000000007
#define db double
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define pi pair<int, int>
#define fi first
#define se second

template <typename T> bool chkmax(T &x,T y){return x<y?x=y,true:false;}
template <typename T> bool chkmin(T &x,T y){return x>y?x=y,true:false;}

using namespace std;
ll ksm(ll a, ll b) {
   if (!b) return 1;
   ll ns = ksm(a, b >> 1);
   ns = ns * ns % mod;
   if (b & 1) ns = ns * a % mod;
   return ns;
}
int s;
int u, v;
int gcd(int a, int b) {
	return __gcd(a, b);
} 
ll ans = 0;
bool chk(int a, int b, int x, int y, int q) {
	ll f = a * y + b * x - q - gcd(b, y) - gcd(abs(a - b), u);
	if (f <= s) return 1;
	return 0;
}
void work() {
	int rb = s + 3 * u + 1;
	for (int y = u - 1; u - y <= y; y--)
		for (int a = 1; a < v; a++) {
			if (y * a > rb) break;
			int rd = 2;
			if (u - y == y) rd = 1;
			
			int x = u - y;
			int eb = (s - y * a) / x;
			int st = 1;
			int ng = gcd(a, x);
			if (eb > 0) {
				eb = min(eb, v - 1);
				st = eb + 1;
				ans += eb * rd;
			}
			while (st < v) {
				if (x * st + a * y > rb) break;
				if (chk(a, st, x, y, ng)) ans += rd;
				st++;
			}
		}
}
int main() {
	int w, h, k;
	cin >> w >> h >> k;
	s = 2 * (k - 1);
	u = w, v = h, work();
	u = h, v = w, work();
	ans *= 2;
	cout << ans << endl;
	return 0;
}
/*
100000 100000 100000
*/

Measured memory_bytes: 3640
def main():
    H, W, N = map(int, input().split())
    sr, sc = map(int, input().split())
    S = input()
    T = input()
    # right
    t = sc
    for i in range(N):
        if S[i] == 'R':
            t += 1
        if t > W:
            return True
        if T[i] == 'L' and t > 1:
            t -= 1
    # left
    t = sc
    for i in range(N):
        if S[i] == 'L':
            t -= 1
        if t < 1:
            return True
        if T[i] == 'R' and t < W:
            t += 1
    # up
    t = sr
    for i in range(N):
        if S[i] == 'U':
            t -= 1
        if t < 1:
            return True
        if T[i] == 'D' and t < H:
            t += 1
    # down
    t = sr
    for i in range(N):
        if S[i] == 'D':
            t += 1
        if t > H:
            return True
        if T[i] == 'U' and t > 1:
            t -= 1
    return False
if main():
    print('NO')
else:
    print('YES')


Measured memory_bytes: 44256
#include <iostream>
#include <iomanip>
#include <random>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <numeric>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <sstream>
#include <bitset>
#include <cassert>
#include <fstream>
#include <queue>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
	#define DBG(X) cout << #X << "=" << (X) << '\n';
	#define SAY(X) cout << (X) << '\n';
#else
	#define DBG(X)
	#define SAY(X)
#endif
 
using namespace std;

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

const int INT_INF = (int)(2e9);
const ll  LL_INF  = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for(auto el: v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for(auto& elem: ret) cin >> elem; return ret; }

void solve() {
	ll n = fetch<ll>();
	cout << n * n << '\n';
}

int main() {
	fast_io();
	solve();

	return 0;
}


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

int main()
{
    int n;
    cin>>n;
   string a;
  
    string s =to_string(n);
  
    string j = s.substr(s.length()-1,1);

    if(j=="3")
    {
       a = "bon";
    }
   else if(j=="0"||j=="1"||j=="6"||j=="8")
   {
        a = "pon";
   }
   else
   {
       a = "hon";
   }

   cout<<a<<endl;

}

Measured memory_bytes: 3696
import collections


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a


ans = 0
n = int(input())
c = collections.Counter(prime_factorize(n))
cnt = list(c.values())
# print(cnt)
for i in range(len(cnt)):
    mainasu = 1
    while True:
        if cnt[i] == 0 or cnt[i] < mainasu:
            break
        # print(cnt[i], mainasu)
        cnt[i] -= mainasu
        mainasu += 1
        ans += 1


print(ans)


Measured memory_bytes: 9464
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
using namespace std;
using ll=long long;
int main(){
    int n;
    cin>>n;
    n*=2;
    vector<int>l(n);
    rep(i,n)cin>>l[i];
    sort(l.rbegin(),l.rend());
    int ans=0;
    for(int i=0; i<n-1; i+=2){
        ans+=l[i+1];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
monster_hp_list = list(map(int, input().split()))
monster_hp_list = sorted(monster_hp_list)

for i in range(K):
    if len(monster_hp_list) >= 1:
        monster_hp_list.pop()
        K -= 1
    else:
        break
print(sum(monster_hp_list))


Measured memory_bytes: 26764
#include<stdio.h>
int main(){
    int a,b;
    char op;
    scanf("%d %c %d",&a,&op,&b);
    switch(op){
        case '+':printf("%d\n",a+b);
                 break;
        case '-':printf("%d\n",a-b);
                 break;
    }
}

Measured memory_bytes: 128
n, m, k = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

a_sum = [0]
b_sum = [0]
cnt = 0
best_b = m
confirm = ()

for i in a:
    a_sum.append(i + a_sum[-1])

for i in b:
    b_sum.append(i + b_sum[-1])

for a_idx in range(n + 1):
    if a_sum[a_idx] > k:
        break
    for b_idx in reversed(range(best_b + 1)):
        if b_sum[b_idx] + a_sum[a_idx] <= k:
            # if cnt < a_idx + b_idx:
            cnt = max(cnt, a_idx + b_idx)
            best_b = b_idx
            break

print(cnt)


Measured memory_bytes: 47644
using System;
using System.Linq;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;

class Program
{
    static void Main(string[] args)
    {
        int N = ReadLineParseInt();
        int[] h = ReadLineParseIntArray();
        int[] cost = new int[N];
        cost[0] = 0;
        cost[1] = Abs(h[0] - h[1]);
        for(int i = 2; i < N; i++)
        {
            cost[i] = Min(cost[i - 1] + Abs(h[i] - h[i - 1]), cost[i - 2] + Abs(h[i] - h[i - 2]));
        }
        WriteLine(cost.Last());
    }

    static int ReadLineParseInt() => int.Parse(ReadLine());
    static int[] ReadLineParseIntArray() => ReadLine().Split(' ').Select(int.Parse).ToArray();
}

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

void file() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}

void fast()
{
    std::ios_base::sync_with_stdio(0);
    cin.tie(NULL); cout.tie(NULL);
}
const int P = (int) 1e9 + 7;
const int MAX = 2e5 + 5;

ll n, k, dp[MAX];

ll fastPower(ll x, ll y)  
{  
    ll res = 1;
  
    x = x % P;  
   
    if (x == 0) return 0;
  
    while (y > 0)  
    {  
        if (y & 1)  
            res = (res*x) % P;  
        y = y>>1;
        x = (x*x) % P;  
    }  
    return res;  
}

int main(int argc, char const *argv[])
{
    file();
    // https://codeforces.com/blog/entry/75894?#comment-601667

    memset(dp, 0, sizeof(dp));

    cin>>n>>k;

    for (int gcd = k; gcd >= 1; --gcd)
    {
        int multipliesOfCurrentGCD = k / gcd;
        int numberOfSequences = fastPower(multipliesOfCurrentGCD, n);
        int overCounting = 0;

        for (int i = 2 * gcd; i <= k; i+=gcd)
        {
            overCounting = (overCounting + dp[i]) % P;
        }
        dp[gcd] = (numberOfSequences - overCounting + P) % P;
    }
    
    for (int i = 1; i <= k; ++i)
    {
        dp[0] = (((dp[i] % P * i % P) % P) % P + dp[0] % P)%P;
        dp[0]%=P;
    }
    cout<<dp[0];

}

Measured memory_bytes: 5176
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
int main(){
	int n;cin>>n;
  vector<int>dp(n+10,-1);
  dp[0]=0;
  rep(i,n){if(i<n&&dp[i]>=0)dp[i+7]=dp[i+7]=max(dp[i+7],dp[i]+1);}
  rep(i,n){if(i<n&&dp[i]>=0)dp[i+4]=dp[i+4]=max(dp[i+4],dp[i]+1);}
       if(dp[n]>=0)cout<<"Yes"<<endl;
           else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS 1
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <sstream>
#include <climits>
#include <cmath>
#include <map>
#include <stack>
using namespace std;
#define M_PI 3.141592
#define toRad 2.0*M_PI/360.0
#define inin(x) int x;cin>>x;
#define all(x) x.begin(),x.end()
#define debug(x) cout<<#x<<" "<<x<<endl;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define EPS 1e-12
#define pri_max 60000
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
/*
bool memo[pri_max] = {};
vector<int> pri;
void calc()
{
	for (int i = 2; i < pri_max; i++)
	{
		if (memo[i] == false)
		{
			pri.push_back(i);
			for (int l = i; l < pri_max; l += i)
			{
				memo[l] = true;
			}
		}
	}
}*/
int main()
{
	string x;
	int m[1001] = {};
	int c[1001][2] = {};


	for (int l = 0; l < 2;l++) while (getline(cin, x) && x != "")
	{
		vector<string> d;
		stringstream ss(x);
		while (getline(ss, x, ','))d.push_back(x);
		m[atoi(d[0].c_str())]++;
		c[atoi(d[0].c_str())][l]++;
	}
	for (int i = 0; i <= 1000; i++)
	{
		if (c[i][0] && c[i][1])
		{
			cout << i << " " << m[i] << endl;
		}
	}

}

Measured memory_bytes: 1224
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;
 
const static int mx[] = {1,-1,1,-1};
const static int my[] = {1,-1,-1,1};

P multiply_ginkgo(const P& p1,const P& p2){
  int a = p1.first * p2.first;
  int b = p1.second * p2.second;
  return P(a-b,a+b);
}

bool is_divisor(const P& p1,const P& p2){
  //judge p1(m,n) is a divisor of p2(p,q)
  
  //if and only if the integer m^2 + n^2 is a common divisor
  //of mp + nq and mq − np
  
  int m = p1.first;
  int n = p1.second;
  
  int p = p2.first;
  int q = p2.second;

  int c = m*m+n*n;
  if((m*p+n*q) % c == 0 && (m*q-n*p) % c == 0){
    return true;
  }
  return false;
}

bool is_eight_divisor(const P& p1,int m,int n){
  //<1, 0>, <0, 1>, <-1, 0>, <0,-1>,
  //<m, n>, <-n,m>, <-m,-n> and <n,-m> 
  //are divisors of <m, n>.
  int p = p1.first;
  int q = p1.second;

  const int candidate_p[] = {1,0,-1,0,m,-n,-m,n};
  const int candidate_q[] = {0,1,0,-1,n,m,-n,-m};

  for(int i=0;i<8;i++){
    if(p == candidate_p[i]
       && q == candidate_q[i]) return true;
  }
  return false;
}
int main(){
  int N;
  while(~scanf("%d",&N)){
    for(int i=0;i<N;i++){
      int m,n;
      scanf("%d %d",&m,&n);
      bool is_ok = true;
      for(int x=0;x*x<20000;x++){
	for(int y=0;x*x+y*y<20000;y++){
	  if(x*x+y*y <= 1) continue;
	  
	  for(int mi=0;mi<4;mi++){
	    if(is_divisor(P(x*mx[mi],y*my[mi]),P(m,n)) 
	       && !is_eight_divisor(P(x*mx[mi],y*my[mi]),m,n)){
	      is_ok = false;
	      goto found;
	    }
	  }
	}
      }
    found:;
      printf("%c\n",is_ok ? 'P' : 'C');
    }
  }
}

Measured memory_bytes: 1188
using System;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var nums = Console.ReadLine().Split(' ');
            int k = Convert.ToInt32(nums[0]), x = Convert.ToInt32(nums[1]);
            int start = x - (k - 1), end = x + (k - 1);
            int num = end - start + 1;
            Console.WriteLine(String.Join(" ", Enumerable.Range(start,num)).ToArray());
            
        }
    }
}

Measured memory_bytes: 13396
#include<bits/stdc++.h>
#define FOR0(i,n) for(i=0;i<n;i++)
#define FOR(i,j,n) for(i=j;i<n;i++)
#define FORD(i,j,k) for(i=j;i>=k;i--)
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define inf 1000000000
#define ninf -1000000000
#define endl '\n' 
#define she_told_me_dont_worry ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
// Use cout.flush() for interactive problems.
// Use this for increased stack size: g++ -o a.exe -Wl,--stack=256000000 -O2 source.cpp
inline long long  MAX2(long long  a, long long int b){return (a)>(b)?(a):(b);}
inline long long  MAX3(long long  a, long long  b,long long  c){return (a)>(b)?((a)>(c)?(a):(c)):((b)>(c)?(b):(c));}
inline long long  MIN2(long long  a, long long  b){return (a)<(b)?(a):(b);}
inline long long  MIN3(long long  a, long long b,long long c){return (a)<(b)?((a)<(c)?(a):(c)):((b)<(c)?(b):(c));}
using namespace std;
typedef long long ll;
typedef pair<int,int> ii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< ii > vii;
int main()
{
    she_told_me_dont_worry
    string s;
    ll n;
    cin>>s;
    n = s.size();
    ll i;
    ll bc = 0;
    ll ans = 0;
    FORD(i, n-1, 0)
    {
        if(s[i]=='A')
        {
            ans += bc;
        }
        else if(i>0 && s[i]=='C'&& s[i-1] =='B')
        {
            bc++;
            i--;
        }
        else
        {
            bc = 0;
        }
    }
    cout<<ans;
    cerr <<endl<< "Time elapsed : " << clock() * 1000.0 / CLOCKS_PER_SEC << " ms" << '\n';
}

Measured memory_bytes: 720
#include <stdio.h>
int main(void){
    int i,N;
    scanf("%d",&N);
    for(i=0;i<N;i++){
        int a,b,c;
        scanf("%d %d %d",&a,&b,&c);
        if((a*a==b*b+c*c) ||(b*b==c*c+a*a)||(c*c==b*b+a*a)){
            printf("YES\n");
        }
        else{
            printf("NO\n");
        }
    }
    return 0;
}



Measured memory_bytes: 2012
//A
#include <bits/stdc++.h>
using namespace std;
#define LL long long
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define LL_MIN -9223372036854775808
#define LL_MAX 9223372036854775807
int main(){
    int A,B;
    cin >> A >> B;
    cout << max({A+B,A-B,A*B}) << endl;
    
    return 0;
}

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

int main() {
  int A, B;
  cin >> A >> B;
  int plus = A + B;
  int minus = A - B;
  int multiplication = A * B;
  
  int ans;
  if (plus < minus) {
    if (minus < multiplication) {
	    ans = multiplication;
    } else {
      	ans = minus;
    }
  } else {
    if (plus < multiplication) {
      ans = multiplication;
    } else {
      ans = plus;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long a[200200];
long long tot,n,zon,ans=1e18;
int main(){
	cin>>n;
	for(int i=0;i<n;i++) cin>>a[i],tot+=a[i];
	for(int i=0;i<n-1;i++){
		zon+=a[i];
		tot-=a[i];
		ans=min(ans,abs(zon-tot));
	}
	cout<<ans<<"\n";
	return 0;
}

Measured memory_bytes: 1792
import java.util.*;
import java.io.*;

public class Main {


    public Main(FastScanner in, PrintWriter out) {
        int K = in.nextInt();
        boolean[] seen = new boolean[K];
        int cur = 0, res = -1;
        for (int i = 0; i < K && res < 0; i++) {
            cur = (cur * 10 + 7) % K;
            if (seen[cur])
                break;
            else if (cur == 0) 
                res = i + 1;
            seen[cur] = true;
        }
        out.println(res);
    }

    public static void main(String[] args) {
        PrintWriter out = new PrintWriter(System.out);
        // Scanner in = new Scanner(
                // new BufferedReader(new InputStreamReader(System.in)));
        FastScanner in = new FastScanner(System.in);

        Main sol = new Main(in, out);

        out.close();
    }
}


class FastScanner{
    private InputStream stream;
    private byte[] buf = new byte[1024];
    private int curChar;
    private int numChars;

    public FastScanner(InputStream stream)
    {
        this.stream = stream;
    }

    int read()
    {
        if (numChars == -1)
            throw new InputMismatchException();
        if (curChar >= numChars){
            curChar = 0;
            try{
                numChars = stream.read(buf);
            } catch (IOException e) {
                throw new InputMismatchException();
            }
            if (numChars <= 0)
                return -1;
        }
        return buf[curChar++];
    }

    boolean isSpaceChar(int c)
    {
        return c==' '||c=='\n'||c=='\r'||c=='\t'||c==-1;
    }

    boolean isEndline(int c)
    {
        return c=='\n'||c=='\r'||c==-1;
    }

    int nextInt()
    {
        return Integer.parseInt(next());
    }

    long nextLong()
    {
        return Long.parseLong(next());
    }

    double nextDouble()
    {
        return Double.parseDouble(next());
    }

    String next(){
        int c = read();
        while (isSpaceChar(c))
            c = read();
        StringBuilder res = new StringBuilder();
        do{
            res.appendCodePoint(c);
            c = read();
        }while(!isSpaceChar(c));
        return res.toString();
    }

    String nextLine(){
        int c = read();
        while (isEndline(c))
            c = read();
        StringBuilder res = new StringBuilder();
        do{
            res.appendCodePoint(c);
            c = read();
        }while(!isEndline(c));
        return res.toString();
    }
}


Measured memory_bytes: 33720
#include<stdio.h>

int n,A[1000],count;

void bubbleSort(){

	int temp;

	count = 0;

	for(int i = 0; i < n; i++){

		for(int j = n-1; j >= i+1; j--){
			if(A[j] < A[j-1]){
				temp = A[j];
				A[j] = A[j-1];
				A[j-1] = temp;

				count = count + 1;
			}
		}
	}

	printf("%d",A[0]);
	for(int i = 1; i < n; i++){
		printf(" %d",A[i]);
	}
}


int main(){

	scanf("%d",&n);

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

	bubbleSort();
              printf("\n");

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

	return 0;
}

Measured memory_bytes: 1040
#include <iostream>
#include <string>

using std::cin;
using std::cout;
using std::endl;
using std::string;

#include <stdio.h>

int main()
{
	unsigned int a, p, ans;

	// input
	cin >> a >> p;	// 林檎がA個、林檎の欠片がP個

	// calc
	p = 3 * a + p;	// 林檎1個は砕くと林檎3個
	ans = p / 2;	// 林檎の欠片2個を鍋で煮込むことで、アップルパイが1個作れます。

	// output
	cout << ans;
	cout << endl;

	return 0;
}


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

int main() {

    int n, m;
    cin >> n >> m;
    vector<int> a(m);
    for (int i = 0; i < m; i++) cin >> a[i];
    ll sum = 0;
    for (int i = 0; i < m; i++) sum += a[i];
    int rest = n - sum;
    if (rest < 0) {
        cout << -1 << endl;
    }
    else {
        cout << rest << endl;
    }

    return 0;

}


Measured memory_bytes: 3664
#include<cstdio>
#include<algorithm>
using namespace std;
int main(void)
{
	int n,l,i,j,a[100000];
	long long mx,sum;
	scanf("%d %d",&n,&l);
	for(i=0;i<n;i++)	scanf("%d",&a[i]);
	sum=l-a[0];	mx=l-a[0];
	for(i=1;i<n;i++)	{
		if(a[i]>a[i-1])	sum+=l-a[i];
		else {
			sum=l-a[i];
		}
		mx=max(mx,sum);
//		printf("sum1=%d\n",sum);
	}
	sum=l-a[n-1];
	for(i=n-2;i>=0;i--)	{
		if(a[i]>a[i+1])	sum+=l-a[i];
		else {
			sum=l-a[i];
		}
		mx=max(mx,sum);
//		printf("sum2=%d\n",sum);
	}
	printf("%lld\n",mx);
    return 0;
}


Measured memory_bytes: 3040
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dup(x,y) (((x)+(y)-1)/(y))
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const double EPS = 1e-10;
const int INF = 1e9;
const ll LINF = 1e15;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

typedef pair<ll, ll> pll;

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

	if (n == 1) {
		cout << 1 << endl;
		return 0;
	}
	
	map<pll, int> mp;
	rep(i,n) mp[make_pair(x[i], y[i])]++;
	int ans = INF;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			ll vx = x[i] - x[j];
			ll vy = y[i] - y[j];
			int t = 0;
			for (int k = 0; k < n; k++) {
				ll nx = x[k] + vx;
				ll ny = y[k] + vy;
				if (!mp[pll(nx, ny)]) t++;
			}
			ans = min(ans, t);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 6124
n,m = input().split()
n = int(n)
m = int(m)
x = input().split()
sa = []
for i in range(m):
    x[i] = int(x[i])
x = sorted(x)
for i in range(m-1):
    sa.append(x[i+1]-x[i])

sa = sorted(sa)


ans = 0
for j in range(m-n):
    ans += sa[j]
print(ans)


Measured memory_bytes: 11124
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int,int> PAIR;
const int N = 1e4+5;
const int M = 1e4;
const int INF = 0x3f3f3f3f;

struct node{
	int A,B,C,D;
} p[55];
int n,m,q,ans,a[15];

inline int cal(){
	int res = 0;
	for(int i = 1;i <= q;++i){
		if(a[p[i].B] - a[p[i].A] == p[i].C)
			res += p[i].D;
	}
	return res;
}

inline void dfs(int now,int st){
	if(now > n){
		ans = max(ans,cal());
		return ;
	}
	
	for(int i = st;i <= m;++i){
		a[now] = i;
		dfs(now+1,i);
	}
	return ;
}

int main() {
	scanf("%d%d%d",&n,&m,&q);
	for(int i = 1;i <= q;++i)
		scanf("%d%d%d%d",&p[i].A,&p[i].B,&p[i].C,&p[i].D);
	
	ans = 0;
	dfs(1,1);
	printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 3816
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=1e9;
const ll INF=5e18;
typedef pair<int,int> P;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  int h,w,n,sr,sc,a,b,c,d;
  cin >> h >> w >> n >> sr >> sc;
  string s,t;
  cin >> s >> t;
  a=sc,b=sc,c=sr,d=sr;
  for(int i=0; i<n; i++) {
    if(s[i]=='L') {
      b--;
    }
    if(s[i]=='R') {
      a++;
    }
    if(s[i]=='U') {
      c--;
    }
    if(s[i]=='D') {
      d++;
    }
    if(b<1||a>w||c<1||d>h) {
      cout << "NO" << endl;
      return 0;
    }
    if(t[i]=='L') {
      a=max(1,a-1);
    }
    if(t[i]=='R') {
      b=min(w,b+1);
    }
    if(t[i]=='U') {
      d=max(1,d-1);
    }
    if(t[i]=='D') {
      c=min(h,c+1);
    }
  }
  cout << "YES" << endl;
}

Measured memory_bytes: 920
#include "iostream"
#include "algorithm"
#include "string"
#include "vector"
#include "cmath"
#include "bitset"
#include "queue"
#include "functional"
#include "map"
#include "unordered_map"

#define lp(n) for (int i = 0; i < n; i++)
#define LP(n,i) for (int i = 0; i < n; i++)
#define mod 1000000007
#define sp ' '
#define intmax 2147483647
#define llmax 9223372036854775807
#define nya_n "(=^･ω･^=)"
typedef long long ll;
using namespace std;


int n, x, a[2000], mem[2000];
ll cnt, mn;

int main() {
	cin >> n >> x;
	mn = 0;
	lp(n) {
		cin >> a[i];
		mn += a[i];
	}
	lp(n) {
		cnt = ll(i + 1)*ll(x);
		LP(n, j) {
			mem[(j + 1) % n] = min(a[j], a[(j + 1) % n]);
			cnt += mem[(j + 1) % n];
		}
		LP(n, j) {
			a[j] = mem[j];
		}
		mn = min(mn, cnt);
	}
	cout << mn << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    static int w, h;
    
    public static void main(String... args){
        Scanner scan = new Scanner(System.in);
       o: while(true){
            w = scan.nextInt();
            h = scan.nextInt();
            if(w == 0 && h == 0)break;
            byte tate[][] = new byte[h][w-1];
            byte yoko[][] = new byte[h-1][w];

            for(int i = 0;i < h*2-1;i++){
                if(i % 2 == 0){
                    for(int j = 0;j < w-1;j++){
                        tate[i/2][j] = scan.nextByte();
                    }
                }else{
                    for(int j = 0;j < w;j++){
                        yoko[i/2][j] = scan.nextByte();
                    }
                }
            }

            boolean dp[][][] = new boolean[w][h][w*h+1];
            for(int i = 0;i < w*h;i++){
                for(int j = 0;j < w;j++){
                    for(int k = 0;k < h;k++){
                        dp[j][k][i] = false;
                    }
                }
            }
            dp[0][0][0] = true;
            boolean flag = true;
            for(int i = 0;i < w*h;i++){
                for(int j = 0;j < w;j++){
                    for(int k = 0;k < h;k++){
                        if(dp[j][k][i]){
                            if(j == w-1 && k == h-1){
                                System.out.println(i+1);
                                continue o;
                            }


                            if(k > 0 && yoko[k-1][j] != 1) {
                                dp[j][k-1][i+1] = true;
                                flag = false;
                                
                            }
                            if(k < h-1 && yoko[k][j] != 1) {
                                dp[j][k+1][i+1] = true;
                                flag = false;
                                
                            }
                            if(j > 0 && tate[k][j-1] != 1) {
                                dp[j-1][k][i+1] = true;
                                flag  = false;
                                
                            }
                            if(j < w-1 && tate[k][j] != 1) {
                                dp[j+1][k][i+1] = true;
                                flag = false;
                               
                            }
                            
                        }
                    }
                }
                if(flag)break;
                
                flag = true;
            }
            System.out.println(0);

        }
        
        scan.close();
    }

}


Measured memory_bytes: 74036
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    String T = sc.next();
    sc.close();

    boolean ans = T.startsWith(S) && T.length() == S.length() + 1;
    System.out.println(ans ? "Yes" : "No");
  }
}


Measured memory_bytes: 35632