akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
using namespace std;

class edge;

class vertex{
    public:
        vector<edge*> edges;
        int color;
        vertex(int _color){
            color = _color;
        }
};

class edge{
    public:
        vertex *to;
        edge(vertex *_to){
            to = _to;
        }
};

class list_node{
    public:
        list_node *prev,*next;
        vertex *data;
        list_node(list_node *_prev,list_node *_next,vertex *_data){
            prev = _prev;
            next = _next;
            data = _data;
        }
};

class list{
    public:
        list_node *back,*front;
        list(){
            back = new list_node(0,0,0);
            front = new list_node(0,back,0);
            back->prev = front;
        }
        list_node *get_first(){
            return front->next;
        }
        list_node *get_last(){
            return back->prev;
        }
        void push_back(vertex *data){
            list_node *node = back->prev;
            node->next = new list_node(node,back,data);
            back->prev = node->next;
        }
        bool isEmpty(){
            if(front->next == back) return true;
            return false;
        }
};

int bfs(list l){
    int count = 0;
    list *L = new list[10000];
    L[0] = l;
    while(true){
        for(list_node *j = L[count].get_first(); j != L[count].back; j = j->next){
            vertex *v = j->data;
            for(int k = 0; k < v->edges.size(); k++){
                vertex *to = v->edges[k]->to;
                if(to->color) continue;
                to->color = 1;
                L[count+1].push_back(to);
            }
        }
        if(L[count+1].isEmpty()) break;
        count++;
    }
    return count;
}

int main(){
    int H,W,color;
    string str;
    cin >> H >> W;
    list l;
    vertex *A[H+2][W+2];
    for(int i = 0; i <= H+1; i++){
        if(i != 0 && i != H+1) cin >> str;
        for(int j = 0; j <= W+1; j++){
            if(i  == 0 || j == 0 || i == H+1|| j == W+1){
                A[i][j] = new vertex(1);
            }else{
                if(str[j-1] == '.') color = 0;
                else color = 1;
                A[i][j] = new vertex(color);
            }
        }
    }

    for(int i = 1; i <= H; i++){
        for(int j = 1; j <= W; j++){
            if(A[i][j]->color) l.push_back(A[i][j]);
            A[i][j]->edges.push_back(new edge(A[i-1][j]));
            A[i][j]->edges.push_back(new edge(A[i][j+1]));
            A[i][j]->edges.push_back(new edge(A[i+1][j]));
            A[i][j]->edges.push_back(new edge(A[i][j-1]));
        }
    }

    cout << bfs(l) << endl;
    
}

Measured memory_bytes: 262432
#include <cstdio>
#include <string>
#include <iostream>
#include <algorithm>

using namespace std;
#define REP(i, y) for(int i=0;i<y;i++)
#define FOR(i,x,y) for(int i=x;i<y;i++)
#define FORI(i,x,y) for(int i=x-1;i>=y;i--)
int main() {
  string s;
  cin >> s;
  int m=0;
  int ssize = (int)s.size();
  REP(i,ssize) {
    if (s[i]=='A') {
      for (int l = ssize - i; l >= 0; l--) {
        string sub = s.substr(i, l);
        if (sub[sub.size() - 1] == 'Z') {
          printf("%d\n", (int)sub.size());
          return 0;
        }
      }
    }
  }
  printf("%d\n",m);
}

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

bool check(long long n, long long s, long long i) {
    while (n > 0) {
        s -= n % i;
        n /= i;
    }
    return s == 0;
}

