akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#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 Repl(i, list) for(int i : list)
#define Sort(v) sort(v.begin(), v.end())
#define Rev(v) reverse(v.begin(), v.end())
#define ll long long
template<typename _T> void Out(_T x) { cout << x << endl; }
template<typename _T> void PrintVec(vector<_T> vec) { Rep(i, vec.size()) { cout << vec.at(i) << " "; } cout << endl; }

int main()
{
    // input
    int N;
    cin >> N;

    // algorithm
    int q = N / 500;
    int rem = (N - (q * 500)) / 5;
    // output
    cout << q * 1000 + rem * 5 << endl;
}

Measured memory_bytes: 256
#include <iostream>
//#include <iomanip>
//#include <algorithm>
//#include <numeric>
//#include <queue>
//#include <stack>
//#include <math.h>
#include <vector>
//#include <string>
typedef long long LL;
using namespace std;

static int MAX = 1000000;
static LL MOD = 1000000007;

LL mod_pow(LL x, LL n){
    LL ans = 1;
    while(n>0){
        if((n&1)==1){
            ans = ans * x % MOD;
        }
        x = x * x % MOD;
        n >>= 1;
    }
    return ans;
}

vector<LL> fac(MAX), finv(MAX);
void COMinit() {
    fac[0] = 1;
    finv[0] = 1;
    for (int i = 1; i < MAX; i++) {
        fac[i] = fac[i-1] * i % MOD;
        finv[i] = mod_pow(fac[i], (LL)MOD - 2) % MOD;
    }
}
 
LL COM(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n-k] % MOD) % MOD;
}

int main(){
    int x;
    int y;
    int n;
    int r;
    LL ans;
    cin >> x >> y;
    n = (x+y)/3;
    r = x-n;
    COMinit();
    if((x+y)%3!=0 || r<0){
      ans = 0;
    }else{
      ans = COM(n, r);
    }
    cout << ans << endl;
}

Measured memory_bytes: 15872
fun main() {
    // 5
    // 3 8 11 16 24
    val n = nextInt()
    val values = nextIntList().sorted()
    val MAX = values.last()
    val elats = Array(MAX + 1) { true }
    var res = 0
    values.forEachIndexed { index, i ->
        val result = elats[i]
        (i..MAX step i).forEach {
            elats[it] = false
        }
        if ((index > 0 && i == values[index - 1]) || (index < n - 1 && i == values[index + 1])) {
            return@forEachIndexed
        }
        if (result) {
            res++
        }
    }
    println(res)
}

// # Utils
// ## Input
fun next() = readLine()!!
fun nextInt() = next().toInt()
fun nextLong() = next().toLong()
fun nextDouble() = next().toDouble()
fun nextList() = next().split(" ")
fun nextIntList() = next().split(" ").map(String::toInt)
fun nextLongList() = next().split(" ").map(String::toLong)
fun nextDoubleList() = next().split(" ").map(String::toDouble)


Measured memory_bytes: 76344
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<double> VD;
typedef vector<VD> VVD;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n;
    cin >> n;
    vector<string> s(n);
    for (int i = 0; i < n; i++){
        cin >> s[i];
        sort(s[i].begin(), s[i].end());
    }
    map<string, int> str2count;
    for (string x : s) str2count[x]++;
    long long ans = 0;
    for (pair<string, int> p : str2count){
        long long c = p.second;
        ans += c * (c - 1) / 2;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 18176
#include <bits/stdc++.h>
#define ll long long

#define INF 999999999

using namespace std;

// input
int a,b,c,d;

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

    cin >> a >> b >> c >> d;

    int ans = (min(b,d) - max(a,c) > 0)?min(b,d) - max(a,c):0;

    cout << ans << "\n";
    
}

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

#define rep for(int i = 0;i<n;i++)
const int MOD = 1000000007;

int main(){
     int a,b;cin  >> a >> b;
     int c = max(a+b,a-b);
     c = max(c,a*b);
     cout << c << endl;
}


Measured memory_bytes: 256
import java.util.Scanner

import scala.io.StdIn._
object Main extends App {

  val s = scala.io.StdIn.readLine()
  val t = scala.io.StdIn.readLine()

  def solve(): Int = {
    s.zipWithIndex.foldLeft(0) { case (acc, (char, index)) =>
      if(char == t(index)) acc  else acc + 1
    }
  }

  println(solve())

}


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