int main() {
    long long n, s;
    long long ans = 1000000000000;
    scanf("%lld %lld", &n, &s);
    if (s == n) ans = n + 1;
    for (long long i = 2; i * i <= n; i++) {
        if (check(n, s, i)) ans = min(ans, i);
    }
    for (long long i = 1; i * i <= (n - s); i++) {
        if ((n - s) % i == 0) {
            long long b = (n - s) / i + 1;
            if (check(n, s, b)) ans = min(ans, b);
        }
    }
    if (ans == 1000000000000) printf("-1\n");
    else printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 256
n = int(input())
dic = {'M': 0, 'A': 0, 'R': 0, 'C': 0, 'H': 0}
for i in range(n):
    s = input()[0]
    if s in dic.keys():
        dic[s] = dic[s] + 1
ans = 0
for i in dic.keys():
    for j in dic.keys():
        if i == j:
            break
        for k in dic.keys():
            if j == k or k == i:
                break
            ans += dic[i] * dic[j] * dic[k]
print(ans)


Measured memory_bytes: 3060
import math
a,b,h,m=list(map(int,input().split()))
h+=m/60
ad=h*math.pi/6
bd=h*2*math.pi

ax=math.cos(ad)*a
ay=math.sin(ad)*a
bx=math.cos(bd)*b
by=math.sin(bd)*b

print(math.sqrt((ax-bx)**2+(ay-by)**2))


Measured memory_bytes: 9504
#include <stdio.h>

int main (void){
  int H,W,h,w;

  while(1){
    scanf("%d %d",&H,&W);
    if(H == 0 && W == 0){
      break;
    }

    for(h=0; h<H; h++){
      for(w=0; w<W; w++){
        if(((w+1)%2 == 1 && (h+1)%2 == 0 ) || ((w+1)%2 == 0 && (h+1)%2 == 1)){
        printf(".");
      }else{
        printf("#");
      }
    }
      printf("\n");
    }
    printf("\n");
  }
  return 0;
}


Measured memory_bytes: 2040
#include<stdio.h>

#define N 20
#define Q 200

int A[N],m[Q];
int n,q,i;
int flag;

void solve(int i,int x){
   
  if(i == n){
    if(x == 0) 
      flag = 1;
  }
  else{
    solve(i+1, x-A[i]);
    solve(i+1,x);
  }
}

int main(){
  scanf("%d",&n);
  for(i=0; i<n; i++) scanf("%d",&A[i]);
  scanf("%d",&q);
  for(i=0; i<q; i++) scanf("%d",&m[i]);
  for(i=0; i<q; i++){
    flag = 0;
    solve(0, m[i]);
    if(flag==1) printf("yes\n");
    else printf("no\n");
  }
  return 0;
}

Measured memory_bytes: 580
#include <iostream>
#include <algorithm>

using namespace std;

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

    int n, x, y;
    cin >> n >> x >> y;
    x--, y--;

    int ans[n];
    fill(ans, ans+n, 0);
    for (int i = 0; i < n; i++) {
        if (i < x) {
            int t = (x + y + 1) / 2;
            ans[1]++;
            ans[t-i+1]--;
            ans[x-i+1]++;
            ans[x-i+1+y-t]--;
            ans[x-i+2]++;
            ans[x-i+1+n-y]--;
        } else if (i <= y) {
            int t = min(y, i + (y - x + 1) / 2);
            ans[1]++;
            ans[t-i+1]--;
            ans[i-x+1]++;
            ans[i-x+1+y-t]--;
            t = min(i - x + 1, y - i);
            ans[t+1]++;
            ans[t+n-y]--;
        } else {
            ans[1]++;
            ans[n-i]--;
        }
    }

    for (int i = 1; i < n; i++) {
        ans[i] += ans[i-1];
        cout << ans[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int gcd(int a,int b)
{
  if(b==0)
    return a;
  return gcd(b,a%b);
}
int main()
{
  int n;
  cin>>n;
  int sum=0;
  for(int i=1;i<=n;i++)
  {
    for(int j=1;j<=n;j++)
    {
      for(int k=1;k<=n;k++)
      {
        int x=gcd(i,j);
        int y=gcd(x,k);
        sum+=y;
      }
    }
  }
  cout<<sum;
  return 0;
}

Measured memory_bytes: 3648
A, B, C, D = map(int, input().split())

is_turn_of_takahashi = True

while A > 0 and C > 0:
    if is_turn_of_takahashi:
        C -= B
    else:
        A -= D

    is_turn_of_takahashi = not is_turn_of_takahashi

print("Yes" if A > 0 else "No")


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

using namespace std;

#define ll long long

const int mxN = 22;
const int mo = 1e9 + 7;

int n;
int m[mxN][mxN];

void addself(int& x, int y) {
    x += y;
    while (x < 0)
        x += mo;
    x = x % mo;
}

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

    cin >> n;

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

    vector<int> dp(1 << n);
    dp[0] = 1;
    for (int mask = 0; mask < 1 << n; mask++) {
        int a = __builtin_popcount(mask);
        for (int b = 0; b < n; b++) {
            if (m[a][b] && !(mask & (1 << b))) {
                int m2 = mask ^ (1 << b);
                addself(dp[m2], dp[mask]);
            }
        }
    }

    //for (int i = 0; i < 1 << n; i++) { cout << dp[i] << ' '; }

    cout << dp[(1 << n) - 1] << endl;
}


Measured memory_bytes: 8576
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
int k;
string s;
int main(){
	cin >> k >> s;
	if(s.size() > k) s = s.substr(0,k) + "...";
	cout << s << "\n";
}

Measured memory_bytes: 3628
import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)
  val str = sc.next
  val a = str.substring(0, 1).toInt
  val b = str.substring(1, 2).toInt
  val c = str.substring(2, 3).toInt
  val d = str.substring(3, 4).toInt
  val abcd = Seq(a, b, c, d)
  val digits = abcd.length - 1

  import scala.util.control.Breaks.{breakable,break}
  breakable {
    for (i <- 0 until 1 << digits) {
      val sb = new StringBuilder
      sb.append(abcd(0))
      var result = abcd(0)
      for (j <- 0 until digits; n = abcd(j + 1)) {
        if ((i >> j & 1) == 1) {
          sb.append('+')
          result += n
        } else {
          sb.append('-')
          result -= n
        }
        sb.append(n)
      }
      if (result == 7) {
        sb.append("=7")
        println(sb.toString)
        break
      }
    }
  }
}

Measured memory_bytes: 25792
#include <iostream>

using namespace std;

int main() {

	int n, k[10001];
	int i, j, l;
	int cnt = 0;

	while (true) {
	
		cin >> n;

		if (n == 0) return 0;

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

			cin >> k[i];

			if (k[i] == 0) cnt++;

		}

		if (n == 1) {

			i = -9999;
			if (k[0] <= 1) {
				cout << "NA" << endl;
			}
		}



		else {

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

				if (k[i] >= 2) { break; }

			}

		}

		if (i >= (n - 1)) { cout << "NA" << endl;}
		else cout << n - cnt + 1 << endl;

		cnt = 0;

	}
	return 0;
}


Measured memory_bytes: 3144
n = int(input())
A = list(map(int, input().split()))
sunuke = sum(A)
arai = 0

f_inf = float("inf")
res = f_inf
for i in range(n - 1):
    arai += A[i]
    sunuke -= A[i]
    res = min(res, abs(sunuke - arai))
print(res)


Measured memory_bytes: 24832
N,M = list(map(int, input().split()))
a = [0]*N
b = [0]*N
c = [0]*M
d = [0]*M
for k in range(N):
     a[k],b[k] = list(map(int, input().split()))
for l in range(M):
     c[l],d[l] = list(map(int, input().split()))

for i in range(N):
    s=10**9
    for j in range(M):
        if  s>abs(a[i]-c[j])+abs(b[i]-d[j]):
             s=abs(a[i]-c[j])+abs(b[i]-d[j])
             e=j+1
    print(e)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

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


	int N;
	cin >> N;
	int X, Y, Z;
	cin >> X >> Y >> Z;
	int M = X + Y + Z;

	const ll mod = 1e9 + 7;
	map<ll, ll> dp[2];
	dp[0][0] = 1;

	ll kotae = 0;
	rep(i, N) {
		int a = i & 1;
		int b = a ^ 1;

		kotae = kotae * 10 % mod;
		for (auto x : dp[a]) {
			ll k = x.second % mod;
			ll DP = x.first;

			dp[b][0] += 3 * k;

			rep1(j, 7) {
				int p = 0;
				int x = j;
				ll tmp = DP;

				while (tmp && x < Z) {
					x += tmp % 11;
					tmp /= 11;
				}
				if (x == Z) {
					while (tmp && x < Y + Z) {
						x += tmp % 11;
						tmp /= 11;
					}
					if (x == Y + Z) {
						while (tmp && x < X + Y + Z) {
							x += tmp % 11;
							tmp /= 11;
						}
						if (x == X + Y + Z) {
							kotae += k;
							continue;
						}
					}
				}
				tmp = DP;
				ll tugi = j;
				ll kari = 11;
				x = j;
				while (tmp && x + tmp % 11 < M) {
					int tmp2 = tmp % 11;
					tmp /= 11;
					x += tmp2;
					tugi += kari * tmp2;
					kari *= 11;
				}
				dp[b][tugi] += k;
			}
		}
		dp[a].clear();
	}
	co(kotae% mod);




	Would you please return 0;
}

Measured memory_bytes: 8192
using System;

namespace _055b
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            long s = Factorial(N);
            Console.WriteLine(s);
        }

        public static long Factorial(int n){
            if(n==0){
                return 1L;
            }else{
                return n * Factorial(n-1)%(1000000000+7);
            }
        }
    }
}

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

int main() {
  int N; cin >> N;
  vector<int64_t> L(N+1);
  rep(i, N+1) {
    if (i == 0) {
      L[i] = 2;
    }
    else if (i == 1) {
      L[i] = 1;
    }
    else {
      L[i] = L[i-1] + L[i-2];
    }
  }
  cout << L[N] << endl;
}

Measured memory_bytes: 256
a=int(input())

h=list(map(int,input().split()))

sum=0

for i in range(1,len(h)):
  if h[i]-h[i-1]<0:
    sum=sum+abs(h[i]-h[i-1])
    h[i]=h[i]-(h[i]-h[i-1])

print(sum)

Measured memory_bytes: 32368
n = int(input())
h = list(map(int, input().split()))

dp = [0] * n
dp[0] = 0
dp[1] = abs(h[1]-h[0])
for i in range (2,n):
     dp[i] = min(dp[i-1]+abs(h[i-1]-h[i]),dp[i-2]+abs(h[i-2]-h[i]))

print(dp[n-1])


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

using namespace std;

#define endl "\n"
#define F first
#define S second
#define B begin()
#define E end()
#define PB push_back
#define int long long

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

const int maxn = 1e5;
const int OO = 1e18;
const int mod = 1e7 + 9;

int32_t main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

//	freopen("name.in","r",stdin);
//	freopen("name.out","w",stdout);

    string s;
    cin >> s;
    string a="ABC",b="ARC";
    if(s==a)
    {
        cout << b;
    }
    else
        cout << a;

	return 0;
}


Measured memory_bytes: 3608
object Main extends App{
import scala.collection.mutable
import scala.io.StdIn._

val map = mutable.Map.empty[String, Int]
val n = readInt()

Iterator.continually(readLine)
    .take(n)
    .foreach(s => {
      if (map.contains(s)) map.put(s, map(s)+1) else map += s->1
    })

val m = readInt()
Iterator.continually(readLine)
    .take(m)
    .foreach(s => {
      if (map.contains(s)) map.put(s, map(s)-1)
    })

println(List(0,map.values.max).max)
}

Measured memory_bytes: 25420
#include <iostream>
#include <string>
#include <vector>
using namespace std;

struct Command {
  char t, d;
};
int main() {
  int n, q;
  cin >> n >> q;
  string s;
  cin >> s;
  vector<Command> commands;
  for (int i = 0; i < q; ++i) {
    char t, d;
    cin >> t >> d;
    commands.push_back((Command){t, d});
  }
  auto f = [&](int c) { 
    int cur = c;
    for (int i = 0; i < q; ++i) {
      if (commands[i].t != s[cur]) continue;
      if (commands[i].d == 'L') --cur;
      else ++cur;
      if (cur >= n || cur < 0) return cur;
    }
    return cur;
  };
  int l = -1, r = n;
  while (r-l>1) {
    int c = (l+r)/2;
    int nc = f(c);
    if (nc >= 0) r = c; else l = c;
  }
  // cerr << l << " " << r << endl;
  int min = l;
  l = -1, r = n;
  while (r-l>1) {
    int c = (l+r)/2;
    int nc = f(c);
    if (nc < n) l = c; else r = c;
  }
  int max = l;
  cout << max-min << endl;
}



Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,f,i,rem;
    cin>>n;
    f=0;
    for(i=1;i<=9;i++)
    {
        if(n%i==0 && (n/i)<=9)
        {
            f=1;
            break;
        }
    }
    if(f==1)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}


Measured memory_bytes: 3652
//
// Created by Harshit on 20-08-2020.
//
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n,W,max_value=0,res=0;
    cin>>n>>W;
    vector <int> weight(n);
    vector <int> value(n);
    for(int i=0;i<n;i++){
        cin>>weight[i]>>value[i];
        max_value+=value[i];
    }
    vector <vector <int> > dp(n+1,vector <int> (max_value+1,INT_MAX));
   dp[0][0]=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<=max_value;j++){
            dp[i+1][j]=min(dp[i][j],dp[i+1][j]);
            if(j+value[i]<=max_value)
                dp[i+1][j+value[i]]=min((long long)dp[i+1][j+value[i]],(long long)weight[i]+(long long)dp[i][j]);
        }
    }
    for(int i=0;i<=max_value;i++){
        if(dp[n][i]<=W)
            res=max(res,i);
    }
    cout<<res<<endl;

}


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

int main(void){
    int x,y,z,k;
    cin >> x >> y >> z >> k;

    vector<ll> a(x),b(y),c(z);
    for(int i=0;i<x;i++) cin >> a[i];
    for(int i=0;i<y;i++) cin >> b[i];
    for(int i=0;i<z;i++) cin >> c[i];

    vector<ll> ab;
    for(int i=0;i<x;i++){
        for(int j=0;j<y;j++){
            ab.push_back(a[i]+b[j]);
        }
    }
    sort(ab.begin(),ab.end());
    reverse(ab.begin(),ab.end());

    vector<ll> abc;
    sort(c.begin(),c.end());
    for(int i=0;i<min(x*y,k);i++){
        for(int j=0;j<z;j++){
            abc.push_back(ab[i]+c[j]);
        }
    }
    sort(abc.begin(),abc.end());
    reverse(abc.begin(),abc.end());

    for(int i=0;i<k;i++) cout << abc[i] << endl;
}