int main() {
  int n,t,a;
  cin>>n>>t>>a;
  vector<long long>h(n);
  for(int i=0;i<n;i++){
    cin>>h.at(i);
  }
  for(int i=0;i<n;i++){
    h.at(i)=abs(a*1000-t*1000+h.at(i)*6);
  }
  vector<long long>ans(n);
  for(int i=0;i<n;i++){
    ans.at(i)=h.at(i);
  }
  sort(ans.begin(),ans.end());
  for(int i=0;i<n;i++){
    if(ans.at(0)==h.at(i)){
      cout<<i+1<< endl;
    return 0;
    }
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdlib>
using namespace std;
int main()
{
    int b;
    cin >> b;
    int n[b];
    for(int i = 0; i < b; i++)
    {
        cin >> n[i];
    }
    if(b % 2 == 0)
    {
        for(int i = b-1; i > 0; i-=2)
        {
            cout << n[i] << ' ';
        }
        for(int i = 0; i < b; i+=2)
        {
            cout << n[i] << ' ';
        }
    }
    else
    {
        for(int i = b-1; i >= 0; i-=2)
        {
            cout << n[i] << ' ';
        }
        for(int i = 1; i < b; i+=2)
        {
            cout << n[i] << ' ';
        }
    }
}


Measured memory_bytes: 2944
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;

namespace D
{
    public class Program
    {
        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);
            Solve();
            Console.Out.Flush();
        }

        public static void Solve()
        {
            var NW = Console.ReadLine().Trim().Split(' ').Select(int.Parse).ToArray();
            var (N, W) = (NW[0], NW[1]);
            var w = new long[N];
            var v = new long[N];
            for (var i = 0; i < N; i++)
            {
                var wv = Console.ReadLine().Trim().Split(' ').Select(long.Parse).ToArray();
                w[i] = wv[0];
                v[i] = wv[1];
            }

            var dict = new Dictionary<long, List<long>>();
            var min = w[0];
            for (var i = 0; i < N; i++)
            {
                min = Math.Min(min, w[i]);
                if (dict.ContainsKey(w[i])) dict[w[i]].Add(v[i]);
                else dict[w[i]] = new List<long> { v[i] };
            }

            var w0v = CumulativeItems(dict[min].OrderByDescending(x => x)).ToArray();
            var w1v = dict.ContainsKey(min + 1) ? CumulativeItems(dict[min + 1].OrderByDescending(x => x)).ToArray() : new long[] { 0 };
            var w2v = dict.ContainsKey(min + 2) ? CumulativeItems(dict[min + 2].OrderByDescending(x => x)).ToArray() : new long[] { 0 };
            var w3v = dict.ContainsKey(min + 3) ? CumulativeItems(dict[min + 3].OrderByDescending(x => x)).ToArray() : new long[] { 0 };

            var answer = 0L;
            for (var i = 0; i < w0v.Length; i++)
            {
                for (var j = 0; j < w1v.Length; j++)
                {
                    for (var k = 0; k < w2v.Length; k++)
                    {
                        for (var l = 0; l < w3v.Length; l++)
                        {
                            var weight = i * min + j * (min + 1) + k * (min + 2) + l * (min + 3);
                            if (weight > W) continue;
                            var sum = w0v[i] + w1v[j] + w2v[k] + w3v[l];
                            answer = Math.Max(answer, sum);
                        }
                    }
                }
            }

            Console.WriteLine(answer);
        }

        public static IEnumerable<long> CumulativeItems(IEnumerable<long> items)
        {
            var arr = items.ToArray();
            var ret = new long[arr.Length + 1];
            for (var i = 0; i < arr.Length; i++) ret[i + 1] = arr[i] + ret[i];
            return ret;
        }
    }
}


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

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

	int n;cin >> n;
	vector<string> s = vector<string>(n);
	for(int i = 0; i < n; i++){
		cin >> s[i];
	}

	int ans[] = {0,0,0,0};
	for(int i = 0; i < n; i++){
		if(s[i] == "AC"){
			ans[0]++;
		}else if(s[i] == "WA"){
			ans[1]++;

		}
		else if (s[i] == "TLE") {
			ans[2]++;

		}
		else if (s[i] == "RE") {
			ans[3]++;

		}
	}

	cout << "AC x " << ans[0] << endl;
	cout << "WA x " << ans[1] << endl;
	cout << "TLE x " << ans[2] << endl;
	cout << "RE x " << ans[3] << endl;

	return 0;
}


Measured memory_bytes: 6372
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cstring>
#include<queue>
using namespace std;
typedef long long LL;
const LL N=100005;
LL x,y,z,n;
LL ans=0;
struct qq
{
	LL a,b,c;
}s[N];
bool ok[N];//这个点用了没有 
bool cmp1 (qq x,qq y)	{return x.a-x.b>y.a-y.b;}
LL l[N],r[N];
priority_queue<LL> q;
int main()
{
	scanf("%lld%lld%lld",&x,&y,&z);n=x+y+z;
	for (LL u=1;u<=x+y+z;u++)	scanf("%lld%lld%lld",&s[u].a,&s[u].b,&s[u].c);
	sort(s+1,s+1+n,cmp1);
	/*printf("\n");
	for (LL u=1;u<=n;u++) printf("%lld %lld %lld\n",s[u].a,s[u].b,s[u].c);
	printf("\n");*/
	LL sum=0;
	for (LL u=1;u<=x;u++) 
	{
		sum=sum+s[u].a;
		q.push(s[u].c-s[u].a);
	}
	l[x]=sum;
	for (LL u=x+1;u<=x+z;u++)
	{
		//这个点选c   s[u].c;
		//这个点选a   top+s[u].a
		LL x=q.top();
		if (x+s[u].a<s[u].c)//用后面这种 
			sum=sum+s[u].c;
		else
		{
			sum=sum+x+s[u].a;
			q.pop();
			q.push(s[u].c-s[u].a);
		}
		l[u]=sum;
	}
//	for (LL u=x;u<=x+z;u++) printf("%lld\n",l[u]);
	while (!q.empty()) q.pop();
	sum=0;
	for (LL u=n;u>n-y;u--)
	{
		sum=sum+s[u].b;
		q.push(s[u].c-s[u].b);
	}
	r[n-y+1]=sum;
	for (LL u=n-y;u>x;u--)
	{
		LL x=q.top();
		if (x+s[u].b<s[u].c)
			sum=sum+s[u].c;
		else
		{
			sum=sum+x+s[u].b;
			q.pop();
			q.push(s[u].c-s[u].b);
		}
		r[u]=sum;
	}
	/*for (LL u=x+1;u<=n;u++) printf("%lld ",r[u]);
	printf("\n");*/
	for (LL u=x;u<=x+z;u++)	ans=max(ans,l[u]+r[u+1]);
	printf("%lld\n",ans);
	return 0;
}

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