Measured memory_bytes: 43368
// Shik and Copying String
// * frank_c1
// * 2017 / 12 / 18
 
#include <bits/stdc++.h>
using namespace std;

const int maxn = (int)(1e6) + 5;
char s[maxn], t[maxn];
int q[maxn], l = 1, r;

int main() {
	int n;
	scanf("%d%s%s", &n, s + 1, t + 1);
	if (!strcmp(s + 1, t + 1)) return printf("0\n"), 0;
	int ps = n, ret = 0;
	for (int i = n; i >= 1; --i) if (t[i] != t[i - 1]) {
		while (ps && (ps > i || s[ps] != t[i])) --ps;
		if (!ps) return printf("-1\n"), 0;
		for (; l <= r && q[l] >= r - l + 1 + i; ++l);
		if (ps < i) q[++r] = ps; ret = max(ret, r - l + 1);
	}
	return printf("%d\n", ret + 1), 0;
}

Measured memory_bytes: 6144
#include <bits/stdc++.h>
using namespace std;
using ll=long long int;
using ld=long double;
using VI=vector<ll>;
using VD=vector<ld>;
using VVI=vector<VI>;
using VC=vector<char>;
using VVC=vector<VC>;
using VS=vector<string>;
using PLL =pair<ll,ll>;
using PLD=pair<ld,ld>;
using VPLL=vector<PLL>;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element((x).begin(),(x).end())
#define MIN(x) *min_element((x).begin(),(x).end())
#define SORTR(x) sort((x).rbegin(),(x).rend())
#define SORT(x) sort((x).begin(),(x).end())
#define SUM(x) accumulate((x).begin(),(x).end(), 0)
#define FILL(x,a) fill(x.begin(),x.end(),a)
#define EACH(i,x) for(typeof((x).begin()) i=(x).begin(); i!=(x).end(); ++i)

const int INF  = 1<<30;
const ld EPS   = 1e-10;
const int MOD  = int(1e9)+7;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template <class BidirectionalIterator>
bool next_partial_permutation(BidirectionalIterator first, BidirectionalIterator middle,BidirectionalIterator last){reverse(middle, last); return next_permutation(first , last);}
#define COUT(x) cout<<x<<"\n"

void Main()
{
	ll N;
	ll result=0;
	cin>>N;
	ll sum=0;
	REP(i,1000000){
		sum+=i;
		if(N<=sum){
			result=i;
			break;
		}
	}
	cout << result << "\n";
	return;
}

int main()
{
	std::cin.tie(0);
	std::ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	Main();
}


Measured memory_bytes: 256
#include<cstdio>
using namespace std;
int main()
{
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(a==1&&b==1&&c==0){
		printf("Open\n");
	}
	else if(a==0&&b==0&&c==1){
		printf("Open\n");
	}
	else{
		printf("Close\n");
	}
	return 0;
}