int main() {
    int N,M,Q;
    cin>>N>>M>>Q;
    vector<tuple<int,int ,int,int>> t(Q);
    for (int i = 0; i < Q; i++){
        int a,b,c,d;
        cin>>a>>b>>c>>d;
        t[i]=make_tuple(a-1,b-1,c,d);
    }
    queue<vector<int>> q;
    vector<int> S(N,1),G(N,M),A(N);
    q.push(S);
    int ans=0;
    while(1){
        A=q.front();
        q.pop();
        int score=0;
        for (int i = 0; i < Q; i++){
            if(A[get<1>(t[i])]-A[get<0>(t[i])]==get<2>(t[i]))
            score+=get<3>(t[i]);
        }
        ans=max(score,ans);
        int digit=0;
        for (int i = N-1; i >=0; i--){
            if(A[i]==1){
                digit=i;
                break;
            }
        }
        int m;
        if(digit==N-1){
            m=M;
        }else m=A[digit+1];
        for (int i = 2; i <= m; i++){
            A[digit]=i;
            q.push(A);
        }
        if(A==G)break;
    }
    cout<<ans<<endl;
}

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

int main()
{
  char x;
  cin >> x;
  if(x == 'a' || x == 'e' || x == 'i' || x == 'o' || x == 'u'){
    cout << "vowel" << endl;
  }
  else
  {
    cout << "consonant" << endl;
  }
}


Measured memory_bytes: 256
import java.util.Scanner;	//Scannerクラス：Java標準入力を取得する

class Main {
	public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {	//Scanerクラスを変数scで使えるようにする
            int a = sc.nextInt();	//二つの変数a,b,cに整数を入力
            int b = sc.nextInt();
            int c = sc.nextInt();

            //かつ(&&),または(||)を用いたif文
            if(a < b && b < c) {			//bがaより大きくcがaより大きい場合
            	System.out.println(String.format("%d %d %d",a,b,c));
            }else if(a > b && b > c){ 						//上記以外の場合
            	System.out.println(String.format("%d %d %d",c,b,a));
            }else if(a < b && b > c){
            	if(a >c) {
            	System.out.println(String.format("%d %d %d",c,a,b));
            	}else {
            		System.out.println(String.format("%d %d %d",a,c,b));
            	}
            }else if(a > b && b < c){
            	if(a >c) {
                	System.out.println(String.format("%d %d %d",b,c,a));
                	}else {
                		System.out.println(String.format("%d %d %d",b,a,c));
                	}
            }else if(a == b || b == c || a == c) {
            	if(a == b) {
            		if(c > a) {
            			System.out.println(String.format("%d %d %d",a,b,c));
            		}else {
            			System.out.println(String.format("%d %d %d",c,a,b));
            		}
            	}else if(c == b) {
            		if(c > a) {
            			System.out.println(String.format("%d %d %d",a,b,c));
            		}else {
            			System.out.println(String.format("%d %d %d",b,c,a));
            		}
            	}else if(a == c) {
            		if(b > a) {
            			System.out.println(String.format("%d %d %d",a,c,b));
            		}else {
            			System.out.println(String.format("%d %d %d",b,c,a));
            		}
            	}
            }
        }
    }
}



Measured memory_bytes: 26440
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 100000000
#define rep(i,s,n) for (int i = (int)(s); i < (int)(n); i++)
#define mp make_pair
ll mod = 10e9+7;
ll mod2 = 998244353;

int main(){
    int n,m;cin>>n>>m;
    vector<int> a(n);
    rep(i,0,n) cin>>a[i];
    sort(a.begin(),a.end());
    vector<pair<int,int>> d(m);
    rep(i,0,m){
        int b,c;cin>>b>>c;
        d[i] = make_pair(c,b);
    }
    sort(d.begin(),d.end());
    int y = 0;
    for(int i=m-1;i>=0;i--){
        int r = d[i].first;
        int l = d[i].second;
        while(y<n&&l>0){
            if (r>a[y]){
                a[y] = r;
                l--;
            }
            y++;
        }
    }
    ll sum = 0;
    rep(i,0,n){
        sum+=a[i];
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 4552
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

int main(){
	int n;
	cin >> n;
	
	for(int i = 1; i < 10; i++){
		for(int j = 1; j < 10; j++){
			if(n==i*j){
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using PII = pair<int, int>;
#define FI(i, a, b) for (int i = (a); i <= (b); ++i)
#define FD(i, b, a) for (int i = (b); i >= (a); --i)
#define DEBUG(x) cerr << #x << ": " << (x) << endl;

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


Measured memory_bytes: 256
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7


n = INT()
l = MAP()

s = sum(l)
tmp=0
for i in range(n):
    tmp+=l[i]
    if tmp >= s/2:
        p1 = tmp - (s/2)
        idx1 = i
        break

tmp=0
for i in range(n-1,-1,-1):
    tmp+=l[i]
    if tmp >= s/2:
        p2 = tmp - (s/2)
        idx2 = i
        break

if p1 <= p2:
    left = sum(l[:idx1+1])
    right = sum(l[idx1+1:])
else:
    left = sum(l[:idx2])
    right = sum(l[idx2:])
print(abs(right-left))

Measured memory_bytes: 25788
let () = Scanf.scanf "%d %d\n" @@ fun n k ->
  let hs = Array.init (n + 1) @@ function
    | 0 -> 0
    | _ -> Scanf.scanf "%d " @@ fun h -> h in
  let dp = Array.init (n + 1) @@ fun _ ->
    Array.make_matrix (n + 1) (k + 1) 10000000000000 in
  dp.(0).(0).(0) <- 0;
  for i = 1 to n do
    for k' = 0 to k do
      for j = 0 to n do
        dp.(i).(i).(k') <-
          min dp.(i).(i).(k') @@
          max 0 (hs.(i) - hs.(j)) + dp.(i - 1).(j).(k')
      done
    done;
    for k' = 1 to k do
      for j = 0 to n do
        dp.(i).(j).(k') <-
          min dp.(i).(j).(k') @@
          dp.(i - 1).(j).(k' - 1)
      done
    done
  done;
  Printf.printf "%d\n" @@
  Array.fold_left (Array.fold_left min) max_int dp.(n)


Measured memory_bytes: 217972
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 1000000007
#define LINF 100000000000000007
#define MOD 1000000007
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
//typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};

int ans;
signed main(){

    int n,a[111],b[111],c[111];
    cin>>n;
    rep(i,n)cin>>a[i];
    rep(i,n)cin>>b[i];
    rep(i,n-1)cin>>c[i];
    rep(i,n){
        ans+=b[a[i]-1];
        if(i!=0 && a[i-1]+1==a[i])ans+=c[a[i-1]-1];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <deque>
using namespace std;
using P = pair<int,int>;
typedef long long int ll;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)

int main(){
    int a,b,k; cin >> a >> b >> k;
    vector<int>x;
    for(int i=1; i<=max(a,b); i++){
        if(a%i==0 && b%i==0){
            x.push_back(i);
        }
    }
    sort(x.rbegin(),x.rend());
    cout << x[k-1] << endl;
    return 0;
}




Measured memory_bytes: 256
n = int(input())
s = input()
ans = s.count('R') * s.count('G') * s.count('B')
for i in range(n-2):
    for j in range(i+1, n-1):
        k = j + (j - i)
        if k < n:
            if s[i] != s[j] and s[j] != s[k] and s[k] != s[i]:
                ans -= 1
print(ans)

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

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SP << " " <<

LL mod = 1000000007;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  LL N;
  cin >> N;
  vector<LL> A(N);
  vector<LL> B(N);
  REP(i,N){
    cin >> A[i];
    B[i] = A[i];
  }

  BACKSORT(A);
  REP(i,N){
    if(A[0]==A[1]){
      cout << A[0] << endl;
    }
    else
    {
      if(B[i]==A[0]){
        cout << A[1] << endl;
      }else{
        cout << A[0] << endl;
      }
    }
  }
}


Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 1; i < (int)(n+1); i++)
 

int main() {
  int n, count = 0;
  cin >> n;
  
  rep(i, n) {
    rep(j, n) {
      int ij = __gcd(i, j);
      rep(k, n) {
        count += __gcd(ij, k);
      }
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <tuple>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
//**デバッグ準備**//
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//gcdlcm, isPrime, eratos, Npow, divisor, modinv, bitSearch, bitList, dfs, bfs//
//dijkstra, WarshallFloyd, BellmanFord, UnionFind, COM, digitDP ,RMQ//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z;
ll MOD = 1000000007; ll INF = 1LL << 60; ll ans = 0; ll z = 0, o = 1;
vl flag, color, D; vll path;
ll Npow(ll x, ll n) {
	if (n == 0) return 1;
	if (n % 2 == 0) return Npow(x * x % MOD, n / 2);
	else return x * Npow(x, n - 1) % MOD;
}
vl P;
map<ll, ll> primeFactorize(ll n, map<ll, ll>& PF) {
	while (n % 2 == 0) {
		PF[2]++;
		n /= 2;
	}
	for (ll p = 3; p * p <= n; p += 2) {
		while (n % p == 0) {
			PF[p]++;
			n /= p;
		}
	}
	if (n != 1) {
		PF[n]++;
	}
	return PF;
}
ll modinv(ll a, ll m) {
	ll b = m, u = 1, v = 0;
	while (b) {
		ll 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 main() {
	cin >> N;
	vector<map<ll, ll>> PF(N);
	vl A(N);
	for (i = 0; i < N; i++) {
		cin >> A[i];
		primeFactorize(A[i], PF[i]);
	}
	map<ll, ll> Pm;
	for (i = 0; i < N; i++) for (auto itr : PF[i]) Pm[itr.first] = max(Pm[itr.first], itr.second);
	ll pre = 1;
	for (auto itr:Pm) {
		//debug(i, P[j], Pm[P[j]], PF[i][P[j]]);
		pre = (pre * Npow(itr.first, (itr.second))) % MOD;
	}
	for (i = 0; i < N; i++) {
		ans = (ans + pre * modinv(A[i], MOD)) % MOD;
	}
	cout << ans;
}

Measured memory_bytes: 3968
#include <cstring>
#include <map>
#include <unordered_map>
#include <string>
#include <list>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <cstdio>
#include <iostream>
#include <set>
#include <unordered_set>
using namespace std;

#define MAX(a,b) (a>b?a:b)
#define MIN(a,b) (a<b?a:b)
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int, int> pii;

int gi() {
    int a;
    scanf("%d", &a);
    return a;
}

ll gli() {
    ll a;
    scanf("%lld", &a);
    return a;
}

int d[400][400];
char g[20][24];
int m;

int gt(int x, int y) {
    return x*m + y;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n = gi();
    m = gi();
    memset(d, 1, sizeof(d));

    for (int i = 0; i < n; i++)
        scanf("%s", g[i]);

    for (int i = 0; i < n; i++)
        for (int j = 0; j < m; j++)
            if (g[i][j] == '.') {
                int x = gt(i, j);
                d[x][x] = 0;
                if (i && g[i-1][j] == '.') {
                    int y = gt(i-1, j);
                    d[x][y] = 1;
                    d[y][x] = 1;
                }
                if (j && g[i][j-1] == '.') {
                    int y = gt(i, j-1);
                    d[x][y] = 1;
                    d[y][x] = 1;
                }
            }

    int t = n*m;
    for (int k = 0; k < t; k++)
        for (int i = 0; i < t; i++)
            for (int j = 0; j < t; j++)
                if (d[i][j] > d[i][k] + d[k][j])
                    d[i][j] = d[i][k] + d[k][j];

    int r = -1;
    for (int i = 0; i < t; i++)
        for (int j = 0; j < t; j++)
            if (d[i][j] < 500 && d[i][j] > r)
                r = d[i][j];

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

    return 0;
}


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

int main(){
  long long n;
cin >> n;
  int count =0;
  vector<string> a(n);
for(long long i=0;i < n;++i)
  cin >> a[i];
  
  sort(a.begin(),a.end());
  for(long long i =0;i < n;++i) {
    if(a[i] == a[i+1])
      count++;
    }
  cout << n-count << endl;
}

Measured memory_bytes: 9504
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define clr(x) memset(x,0,sizeof(x))
#define all(x) x.begin(),x.end()
#define endl '\n'
#define pb push_back
const int N=1e5+1;
const int INF=1e9+7;
const int inf=1e18;

vector <int> adj[N];
bool vis[N];

void dfs(int node)
{
    vis[node]=1;

    for(auto it : adj[node])
    {
        if(!vis[it]){dfs(it);}
    }
}

int32_t main()
{
 ios_base::sync_with_stdio(0);
 cin.tie(0); cout.tie(0);
 int n,m; cin>>n>>m;
 for(int i=0;i<m;i++)
 {
     int a,b; cin>>a>>b;
     adj[a].pb(b); adj[b].pb(a);
 }
 int ans=-1;
 for(int i=1;i<=n;i++)
 {
     if(!vis[i]){dfs(i); ans++;}
 }
 cout<<ans<<endl;
}

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

int main(){
  char a, b;
  cin >> a >> b;
  vector<string> S(2);
  for(int i = 0; i < b - '0'; i++){
    S.at(0) += a;
  }
  for(int i = 0; i < a - '0'; i++){
    S.at(1) += b;
  }
  sort(S.begin(), S.end());
  cout << S.at(0) << endl;
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10000)
import re

# N = int(input())
# A = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]

# N = [int(x) for x in input().split()]

S = input()

K = "keyence"

s_idx = 0
k_idx = 0
skip = False

if S == K:
    print("YES")
    sys.exit(0)


while (S[s_idx] == K[k_idx]):
    s_idx += 1
    k_idx += 1

# s_idx -= 1
# k_idx -= 1

rs_idx = 1
rk_idx = 1
while (S[-rs_idx] == K[-rk_idx]):
    rs_idx += 1
    rk_idx += 1

    s1 = S[0:s_idx]
    s2 = S[-(rs_idx-1):]
    if s1+s2 == K:
        print("YES")
        sys.exit(0)


print("NO")

# print(S[0:s_idx])
# print(S[rs_idx:])


Measured memory_bytes: 3188
n = int(input())
a_list = []
b_list = []
for _ in range(n):
    a, b = map(int, input().split())
    a_list.append(a)
    b_list.append(b)

a_list.sort()
b_list.sort()

if n % 2 == 1:
    mid = (n+1)//2-1
    res = b_list[mid] - a_list[mid] + 1
else:
    mid_f = n//2-1
    mid_s = n//2
    max_sum = b_list[mid_s] + b_list[mid_f]
    min_sum = a_list[mid_s] + a_list[mid_f]
    res = max_sum - min_sum + 1

print(res)

Measured memory_bytes: 25584
#include<bits/stdc++.h>
using namespace std;
#define inf 1e9
#define ll long long 
#define M 1000000007
#define P pair<int,int>
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define rep(i,n) FOR(i,0,n)
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265

int n;
int a[110000];
ll sum;


int main(){
  cin>>n;

  FOR(i,1,n+1){
    cin>>a[i];
  }
  
  FOR(i,1,n+2){
    sum+=abs(a[i]-a[i-1]);
  }

  FOR(i,1,n+1){
    if(a[i-1]<a[i]&&a[i]<a[i+1])
      cout<<sum<<endl;
    else{
      cout<<sum-abs(a[i-1]-a[i])-abs(a[i]-a[i+1])+abs(a[i-1]-a[i+1])<<endl;
    }
  }

  return 0;
}



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

using namespace std;
typedef long long ll;

int main() {
    string S;
    cin >> S;
    ll ans;

    if (S == "SUN") {
        ans = 7;
    } else if (S == "MON") {
        ans = 6;
    } else if (S == "TUE") {
        ans = 5;
    } else if (S == "WED") {
        ans = 4;
    } else if (S == "THU") {
        ans = 3;
    } else if (S == "FRI") {
        ans = 2;
    } else if (S == "SAT") {
        ans = 1;
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<cstdio>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cmath>
#include<vector>

#include<stack>
#include<queue>
#include<time.h>
#include<set>
#include<map>
#include <iomanip>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a,b) for(int i=a;i>b;i--)
#define vint vector<int> 
#define vvint vector<vint>
#define ct(a) cout<<a<<endl
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll mod = 998244353;

string S;


ll ans, N, K;


queue<ll>que;




int main() {


	cin >> N >> K;
	if (K > 1)cout << N - K << endl;
	else cout << 0 << endl;



	return 0;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

const MOD: i64 = 1e+9 as i64 + 7;
fn calc(
    memo: &mut Vec<Vec<Vec<i64>>>,
    cs: &Vec<usize>,
    in_constraint: &Vec<Vec<usize>>,
    out_constraint: &Vec<Vec<usize>>,
) -> i64 {
    // assert!(cs[0] >= cs[1]);
    // assert!(cs[1] >= cs[2]);
    let n = memo.len() - 1;
    if cs[0] == n {
        return 1;
    }
    if memo[cs[0]][cs[1]][cs[2]] != -1 {
        return memo[cs[0]][cs[1]][cs[2]];
    }
    let index = cs[0];
    let mut ret = 0;
    'outer_loop: for t in 0..3 {
        let mut ncs = vec![index + 1];
        for i in 0..3 {
            if t == i {
                continue;
            }
            ncs.push(cs[i]);
        }
        if ncs[0] < ncs[1] {
            ncs.swap(0, 1);
        }
        if ncs[0] < ncs[2] {
            ncs.swap(0, 2);
        }
        if ncs[1] < ncs[2] {
            ncs.swap(1, 2);
        }
        for c in 0..3 {
            if c != 2 && ncs[c + 1] >= in_constraint[c][index + 1] {
                continue 'outer_loop;
            }
            if ncs[c] < out_constraint[c][index + 1] {
                continue 'outer_loop;
            }
        }
        ret = (ret + calc(memo, &ncs, in_constraint, out_constraint)) % MOD;
    }
    memo[cs[0]][cs[1]][cs[2]] = ret;
    ret
}

fn main() {
    let n = read::<usize>();
    let m = read::<usize>();
    let mut seq = vec![(0, 0, 0); m];
    for i in 0..m {
        seq[i].0 = read::<usize>();
        seq[i].1 = read::<usize>();
        seq[i].2 = read::<usize>();
    }
    seq.sort();
    let mut in_constraint = vec![vec![n + 2; n + 1]; 3];
    let mut out_constraint = vec![vec![0; n + 1]; 3];
    for i in 0..m {
        let (l, r, c) = seq[i];
        for j in l..r + 1 {
            in_constraint[c - 1][j] = std::cmp::min(in_constraint[c - 1][j], l);
        }
        out_constraint[c - 1][r] = std::cmp::max(out_constraint[c - 1][r], l);
    }
    let mut memo = vec![vec![vec![-1; n + 1]; n + 1]; n + 1];
    let ans = calc(&mut memo, &vec![0, 0, 0], &in_constraint, &out_constraint);
    println!("{}", ans);
}


Measured memory_bytes: 237948
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MOD 1000000007
#define PI 3.141592653589793

int main(){
    int x, y;
    cin >> x >> y;
    int g[] = {0,1,3,1,2,1,2,1,1,2,1,2,1};
    cout << (g[x] == g[y] ? "Yes":"No") << endl;
}


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

main(){
  int L,R,A,B,C,D;
  cin >>A>>B>>C>>D;
  L=A+B;
  R=C+D;
  if(L>R){
    cout<<"Left"<<endl;
  }
  else if(L==R){
    cout<<"Balanced"<<endl;
  }
  else{
    cout<<"Right"<<endl;
  }
}

Measured memory_bytes: 256
// -----------------------------------
// author   : MatsuTaku
// country  : Japan
// created  : 06/17/20 20:48:51
// -----------------------------------

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

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

  int g[13] = {0,1,3,1,2,1,2,1,1,2,1,2,1};
  int x,y; cin>>x>>y;
  if (g[x] == g[y]) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  
  return 0;
}


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

int Int_log2(int x){
  int y = log2(x);
  return y;
}

int main(){
  int n, m; cin >> n >> m;
  map<int, vector<int> > mp;
  int max_pow = 0;

  for(int i=0; i<n; i++){
    int a; cin >> a;
    int pow = Int_log2(a);
    mp[pow].push_back(a);
    if(max_pow < pow) max_pow = pow;
  }

  for(int i=max_pow; i>0; i--){
    sort(mp[i].begin(), mp[i].end());
    vector<int> v = mp[i];
    for(int j = v.size()-1; j>=0; j--){
      mp[i-1].push_back(v[j]/2);
      mp[i].pop_back();
      m--;
      if(m <= 0) break;
    }
    if(m <= 0) break;
  }

  long long int ans = 0;
  if(m > 0) {
    ans = max(n-m, 0);
  } else {
    for(auto itr = mp.begin(); itr != mp.end(); ++itr){
      vector<int> v = itr -> second;
      for(int j=0; j<v.size(); j++) ans += v[j];
    }
  }

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

Measured memory_bytes: 1784
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>

using namespace std;

#define int long long
#define endl '\n'
#define maxn 100010
const int MOD = 1000000007;
using int32 = __uint32_t;

void solve() {
    string a, b;
    cin >> a >> b;

    auto check = [](const string a,const string b)->bool{
        if(a.size() != b.size())return false;
        for(int i = 0; i < a.size(); i++){
            if(a[i] != b[i] and a[i] != '?')return false;
        }
        return true;
    };
    int sz = b.size();
    int id = -1;
    for(int i = 0; i < a.size(); i++){
        bool fl = true;
        if(!check(a.substr(i, b.size()),b))fl = false;
        if(fl)
            id = i;
    }
    if(id == -1 or a.size() < b.size())cout << "UNRESTORABLE";
    else{
        for(int i = 0; i < a.size();i++){
            if(i == id){
                cout<< b;
                i+= b.size() - 1;
                continue;
            }
            else if(a[i] == '?')cout << 'a';
            else cout << a[i];
        }
    }
}

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    int t = 1;
//    cin >> t;

    while (t--)
        solve();
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++){
		if(s[i]=='A'){
			for(int j=s.size()-1;j>=0;j--){
				if(s[j]=='Z'){
					cout<<j-i+1<<endl;
					return 0;
				}
			}
		}
	}
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;

int n;

int main(){
    cin>>n;
    int ans=0;
    rep(i,n+2){
        if(i*i-i==n*2){
            ans=i;
        }
    }
    if(!ans){
        cout<<"No\n";
        return 0;
    }
    cout<<"Yes\n"<<ans<<endl<<ans-1;
    for(int i=2;i<=ans;i++)cout<<" "<<i*(i-1)/2;
    for(int i=1;i<ans;i++){
        cout<<endl<<ans-1;
        for(int j=i*(i-1)/2+1;j<=i*(i+1)/2;j++)cout<<" "<<j;
        for(int j=i;j*(j+1)/2+i<=n;j++)cout<<" "<<j*(j+1)/2+i;
    }
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define REP(i,x) for(int i=0,i##_len=(x);i<i##_len;++i)
#define rep(i,a,b) for(int i=(a),i##_len(b);i<i##_len;++i)
#define All(x) begin(x),end(x)
#define rAll(x) rbegin(x),rend(x)
using namespace std;
using ll = long long;

int main(){
    string s,t;cin>>s>>t;
    cout<<t<<s<<endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
static const int MAX = 100;

int sum;

int minh(int h[], int left, int right){
    int min = 101, k;
    for(int i = left; i < right; i++){
        if(min > h[i]){
            min = h[i];
            k = i;
        }
    }
    return k;
}

void res(int h[], int left, int right){
    if(right - left <= 1) sum += h[left];
    else{
        int k = minh(h, left, right);
        int min = h[k];
        sum += min;
        //cout << k << endl;
        for(int i = left; i < right; i++){
            h[i] -= min;
            if(h[i] == 0){
                if(i == left){
                    left++;
                }else if( i + 1 == right){
                    right--;
                }else{
                    res(h, left, i);
                    left = i + 1;
                }
            }
        }
        //cout << left << right << endl;
        res(h, left, right);
    }
}

int main(){
    int N, i;
    sum = 0;
    cin >> N;
    int h[MAX];
    for(i = 0; i < N; i++){
        cin >> h[i];
    }
    res(h, 0, N);
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <queue>

using namespace std;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
    int H, W;   cin >> H >> W;
    vector<string> s(H);
    for (int i = 0; i < H; i++)
        cin >> s[i];

    vector<vector<int> > dist(H, vector<int>(W, -1));
    queue<pair<int, int> > que;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (s[i][j] == '#') {
                que.push(pair<int, int>(i, j));
                dist[i][j] = 0;
            }
        }
    }

    int ans = 0;
    while (!que.empty()) {
        pair<int, int> v = que.front();
        for (int i = 0; i < 4; i++) {
            int nx = v.first + dx[i];
            int ny = v.second + dy[i];

            if (nx < 0 || H <= nx || ny < 0 || W <= ny || s[nx][ny] == '#' || dist[nx][ny] != -1)
                continue;
            
            dist[nx][ny] = dist[v.first][v.second] + 1;
            ans = max(ans, dist[nx][ny]);
            que.push(pair<int, int>(nx, ny));
        }
        que.pop();
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 13568
#include <bits/stdc++.h>
using namespace std;
int main(){
    int K,N;
    cin>>K>>N;
    
    vector<int> A(N+1);A[0]=0;
    for(int i=1;i<=N;++i)cin>>A[i];
    
    vector<int> D(N+1);A[0]=0;
    for(int i=1;i<=N;++i)D[i]=A[i]-A[i-1];
    D[0]=(K-A[N])+A[1];
    
    int d=K-*max_element(D.begin(),D.end());
    cout<<d<<endl;
}

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

#define ff first
#define ss second
#define pb push_back

using namespace std;
using ll = long long;
using ii = pair<int, int>;

const int N = 100005;

int main() {
	char s[N];
	scanf("%s", s);
	int n = strlen(s);
	int ans  =0;
	for(int i = 0; i < n/2; i++){
		if(s[i] != s[n-1-i]){
			ans++;
		}
	}
	printf("%d\n", ans);

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n,tot;
int x;
bitset<4000001>bs;
int main(){
	scanf("%d",&n);
	bs[0]=1;
	for(int i=1;i<=n;i++){
		scanf("%d",&x);
		tot+=x;
		bs|=(bs<<x);
	}
	for(int i=(tot+1)/2;i<=4000000;i++)if(bs[i]){
		cout<<i<<"\n";
		return 0;
	}
}

Measured memory_bytes: 5132
#include <iostream>
#include <sstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iomanip>
#include <vector>
#include <cstdio>
#include <float.h>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <stack>
#include <functional>
 
using namespace std;
 
#define endl '\n'
#define MOD 1000000007
#define INF 1ll<<30
#define MAX 100010
#define eps 1e-11
#define bit_max 1ll<<32
#define _USE_MATH_DEFINES
 
 
 
 
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
   // freopen("./input.txt","r",stdin);
   /// freopen("./output.txt","w",stdout);
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    int ctr =0;
    for(int i=1;i<n-1;i++)
    {
        if(a[i]>a[i-1]&&a[i]<a[i+1])
            ctr++;
        if(a[i]<a[i-1]&&a[i]>a[i+1])
            ctr++;
    }
    cout<<ctr;
}

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

typedef vector<pair<int,int> > Points;

int n;
Points ps;

int cal_rect(int dx,int dy){
	int x = abs(dx);
	int y = abs(dy);
	return (x+y)*(x+y) - 2*x*y;
}

int main(){
	while(scanf("%d",&n),n != 0){
		ps = Points();
		for(int i= 0; i < n; i++){
			int x,y;
			scanf("%d%d",&x,&y);
			ps.push_back(make_pair(x,y));
		}
		sort(ps.begin(),ps.end());

		int ans = 0;
		//2点選んで右回りと左回りに見ていき、正方形になってるかチェック＋ans更新
		for(int i = 0; i < n; i++){
			for(int j = i+1; j < n; j++){
				int dx,dy;
				dx = ps[i].first - ps[j].first;
				dy = ps[i].second - ps[j].second;
			
				//左回り
				int lx,ly,lx2,ly2;
				lx = ps[i].first - dy;
				ly = ps[i].second + dx;
				lx2 = lx - dx;
				ly2 = ly - dy;
				bool lok = binary_search(ps.begin(),ps.end(),make_pair(lx,ly));
				bool lok2 = binary_search(ps.begin(),ps.end(),make_pair(lx2,ly2));

				//右回り
				int rx,ry,rx2,ry2;
				rx = ps[i].first + dy;
				ry = ps[i].second - dx;
				rx2 = rx - dx;
				ry2 = ry - dy;
				bool rok = binary_search(ps.begin(),ps.end(),make_pair(rx,ry));
				bool rok2 = binary_search(ps.begin(),ps.end(),make_pair(rx2,ry2));
				
				int rect = cal_rect(dx,dy);
				if((lok && lok2) || (rok && rok2)){
					if(ans < rect){
						ans = rect;
					}
				}
			}
		}
		printf("%d\n",ans);
	}
	
	return 0;
}



Measured memory_bytes: 3264
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll a,b,c,k;
	cin>>a>>b>>c>>k;
	cout << (k%2==0?a-b:b-a);
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<cstring>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define int           long long
#define umapii        unordered_map<int,int>
#define ps(x,y)       fixed<<setprecision(y)<<x // sets precision upto required digits
#define arr(a,n)      int n;cin>>n;int a[n];for(int i=0;i<n;i++){cin>>a[i];}
#define outarr(a,n)   for(int i=0;i<n;i++){cout<<a[i]<<" ";}
#define mod           1000000007
#define ff            first
#define big           1e15
#define ss            second
#define add           push_back
#define remove        pop_back
#define mapii         map<int,int>
#define large         *max_element
#define small         *min_element
#define float         double
#define pqi           priority_queue<int>
#define mpqi          priority_queue<int,vector<int>,greater<int>>
#define in(n)         int n;cin>>n;
#define w(t)          int t;cin>>t;while(t--)
#define vi            vector<int>
#define vivi          vector<vector<int>>
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>pbds;




int32_t main() {
#ifndef ONLINE_JUDGE
    freopen("input1.txt", "r", stdin);
    freopen("output3.txt", "w", stdout);
#endif

    int n, m;
    cin >> n >> m;
    int h[n + 1];
    for (int i = 1; i <= n; i++) {
        cin >> h[i];
    }
    int x, y;
    int a[n + 1] = {0};
    for (int i = 0; i < m; i++) {
        cin >> x >> y;
        if (h[x] < h[y]) {
            a[x] = 1;
            if (a[y] != 1) {
                a[y] = 0;
            }
        } else if (h[x] > h[y]) {
            a[y] = 1;
            if (a[x] != 1) {
                a[x] = 0;
            }
        } else {
            a[x] = 1;
            a[y] = 1;
        }
    }
    int count = 0;
    for (int i = 1; i <= n; i++) {
        if (a[i] == 0) {
            count++;
        }
    }
    cout << count << endl;


}

Measured memory_bytes: 5176
#include <iostream>
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (int i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
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;
}
struct io
{
    io()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
};
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-19;




signed main() {
    string s;
    cin >> s;
    ll r = 1;
    if (s == "RRR") r = 3;
    if (s == "RRS" || s == "SRR") r = 2;
    if (s == "SSS") r = 0;
    
    mes(r);
    
    
}

Measured memory_bytes: 3588
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
 
using namespace std;
 
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
 
long gcd(long a, long b){
	if (a%b==0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}
}
 
long lcm(long a, long b){
	return (a*b) / gcd(a,b);
}
 
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a < b) { a = b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a > b) { a = b; return 1; } return 0; }
 
typedef long long ll;

const ll INF = 1ll<<60;
const ll MOD = 1000000007;
const double EPS = 1e-10;

ll num[102345];

int main(){
	ll n, k;
	
	cin >> n >> k;
	
	REP(i,n){
		ll a, b;
		
		cin >> a >> b;
		
		num[a] += b;
	}
	
	ll sum = 0;
	
	ll i = 0;
	
	while (k > sum){
		i++;
		sum += num[i];
	}
	
	cout << i << endl;
	
	return 0;
}

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

int main() {
  int H, W;
  cin >> H >> W;
  vector<string> vec(H);

  for(int i=0; i<H; i++){
    cin >> vec.at(i);
  }
  //出力
  for(int i=0; i<W+2; i++){
    cout << "#";
  }
  cout << endl;
  for(int i=0; i<H; i++){
    cout << "#" << vec.at(i) << "#" << endl;
  }
    for(int i=0; i<W+2; i++){
    cout << "#";
  }
  cout << endl;
}

Measured memory_bytes: 256
from math import floor

def solve(X, D, lb, ub):
    # min abs(X + t * D) (lb <= t <= ub) (lb, ub, t are int)
    ts = [
        lb,
        ub,
        max(min(floor(-X / D), ub), lb),
        max(min(floor(-X / D) + 1, ub), lb),
    ]
    return min([abs(X + t * D) for t in ts])

X, K, D = map(int, input().split())

if K % 2 == 0:
    ans = solve(X, D * 2, -(K // 2), +(K // 2))
else:
    ans1 = solve(X + D, D * 2, -((K + 1) // 2), +((K - 1)) // 2)
    ans2 = solve(X - D, D * 2, -((K - 1) // 2), +((K + 1)) // 2)
    ans = min(ans1, ans2)
print(ans)



Measured memory_bytes: 9080
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
string s, ans;

int main()
{
    cin >> s;
    int a;
    ans = "YES";
    while (s.length() > 0)
    {

        string t = s.substr(0, 5);

        if (t == "dream" || t == "erase")
        {
            s.erase(0, 5);
        }
        else
        {
            ans = "NO";
            break;
        }
        if (t == "erase" && s[0] == 'r')
        {
            s.erase(0, 1);
        }
        if (s.substr(0, 5) == "erase")
        {
            continue;
        }
        else if (t == "dream" && s[0] == 'e' && s[1] == 'r')
        {
            s.erase(0, 2);
        }
    }

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


Measured memory_bytes: 3668