Measured memory_bytes: 2700
#include<iostream>
#include<cstdio>
using namespace std;
int main()
{
	int n,m,p,x,t[100005];
	while(~scanf("%d",&n))
	{
		int s=0;
		for(int i=1;i<=n;i++)
		{
			cin>>t[i];
			s+=t[i];
		}
		cin>>m;
		for(int i=0;i<m;i++)
		{
			cin>>p>>x;
			int tt=x-t[p];
			cout<<s+tt<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
const int mol=1e9+7;
int main(){
	int n,m;
	long long ans=0,sum=1;
	scanf("%d%d",&n,&m);
	if(n-m>1||m-n>1){
		printf("0\n");
		return 0;
	}
	int j=n,h=m;
	while(j>0){
		sum*=j;
		sum%=mol;
		j--;
	}
	sum%=mol;
	ans=sum;
	j=n-1;sum=1;
	while(j>0){
		sum*=h;
		sum%=mol;
		h--;
		j--;
	}
	sum%=mol;
	ans*=sum;
	ans%=mol;
	m=m-n+1;
	if(m>1){
		int k=(m-1)*m;
		k%=mol;
		ans*=k;
	}
	else if(m==1)
		ans*=2;
	ans%=mol;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 128
n,k = map(int,input().split())
locations = list(map(int,input().split()))
tmp = 10 ** 18

for left in range(n-k+1):
    right = left + k - 1
    if locations[left] * locations[right] > 0:
        answer = max(abs(locations[left]),abs(locations[right]))
    else:
        answer1 = abs(locations[left]) * 2 + locations[right]
        answer2 = locations[right]* 2 + abs(locations[left])
        answer = min(answer1,answer2)
    tmp = min(tmp,answer)
    
print(tmp)

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

inline int max(int a, int b){
	return (a>b)? a : b ;
}

int main(){
	int n, max1, max2, a[5001];

	while( cin >> n , n ){
		for(int i=0 ; i<n ; i++){
			cin >> a[i] ;
		}
		max1 = a[0];

		for(int i=0 ; i<n ; i++){
			int sum = 0;
			for(int j=i ; j<n ; j++){
				sum += a[j];
				max1 = max( max1 , sum );
			}
		}
		cout << max1 << endl;
	}
}

Measured memory_bytes: 0
# include <bits/stdc++.h>
# define int        long long
# define all(vc)   vc.begin(),vc.end()
# define all2(vc)  vc.rbegin(),vc.rend()
# define pb        push_back
# define fi        first
# define se        second
# define speed     ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
# define time      cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n"
 
using namespace std;

void solve(){
    int n, k = 1, i, p = 1e19;
    cin >> n >> k ;
    if( n == k ) cout << 0;
    else if( n < k ){
        if( n < abs(n - k) ) cout << n;
        else cout << abs(n - k);
    }
    else if( n % k == 0 ) cout << 0;
    else {
        n %= k;
        cout << k % n;
    }
}

int32_t main(){
    speed;
    cout<<fixed<<setprecision(0);
    int t = 1;
    //cin >> t;
    while( t-- ){
         solve();
         cout<<'\n';
    }

    time;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<set>
#include<map>
#include<queue>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);++i)
#define rrep(i,n) for(int (i)=(n)-1;(i)>=0;--i)
#define rep1(i,n) for(int (i)=1;(i)<=(n);++i)
#define rrep1(i,n) for(int (i)=(n);(i)>=1;--i)
#define pb push_back
#define fr first
#define sc second
typedef long long ll;
typedef pair<int,int> P;
typedef pair<long long,long long> LP;
typedef double db;
using namespace std;
ll N,M;
bool imos[100002];

int main(){
  ll A,B;
  cin>>N>>M;
  rep(i,M){
    cin>>A>>B;
    if(A>B) swap(A,B);
    imos[A]^=1;
    imos[B]^=1;
  }
  rep1(i,N-2){
    imos[i+1]^=imos[i];
  }
  // rep1(i,N-1){
  //   cout<<imos[i]<<endl;
  // }
  rep1(i,N-1){
    if(imos[i]){
      puts("NO");
      return 0;
    }
  }
  puts("YES");
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define LL long long

const int N = 5e5 + 11;

namespace IO {
struct q_instream {
  template <typename classT>
  inline q_instream operator>>(classT &e) const {
    e = 0;
    classT f = 1, c = 0;
    while (c < '0' || c > '9') {
      if (c == '-') f = -1;
      c = getchar();
    }
    while (c >= '0' && c <= '9') e = e * 10 + c - '0', c = getchar();
    return e = e * f, (*this);
  }
} in;

struct q_outstream {
  template <typename classT>
  inline q_outstream operator<<(const classT &e) const {
    if (e < 0) {
      putchar('-');
      (*this) << -e;
    } else {
      if (e > 9) (*this) << (e / 10);
      putchar(e % 10 + '0');
    }
    return (*this);
  }
  inline q_outstream operator<<(const char &c) const {
    return putchar(c), (*this);
  }
} out;
}  // namespace IO
using namespace IO;
int B;
struct Query {
  int le, ri;
  int id;
  bool operator<(const Query &b) const {
    if (le / B == b.le / B)
      return ri < b.ri;
    else
      return le / B < b.le / B;
  }
} Q[N];
int ANS[N], cnt[N], a[N], ans;
void Add(int x) {
  x = a[x];
  if (cnt[x] == 0) ans++;
  cnt[x]++;
}
void Del(int x) {
  x = a[x];
  cnt[x]--;
  if (cnt[x] == 0) ans--;
}

void solve(int q) {
  sort(Q + 1, Q + q + 1);
  memset(cnt, 0, sizeof(cnt));
  int L = 1, R = 0;
  ans = 0;
  for (int i = 1; i <= q; i++) {
    while (R < Q[i].ri) Add(++R);
    while (R > Q[i].ri) Del(R--);
    while (L < Q[i].le) Del(L++);
    while (L > Q[i].le) Add(--L);

    ANS[Q[i].id] = ans;
  }
  for (int i = 1; i <= q; i++) {
    out << ANS[i];
    puts("");
  }
}

int main() {
  int n, q;
  in >> n;
  in >> q;
  B = (int)sqrt(n * 1.0);
  for (int i = 1; i <= n; i++) in >> a[i];
  for (int i = 1; i <= q; i++) {
    in >> Q[i].le;
    in >> Q[i].ri;
    Q[i].id = i;
  }
  solve(q);
  return 0;
}

Measured memory_bytes: 15496
#include<stdio.h>
int main(){
  int a,b,c,temp;
  scanf("%d%d%d",&a,&b,&c);
  if (a > b) {
    temp = a;
    a = b;
    b = temp;
  }
  if (a > c) {
    temp = a;
    a = c;
    c = temp;
  }
  if (b > c) {
    temp = b;
    b = c;
    c = temp;
  }
  printf("%d %d %d\n",a,b,c);
  return 0;
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
#define ll long long int
#define vec vector<ll>
#define mat vector<vec>

using namespace std;

const ll mod=1000000007;
const ll inf=LONG_LONG_MAX;
ll dx4[4]={1,0,-1,0};
ll dy4[4]={0,-1,0,1};
ll dx8[8]={1,0,-1,1,-1,1,0,-1};
ll dy8[8]={1,1,1,0,0,-1,-1,-1};

int main(){

  ll n,h;
  cin >> n >> h;
  vec a(n),b(n);
  for(ll i=0;i<n;i++)cin >> a[i] >> b[i];

  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  ll r=1000000000,l=0;
  ll half;
  ll p=upper_bound(b.begin(),b.end(),a[n-1])-b.begin();
  p=n-p;
  ll m=0;
  for(ll i=0;i<p;i++)m+=b[n-1-i];
  
  while(abs(r-l)>1){
    ll s=0;
    half=(r+l)/2;
    if(half<=p){
      for(ll i=0;i<half;i++){
        s+=b[n-1-i];
      }
    }
    else{
      s+=(half-p)*a[n-1];
      s+=m;
    }
    if(s>=h)r=half;
    else l=half;
  }

  cout << r << endl;
  //cout << p << endl;

  
  

}

Measured memory_bytes: 4840
let readString() = stdin.ReadLine()
let readStringArray() = stdin.ReadLine().Split(' ');
let readInt() = readString() |> int
let readIntArray() = readStringArray() |> Array.map(fun x -> int x)
let char2String(value) = List.ofSeq value |> List.toArray |> System.String

[for i in [1..5] -> readInt()]
|> List.sortBy (fun x -> (x - 1) % 10)
|> fun x ->  
    match x with
    | h :: t -> h + List.sumBy (fun x -> x + if x % 10 = 0 then 0 else 10 - x % 10) t 
    | _ -> 0
|> printfn "%d"

Measured memory_bytes: 14940
#include<iostream>
#include<string>
#include<sstream>
#include<algorithm>
#include<cmath>
#include<map>
#include<set>
#include<vector>
#include<stack>
#include<queue>
#include<deque>
using namespace std;

bool sameside (double ax, double ay, double bx, double by, double cx, double cy, double dx, double dy) {
    bool result = false;
    if (ax != bx) {
        double r = (ay - by) / (ax - bx);
        double s = ay - r * ax;
        if ( (r * cx + s - cy) * (r * dx + s - dy) > 0) {
            result = true;
        }
    } else {
        if ( (cx - ax) * (dx - ax) > 0 ) {
            result = true;
        }
    }
    return result;
}

int main() {
     
    double ax, ay, bx, by, cx, cy, dx, dy;
    char c;
    while(cin >> ax >> c >> ay >> c >> bx >> c >> by >> c >> cx >> c >> cy >> c >> dx >> c >> dy) {
        if( sameside(ax, ay, cx, cy, bx, by, dx, dy) || sameside(bx, by, dx, dy, ax, ay, cx, cy) ) {
            cout << "NO" << endl;
        } else {
            cout << "YES" << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 0
// https://atcoder.jp/contests/arc059/tasks/arc059_b

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

const ll INF = 1e18;

void solve() {
  string s;
  cin >> s;
  ll N = s.size();

  // AA or AXA or AXYA のいずれかのみを考慮すれば十分

  rep(i, N - 1) {
    if (s[i] == s[i + 1]) {
      print_ints({i + 1, i + 2});
      return;
    }
  }
  rep(i, N - 2) {
    if (s[i] == s[i + 2]) {
      print_ints({i + 1, i + 3});
      return;
    }
  }

  print_ints({-1, -1});
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

template <typename T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

void print_ints(vector<ll> v) {
  rep(i, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


Measured memory_bytes: 512
import qualified Data.ByteString.Char8 as BS

main = do
    ni <- BS.getLine 
    let n = read $ BS.unpack ni :: Int
    slime_i <- BS.getLine 
    let slime = BS.unpack slime_i
    if n == 1
        then putStrLn "1"
        else putStrLn $ show $ check (head slime) (tail slime)

check :: Char -> [Char] -> Int
check prev (x:[]) = answer
    where answer = if prev == x
            then 1
            else 2
check prev (x:xs) = answer + (check x xs)
    where answer = if prev == x
            then 0
            else 1

Measured memory_bytes: 1916
#[allow(unused_imports)]
use proconio::{fastout, input, marker::*};

#[fastout]
fn main() {
    input! {
        x: usize,
        n: usize,
        p: [usize; n],
    }
    let mut dp = vec![true; 103];
    for i in 0..n {
        dp[p[i]] = false;
    }

    for i in 0..102 {
        if i <= x && dp[x - i] {
            println!("{}", x - i);
            break;
        }

        if dp[x + i] {
            println!("{}", x + i);
            break;
        }
    }
}


Measured memory_bytes: 2180
#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;
    ll d;cin>>d;
    ll d2 = d*d;
    int ans = 0;
    rep(i,n){
        ll x,y;cin>>x>>y;
        if(x*x + y*y <= d2)++ans;
    }
    cout<<ans<<endl;
	return 0;
}

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

int main() {
  
  int n,m;
  cin >> n >> m;
  
  vector<pair<int,int>> p;
  long long a,b;
  
  
  for ( int i = 0; i < n; i++){
    cin >> a >> b;
    p.push_back(make_pair(a,b));
  }
  
  sort(p.begin(),p.end());
  
  long long cnt = 0,price = 0;
  
  for ( int i = 0; i < n; i++){
    tie(a,b) = p[i];
    //cout << a << ' ' << b << endl;
    if ( cnt + b <= m ){
      cnt += b;
      price += a * b;
    }else{
      price += a * ( m - cnt );
      break;
    }
    //cout << cnt << ' ' << price << endl;
  }
  
  cout << price << endl;  
 
}


Measured memory_bytes: 4244
# 5
import sys


def input(): return sys.stdin.readline().strip()
def I(): return int(input())
def LI(): return list(map(int, input().split()))
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def S(): return input()
def LS(): return input().split()


INF = float('inf')


n = I()
s = S()
ciphers = [f'{i:03}' for i in range(1000)]
ans = 0
for v in ciphers:
    j = 0
    for i in range(n):
        if s[i] == v[j]:
            j += 1
        if j == 3:
            ans += 1
            break
print(ans)


Measured memory_bytes: 68588
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sys/time.h>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>

using namespace std;

void solve(long long N, vector<long long> P){
    long long INF = 1000000000;
    vector<long long> dp(N, 1);
    long long m = 1;
    vector<long long> b(N);
    for (int i = 0; i < N; i++) {
        b[P[i]-1] = i;
    }
    for (int i = 0; i < N - 1; i++) {
        if (b[N-1-i] - b[N-2-i] > 0) {
            dp[N-2-i] = dp[N-1-i] + 1;
        } else {
            dp[N-2-i] = 1;
        }
    }
    m = *max_element(dp.begin(), dp.end());
    std::cout << N - m << std::endl;
}

int main(){	
    struct timeval start,end;
    long long span;
    gettimeofday(&start,NULL);

    long long N;
    scanf("%lld",&N);
    vector<long long> P(N-1+1);
    for(int i = 0 ; i <= N-1 ; i++){
    	scanf("%lld",&P[i]);
    }
    solve(N, P);

    gettimeofday(&end,NULL);
    span = (end.tv_sec -start.tv_sec)*1000000LL + (end.tv_usec - start.tv_usec);
    std::cerr << "--Total Time: " << span/1000 << "ms" << endl;
    return 0;
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ll mod = 1e9 + 7;
//const ll mod = 998244353;
#define REP(i,n) for(int i=0;i<(int)n;++i)
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
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 (a>b) { a=b; return 1; } return 0; }
template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
for(int i = 0; i < (int)v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}
string num2bit(ll num, ll len){
    string bit = "";
    REP(i, len){
    bit += char('0'+(num>>i & 1));
    }
    return bit;
}

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

    ll N, K, C;
    cin >> N >> K >> C;
    string S;
    cin >> S;

    vector<ll> dp(N, 0);
    for(int i=N-1;i>=0;i--){
        if(S[i]=='x'){
            if(i!=N-1) dp[i] = dp[i+1];
        }else{
            if(i+C+1>N-1){
                dp[i] = 1;
            }else{
                dp[i] = dp[i+C+1] + 1;
            }
        }
    }

    ll now = 0;
    ll cnt = 0;
    vector<ll> res;
    while(now<N){
        if(S[now]=='o'){
            ll tasu = (now==N-1 ? 0 : dp[now+1]);
            if(cnt+tasu<K) res.push_back(now);
            cnt++;
            now += C+1;
        }else{
            now++;
        }
    }

    for(auto x: res){
        cout << x + 1 << "\n";
    }

    return 0;
}

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

int main(){
  int n;
  string s;
  cin >> n >> s;
  int ans =0;
  int max1 = 0;
  for(char i:s){
      if(i=='I') ans++;
      else ans--;
      max1 = max(ans,max1);
  }
  cout << max1 << endl;
}

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

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
  int N, M;
  cin >> N >> M;
  cout << (N+M)*(N+M-1)/2-N*M << endl;

return 0;
}




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

R = max(X)
L = min(X)

ans = float('inf')

for i in range(L, R+1):
  cost = 0
  for j in X:
    cost += (j - i) * (j - i)
  ans = min(ans, cost)

print(ans)

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

using namespace std;

class A {
	int a, b, c;

public:
	void solve()
	{
		cin >> a >> b >> c;
		if ((b - a) == (c - b)) cout << "YES" << endl;
		else cout << "NO" << endl;
	}
};

class B {
	string O, E;

public:
	void solve()
	{
		cin >> O >> E;

		for (size_t i{ 0 }; i < E.length(); i++)
		{
			cout << O[i] << E[i];
		}

		if (E.length() != O.length())
			cout << O.back();

		cout << endl;
	}
};


int main()
{
	A solution;
	solution.solve();

	return 0;
}

Measured memory_bytes: 256
n = int(input())
dList = []

for i in range(n):
  dList.append(int(input()))

dList.sort()

gokei = sum(dList)
if gokei % 10 == 0:
  for i in dList:
    if (gokei - i ) % 10 != 0:
      print(gokei -i)
      exit(0)
  print(0)
else:
  print(gokei)
  

Measured memory_bytes: 3060
from sys import stdin
x1,y1,x2,y2=[int(x) for x in stdin.readline().rstrip().split()]
x3=x2-(y2-y1)
y3=y2+(x2-x1)
x4=x1-(y2-y1)
y4=y1+(x2-x1)
print(x3,y3,x4,y4)

Measured memory_bytes: 3060
import sys
sys.setrecursionlimit(2000000)

n=int(input())
three=['3','5','7']


ans=[]
def search(dfs):
    newdfs=[]
    for moto in dfs:
        for i in three:
            new=moto+i
            threeok=[False for k in range(3)]
            if int(new)>n:
                return
            for m in list(new):
                for j in range(3):
                    if m==three[j]:
                        threeok[j]=True
                        break
            if False not in threeok:
                ans.append(new)
            newdfs.append(new)
    search(newdfs)

search(three)

print(len(ans))

Measured memory_bytes: 5464
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("fast-math")
#pragma GCC optimize("trapv")
#pragma GCC target("sse4")

#include<bits/stdc++.h>
#include<iomanip>
#define inf  (int)1e18
#define EPS   1e-9
#define MOD 1000000007
#define all(k) sort(k.begin(),k.end())
#define Pi 3.14159
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (ll i=n-1;i>=a;i--)
#define repk(i,a,n) for(int i=a;i<=(n);i++)
#define ll  long long
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#define mp make_pair
#define F first
#define S second
#define pi pair<int,int>
#define pl pair<ll,ll>
#define vc vector<char>
#define vl vector<ll>
#define vi vector<int>
#define mi map<int,int>
#define ml map<ll,ll>
#define umap unordered_map<ll,int>
using namespace std;

void sol() {

	int n;
	cin >> n;
	if (n == 0)
		cout << 1;
	else if (n == 1)
		cout << 0;

}

int main() {


	int t = 1;


	// cin >> t;
	for (int i = 0; i < t; ++i) {
		sol();

	}


	return 0;
}

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

typedef long long ll;
#define MOD = 1000000007;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define ALL(a) begin(a),end(a)
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_v(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << endl; }
template<class T> void cout_h(const vector<T>& c)
{ for (int i = 0; i < c.size(); i++) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
template<class T> inline bool is_overlap(const T& as, const T& ae, const T& bs, const T& be)
{ return bs <=ae && as <= be; }
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
#define ANS(a) cout<<a<<endl
void yes(bool f){cout<<(f?"yes":"no")<<endl;}
void Yes(bool f){cout<<(f?"Yes":"No")<<endl;}
void YES(bool f){cout<<(f?"YES":"NO")<<endl;}

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //cout<<std::fixed<<std::setprecision(10);

    string S; cin >>S;

    int ans = INT_MAX;
    for (int i = 0; i <= S.size() - 3; i++) {
        chmin(ans, abs(stoi(S.substr(i, 3)) - 753));
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
n = int(input())
s = [input() for _ in range(n)]
m = int(input())
t = [input() for _ in range(m)]

words = {}
for i in range(n):
    if not s[i] in words.keys():
        words[s[i]] = 1
    else:
        words[s[i]] += 1
for i in range(m):
    if not t[i] in words.keys():
        words[t[i]] = -1
    else:
        words[t[i]] -= 1

ans = 0
for k, v in words.items():
    ans = max(ans, v)
print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i=a; i<n; i++)
#define RREP(i, a, n) for(ll i=n-1; i>=a; i--)
typedef long long ll;
const ll mod =1e9+7;
const ll inf =1e18;
using namespace std;

ll n, m, X, Y;
ll x[101], y[101];
int main() {
    cin>>n>>m>>X>>Y;
    REP(i, 0, n) cin>>x[i];
    REP(i, 0, m) cin>>y[i];

    sort(x, x+n);
    sort(y, y+m);
    bool flag=false;
    REP(i, -100, 101){
        if(X<i && i<=Y && x[n-1]<i && i<=y[0]){
            flag=true;
            break;
        }
    }
    if(flag) cout<<"No War"<<endl;
    else cout<<"War"<<endl;
    return 0;
}

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	string S=in<string>();
	S += S;
	string P=in<string>();
	auto res = search(ALL(S),ALL(P));
	out(res!=S.end() ? "Yes" : "No");

	return 0;
}



Measured memory_bytes: 3208
#include<bits/stdc++.h>
using namespace std;
using LL = long long;
int main() {
  LL X, Y, A, B, C;
  cin >> X >> Y >> A >> B >> C;
  deque<LL> p(A), q(B), r(C);
  for(auto v: {&p, &q, &r}) {
    for(auto& i: *v) cin >> i;
    sort(rbegin(*v), rend(*v));
  }
  multiset<LL> R, G;
  for(auto i=0; i<min(X,A); ++i) R.emplace(p[i]);
  for(auto i=0; i<min(Y,B); ++i) G.emplace(q[i]);
  for(auto i=R.size(); i<X; ++i) R.emplace(r.front()), r.pop_front();
  for(auto i=G.size(); i<Y; ++i) G.emplace(r.front()), r.pop_front();
  while(!r.empty()) {
    auto& l=R;
    auto& h=G;
    if(*begin(l) > *begin(h)) swap(l, h);
    if(r.front() <= *begin(l)) break;
    l.erase(begin(l));
    l.emplace(r.front());
    r.pop_front();
  }
  cout << accumulate(begin(R), end(R), 0ll) + accumulate(begin(G), end(G), 0ll) << endl;
}


Measured memory_bytes: 14456
#include<iostream>
#include<string>
#include<vector>

using namespace std;
bool isOK(string);
string isOK(string, char);

int main() {
    string str;
    bool ans;
    cin >> str;

    ans = isOK(str);
    if( ans ) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}

bool isOK(string str){
    bool a=true,b=true,c=true;
    int count=0;
    if (str == "ABC") return true;
    if(str.size() < 3) return false;
    for(int i=0; i< str.size() ;){
        if( str[i] == 'A'){
            i++;
            //a++;
            if(!(i<str.size())) break;
            if(str[i] == 'B') {
                i++;
                //b++;
                if(!(i<str.size())) break;
                if(str[i] == 'C'){
                    count++;
                    //c++;
                    //i = i-2;
                    //str.erase(str.begin() + i, str.begin() + i +3);
                    //str.insert(str.begin() + i, mo);
                    i++;
                }else{
                    a=false; b=false;//b++;
                }
            }else{
                if(str[i]=='A')a=false;//b++;
                if(str[i]=='C'){a=false;c=false;}//b++;
            }
        }else{
            if(str[i]=='B')b=false;//b++;
            if(str[i]=='C')c=false;//c++;
            i++;
        }
    }
    if(count==0)return false;
    if(a)return isOK(isOK(str,'A'));
    if(b)return isOK(isOK(str,'B'));
    if(c)return isOK(isOK(str,'C'));
    return false;
}

string isOK(string str, char mo){
    int count=0;
    //if (str == "ABC") return true;
    //if(str.size() < 3) return false;
    for(int i=0; i< str.size() ;){
        if( str[i] == 'A'){
            i++;
            //a++;
            if(!(i<str.size())) break;
            if(str[i] == 'B') {
                i++;
                //b++;
                if(!(i<str.size())) break;
                if(str[i] == 'C'){
                    count++;
                    //c++;
                    i = i-2;
                    str.erase(str.begin() + i, str.begin() + i +3);
                    str.insert(str.begin() + i, mo);
                    i++;
                }else{
                   // a=false; b=false;//b++;
                }
            }else{
               // if(str[i]=='A')a=false;//b++;
               // if(str[i]=='C'){a=false;c=false;}//b++;
            }
        }else{
            //if(str[i]=='B')b=false;//b++;
            //if(str[i]=='C')c=false;//c++;
            i++;
        }
    }
    return str;
    /*if(count ==0) {return false;}
    else{ 
        if(a) return isOK(str,'A');
        else if(b) return isOK(str,'B');
        else if(c) return isOK(str,'C');
        else return false;
    }*/
}



Measured memory_bytes: 9532
from itertools import permutations


def warshall_floyd(d):
    # d        : nxn adjacent matrix
    for k in range(n):
        for i in range(n):
            for j in range(n):
                if d[i][j] > d[i][k] + d[k][j]:
                    d[i][j] = d[i][k] + d[k][j]


INF = float("inf")

n, m, r = map(int, input().split())
r_list = list(map(lambda x: int(x) - 1, input().split()))
d = [[INF] * n for _ in range(n)]
for i in range(n):
    d[i][i] = 0
for i in range(m):
    a, b, c = map(int, input().split())
    a, b = a - 1, b - 1
    d[a][b] = d[b][a] = c
warshall_floyd(d)

ans = float("inf")
for np in permutations(r_list):
    cand = sum([d[np[i]][np[i + 1]] for i in range(r - 1)])
    ans = min(ans, cand)

print(ans)


Measured memory_bytes: 4636
#include <stdio.h>
#include <algorithm>

using namespace std;

int main(void)
{
	int d;
	int n, m;
	int ans;
	int coor[100000];
	int query[10000];
	int store[100000];
	int last;
	
	while (1){
		scanf("%d", &d);
		
		if (d == 0) break;
		
		scanf("%d%d", &n, &m);
		
		coor[0] = 0;
		for (int i = 1; i < n; i++){
			scanf("%d", &coor[i]);
		}
		for (int i = 0; i < m; i++){
			scanf("%d", &query[i]);
		}
		
		sort(coor, coor + n);
		
		last = (d + coor[n - 1]) / 2 + 1;
		
		for (int i = 1; i < n; i++){
			store[i - 1] = (coor[i] + coor[i - 1]) / 2 + 1;
		}
		store[n - 1] = last - 1;
		/*
		for (int i = 0; i < n; i++){
			printf("%d ", store[i]);
		}
		puts("");
		*/
		ans = 0;
		for (int i = 0; i < m; i++){
			if (query[i] >= last){
				ans += d - query[i];
			}
			else {
				ans += abs(query[i] - coor[(upper_bound(store, store + n, query[i]) - store)]);
			}
		}
		
		printf("%d\n", ans);
	}
	return (0);
}

Measured memory_bytes: 1228
#include<stdio.h>
int main(void)
{
	int a,b;
	int sum=0;
	scanf("%d%d",&a,&b);
	
	if(a>b){
	sum=a;
	a--;
	}
	else{
	sum=b;
	b--;
	}
	
	if(a>b)
	sum=sum+a;
	else
	sum=sum+b;
	
	printf("%d",sum);

	return 0;
}

Measured memory_bytes: 1716