akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int,int> pii;
typedef pair<long,long> pll;
typedef long long ll;
typedef vector<pii> vpii;
#define reps(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define all(g) (g).begin(),(g).end()
#define pb push_back
const int mod = 1e9 + 7;
#define INF 1<<25
/*
input case
output case
*/

int N, L;
const int MAX = 100100;
int a[MAX];

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

    cin >> N >> L;
    rep(i,N) cin >> a[i];

    int tmp = -1;
    rep(i,N){
        if (a[i]+a[i+1] >= L){
            tmp = i;
        }
    }

    if (tmp == -1){
        cout << "Impossible" << endl;
    }else{
        cout << "Possible" << endl;
        rep(i,tmp) cout << (i+1) << endl;
        for(int i = N-1; tmp < i ;--i){
            cout << i << endl;
        }
    }
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define ld double
#define ull unsigned long long
#define ll long long
#define pii pair <int, int>
#define iiii pair <int, pii >
#define mp make_pair
#define INF 1000000000
#define MOD 1000000007
#define rep(i, x) for(int (i) = 0; (i) < (x); (i)++)
inline int getint() {
  int x = 0, p = 1; char c = getchar();	
  while (c <= 32) c = getchar();
  if (c == 45) p = -p, c = getchar();
  while (c > 32) x = x * 10 + c - 48, c = getchar();
  return x * p;
}
using namespace std;
//ruogu_alter
int n, s;
deque<pair<int, ll>> dq;
#define int ll 
//
signed main() {
  n = getint(); s = getint();
  rep(i, n) {
    int x = getint(), y = getint();
    dq.emplace_back(x, y);
  }
  vector<int> pos;
  while (1) {
    pii x = dq.front(), y = dq.back();
    if (y.first < s) {
      pos.emplace_back(x.first);
      break;
    }
    if (x.first > s) {
      pos.emplace_back(y.first);
      break;
    }
    if (x.second >= y.second) {
      dq[0].second += y.second;
      dq.pop_back();
      pos.emplace_back(y.first);
    }
    else {
      dq[dq.size() - 1].second += x.second;
      dq.pop_front();
      pos.emplace_back(x.first);
    }
  }
  ll res = 0;
  for (int i = pos.size() - 1; i >= 0; i--) {
    res += abs(s - pos[i]);
    s = pos[i];
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 2632
#include<stdio.h>
int main()
{
    int N,A,B;
    scanf("%d %d %d",&N,&A,&B);
    if(1<=N&&N<=20&&1<=A&&A<=50&&1<=B&&B<=50)
    {
        if(N*A<B)
        {
            printf("%d",N*A);
        }
        else if(N*A>B)
        {
            printf("%d",B);
        }
        else if(N*A==B)
        {
            printf("%d",B);
        }

    }
    return 0;

}


Measured memory_bytes: 128
x, y = map(int, input().split())

if y >= x:
    if x >= 0:
        ans = y - x
    elif x < 0:
        if y >= -x:
            ans = min([y + x + 1, y - x])
        elif y < -x:
            if y >= 0:
                ans = min([-x - y + 1, y - x])
            elif y < 0:
                ans = y - x
elif y < x:
    if y >= 0:
        ans = min([x - y + 2, y + x + 1])
    elif y < 0:
        if x >= 0:
            if -x >= y:
                ans = -x - y + 1
            elif -x < y:
                ans = y + x + 1
        elif x < 0:
            ans = min([x - y + 2, -y - x + 1])

print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
  int k,s; cin >> k >> s;
  // x + y + z = s
  // z = s - x - yとなるzを見つける
  
  vector<int> vecK(k+1);
  for(int i = 0; i <= k; i++ )
  {
    vecK[i] = i;
  }
  
  // zの取りうる値は0<=z<=k
  int count = 0;
  for (int i = 0; i <= k; i++)
  {
    for (int j = 0; j <=k; j++)
    {
      if( binary_search(vecK.begin(),vecK.end(),s - i - j) ) count++;
    }
  }
  cout << count << endl;
  
  return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

const ll MOD = 1000000007;
const ll MAX = 200001;

ll mod(ll a){
  return a % MOD;
}

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

ll fac[MAX], finv[MAX], inv[MAX];

void nCrprep() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll nCr(ll n, ll r){
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

ll nCrcheep(ll n,ll r){
  if(r == 0) return 1;
  else if(r == 1) return n;
  else return nCrcheep(n-1,r-1)*n/r;
}

int main(){
  ll n; cin >> n; ll sum = 0;
  vl num(100001);
  
  rep(i,n){
    ll x; cin >> x;
    num[x]++;
    sum += x;
  }
  
  ll q; cin >> q;
  rep(i,q){
    ll a,b; cin >> a >> b;
    sum += (b-a)*num[a];
    num[b] += num[a];
    num[a] = 0;
    
    cout << sum << endl;
    
  }
  
}
  


Measured memory_bytes: 4052
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
int main() {
  int a,b;
  cin >> a >> b;
  int ans=0;
  while(b > ans*a-ans+1){
    ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
unittest
{
	assert( [ "4 2 5", "1 2 5 7" ].parse.expand.solve == 11 );
	assert( [ "7 1 100", "40 43 45 105 108 115 124" ].parse.expand.solve == 84 );
	assert( [ "7 1 2", "24 35 40 68 72 99 103" ].parse.expand.solve == 12 );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto nab = input.front.split.to!( long[] );
	input.popFront;
	auto xs = input.front.split.to!( long[] );
	return tuple( nab[ 1 ], nab[ 2 ], xs );
}

auto solve( long a, long b, long[] xs )
{
	auto ans = 0L;
	for( auto i = 1L; i < xs.length; i++ )
	{
		ans += min( ( xs[ i ] - xs[ i - 1 ] ) * a, b );
	}
	return ans;
}


Measured memory_bytes: 6964
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author Pradyumn Agrawal (coderbond007)
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        CUbiquity solver = new CUbiquity();
        solver.solve(1, in, out);
        out.close();
    }

    static class CUbiquity {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            long N = in.nextLong();
            long all = Modular.powerMod(10, N, Modular.MOD7);
            long remove = Modular.subtract(Modular.multiply(2L, Modular.powerMod(9, N, Modular.MOD7), Modular.MOD7), Modular.powerMod(8, N, Modular.MOD7), Modular.MOD7);
            out.println(Modular.subtract(all, remove, Modular.MOD7));
        }

    }

    static class Modular {
        public static final long MOD7 = (long) 1e9 + 7;

        public static long powerMod(long a, long n, long mod) {
            //    a %= mod;
            long ret = 1;
            int x = 63 - Long.numberOfLeadingZeros(n);
            for (; x >= 0; x--) {
                ret = ret * ret % mod;
                if (n << 63 - x < 0) ret = ret * a % mod;
            }
            return ret;
        }

        public static long multiply(long a, long b, long MODULO) {
            long res = 0;
            a %= MODULO;
            while (b != 0) {
                if ((b & 1) != 0) {
                    res = (res + a) % MODULO;
                }
                a = a * 2 % MODULO;
                b >>>= 1;
            }
            return res;
        }

        public static long subtract(long a, long b, long mod) {
            long ans = a - b;
            while (ans < mod) ans += mod;
            return ans % mod;
        }

    }

    static class FastScanner {
        BufferedReader reader;
        StringTokenizer tokenizer;

        public FastScanner(InputStream inputStream) {
            reader = new BufferedReader(new InputStreamReader(inputStream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

    }
}



Measured memory_bytes: 33060
#include <bits/stdc++.h>
using namespace std;
#define N 100010
int cnt[2][N],Mx[2],Mxt[2],Mx2[2],Mxt2[2];
int main(){
	int n; scanf("%d",&n);
	for (int i=1;i<=n;i++){
		int x; scanf("%d",&x);
		cnt[i&1][x]++;
		if (cnt[i&1][x]>Mx[i&1]){
			Mx[i&1]=cnt[i&1][x]; 
			Mxt[i&1]=x;
			if (x!=Mxt[i&1]){
			//	puts("WTF");
				Mx2[i&1]=Mx[i&1];
				Mxt2[i&1]=Mxt[i&1];
			}
		}else
			if (cnt[i&1][x]>Mx2[i&1]){
			//	puts("WTF");
				Mx2[i&1]=cnt[i&1][x];
				Mxt2[i&1]=x;
			}
	}
	int n1=n/2,n2=n/2; if (n&1) n1++;
//	printf("%d %d\n",n1,n2);
//	printf("%d %d\n",Mx[1],Mx2[1]);
//	printf("%d %d\n",Mx[0],Mx2[0]); printf("%d %d\n",Mxt2[1],Mxt2[0]);
	if (Mxt[1]!=Mxt[0]) printf("%d\n",n1-Mx[1]+n2-Mx[0]);
	else printf("%d\n",min(n1-Mx[1]+n2-Mx2[0],n1-Mx2[1]+n2-Mx[0]));
	return 0;
}
	
	

Measured memory_bytes: 1024
from sys import stdin, setrecursionlimit


def main():
    input = stdin.buffer.readline
    x = int(input())

    while True:
        for i in reversed(range(1, x)):
            if i == 1:
                print(x)
                exit()
            elif x % i == 0:
                break
        else:
            continue
        x += 1
        continue


if __name__ == "__main__":
    setrecursionlimit(10000)
    main()


Measured memory_bytes: 40556
h, w, k = map(int, input().split())
ans = 0
c = [input() for i in range(h)]
for i in range(1<<h):
    for j in range(1<<w):
        cnt = 0
        for l in range(h):
            for m in range(w):
                if c[l][m] == '#' and (i >> l) & 1 and (j >> m) & 1:
                    cnt += 1
        if cnt == k:
            ans += 1
print(ans)


Measured memory_bytes: 9068
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
using namespace std;
typedef long long ll;

int main(){
    int n;
    cin >> n;
    vector<int> p(n), q(n), v(n);

    rep(i,n){cin >> p[i]; p[i]--;}
    rep(i,n){cin >> q[i]; q[i]--;}
    rep(i,n) v[i] = i;

    map<vector<int>, int> ord;
    int num = 0;

    do{
        ord[v] = num++;
    }
    while(next_permutation(all(v)));

    dunk(abs(ord[p]-ord[q]));

}

Measured memory_bytes: 5248
open Printf
let input_int_array n =
	Array.init n (fun _ -> Scanf.scanf " %d" (fun v -> v))

let get_int () = Scanf.scanf " %d" (fun v -> v)
let get_2_ints () = Scanf.scanf " %d %d" (fun u v -> u,v)
let get_3_ints () = Scanf.scanf " %d %d %d" (fun u v w -> u,v,w)
let get_4_ints () = Scanf.scanf " %d %d %d %d" (fun u v w x -> u,v,w,x)
let get_5_ints () = Scanf.scanf " %d %d %d %d %d" (fun u v w x y -> u,v,w,x,y)

let print_int_endline n = n |> string_of_int |> print_endline

let () =
  let a,b = get_2_ints ()
  in
  (if a+b = 15 then "+" else if a*b = 15 then "*" else "x")
  |> print_endline

Measured memory_bytes: 384
from collections import defaultdict
import queue

if __name__ == "__main__":
    inp = [int(i) for i in input().split()]
    N = inp[0]
    M = inp[1]
    adjs = defaultdict(lambda: [])
    for i in range(M):
        a, b = [int(i) for i in input().split()]
        adjs[a].append(b)
        adjs[b].append(a)
    
    q = queue.Queue()
    q.put([1])
    n = 0
    while True:
        if q.empty(): break
        p = q.get()
        if len(p) == N:
            n += 1
        else:
            for i in adjs[p[-1]]:
                if i not in p:
                    pp = p.copy()
                    pp.append(i)
                    q.put(pp)
    print(n)

Measured memory_bytes: 4840
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <bitset>
#include <cassert>
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define srep(i,n,m) for(int i=n;i<m;i++)
#define elif else if
#define INF 1000000007
#define pi 3.141592653589793
using namespace std;
int saidaikouyakusuu(int a,int b){
    if(b==0) return a;
    return saidaikouyakusuu(b,a%b);
}
int saisyoukoubaisuu(int a,int b){
    return a*b/saidaikouyakusuu(a,b);
}
int n,m,cnt=0,aa[220000],ans=0,t,a;
pair<int,int> pp[220000];
string s,ss[220000];
char c;
queue<int> que;
signed main(){
    cin>>n;
    rep(i,50){
        rep(j,9){
            if(pow(i+1,j+2)<=n){
                cnt=max(double(cnt),pow(i+1,j+2));
            }
        }
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 11020
#include<stdio.h>

int main(){

  int i,I,j,k,Ju,n,u,Adj[110][110];

  scanf("%d",&n);

 for(i=0 ; i<=n ; i++){
   for(j=0 ; j<=n ; j++){ 
   Adj[i][j] = 0;
   }
 }


  for(i=1 ; i<=n ; i++){
    scanf("%d",&I);
    scanf("%d",&k);
    for(j=1 ; j<=k ; j++){
        scanf("%d",&Ju);
        Adj[I][Ju] = 1;
  }
}

 for(i=1 ; i<=n ; i++){
   for(j=1 ; j<=n ; j++){
     printf("%d",Adj[i][j]);
     if(j != n )  printf(" ");
   }
   printf("\n");
 }   

 return 0;
}



Measured memory_bytes: 2048
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;

int b,r,g,c,s,t;

void solve() {
    int ans = 100;
    t-=s;
    ans += c*2;
    ans += g*7;
    ans -= t*3;
    ans += r*3*16;
    ans += b*5*16;
    ans += r*15;
    ans += b*15;
    cout<<ans<<endl;

}

int main() {
    while(cin>>b>>r>>g>>c>>s>>t) {
        if(b+r+g+c+s+t==0) break;
        solve();
    }
    return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
  int N; cin >> N;
  vector<int> H(N);
  bool ans = true;
  for(int i = 0; i < N; ++i) cin >> H[i];
  reverse(H.begin(), H.end());
  for(int i = 0; i < H.size()-1; ++i) {
    if(H[i] >= H[i+1]) continue;
    else if(H[i] + 1 == H[i+1]) H[i+1] = H[i+1] - 1;
    else {
      ans = false;
    }
  }
  std::cout << (ans ? "Yes" : "No") << std::endl;
  return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;

int main(void) {
    ll N, M;
    list<pair<ll, ll>> A;
    ll sum = 0;
    ll count = 0;
    cin >> N >> M;
    for(ll i = 0;i < N;i++) {
        ll temp;
        cin >> temp;
        A.emplace_back(1, temp);
    }
    for(ll i = 0;i < M;i++) {
        ll b, c;
        cin >> b >> c;
        A.emplace_back(b, c);
    }
    A.sort([](pair<ll, ll> a, pair<ll, ll> b) { return a.second < b.second; });
    auto iter = A.rbegin();
    while(count < N) {
        pair<ll, ll> p = *iter++;
        ll c = min(p.first, N - count);
        count += c;
        sum += p.second * c;
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 9728
#include <iostream>
#include <math.h>
using namespace std;

int nannkaiwareru(int x){
	int count = 0;
	while((x%2)==0){
		count++;
		x=x/2;
	}
	return count;
}

int main(){
	int n;
	int answer=0;
	cin >> n;
	
	int i=0;
	while(n-i>0){
//	for(int i=0;i<100;i++){
		answer=max(answer,nannkaiwareru(n-i));
		i++;
	}
	cout << pow(2,answer) << endl;;
	return 0;
}

Measured memory_bytes: 384
import java.util.Scanner

object Main {
  def main(args: Array[String]): Unit = {
    //nextLineとnextを同時に使ったら死ぬ
    val sc = new Scanner(System.in)
    val n = sc.nextInt()
    val s = sc.next()
    val sum = s
      .map {
        case c if c == '(' => 1
        case _             => -1
      }
      .scan(0)(_ + _)
    val min = sum.min
    (1 to (-min)).foreach(_ => print('('))
    print(s)
    (1 to  (sum.last - min)).foreach(_ => print(')'))
    println()
  }
}


Measured memory_bytes: 25420
#include<iostream>

using namespace std;

int main() {
    int N, L;

    cin >> N >> L;

    int select = 999, sum = 0;

    for(int i = 0; i < N; i++){
        int agi = L + i;
        sum += agi;
        if(abs(agi) < abs(select)){
            select = agi;
        }
    }

    int ans = sum - select;

    cout << ans << endl;

    return 0;
}

int abs(int num){
    return num < 0 ? -num : num;
}

Measured memory_bytes: 256
import sys
from collections import deque

def solve():
    input = sys.stdin.readline
    N = int(input())
    first = False
    for _ in range(N):
        a = int(input())
        if a % 2 == 1: first = True
    if first: print("first")
    else: print("second")
    
            
    return 0

if __name__ == "__main__":
    solve()

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

int main()
{
    ll n, k;
    cin >> n >> k;
    if (2 * k - 1 <= n)
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#define ll long long

using namespace std;


int main() {
	int s; cin >> s;
	cout << s / 3600 << ":" << (s % 3600) / 60 << ":" << s % 60 << endl;
}




Measured memory_bytes: 3116
#include <cstdio>
#include <cstdlib>
#include <cstring>
#define INF (__INT32_MAX__ / 2)
#define BTC 380000.0

using namespace std;



int main(int argc, char **argv) {
    int n;
    scanf("%d", &n);

    double sum = 0;
    for(int i = 0; i < n; ++i) {
        char x[10];
        double val;
        scanf("%lf", &val);
        scanf("%s", x);

        if(strcmp(x, "JPY") == 0)
            sum += val;
        else
            sum += val * BTC;
        
    }

    printf("%lf\n", sum);
}

Measured memory_bytes: 128
x,y = gets.split.map(&:to_i)
count = "-1 -1 -1"
(0..x).each do |n|
  (0..(x-n)).each do |m|
    l = x - n -m
    count = "#{n} #{m} #{l}" if 10000 * n + 5000 * m + 1000 * l == y
  end
end
puts count

Measured memory_bytes: 1788
#include <stdio.h>
#define N 100000

void swap(int *,int *);
int partition(int *,int,int);

int main() {
    int n, a[N], i,p,r,key;
    scanf("%d", &n);

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

    p = 0;
    r = n-1;
    key = partition(a, p, r);

    for (i = 0; i < n-1; i++) {
        if(key == i) printf("[%d] ", a[i]);
        else printf("%d ", a[i]);
    }
    printf("%d\n", a[n-1]);

    return 0;
}

void swap(int *x, int *y) {
    int temp;
    temp = *x;
    *x = *y;
    *y = temp;
}

int partition(int a[], int p, int r){
    int i = p-1;        // p = 0
    int j;
    int key = a[r];     // r = n-1

    for (j = p; j < r; j++) {
        if(key >= a[j]) {
            i++;
            swap(&a[j], &a[i]);
        }
    }
    swap(&a[i+1], &a[r]);
    return i+1;
}

Measured memory_bytes: 992
#include <iostream>
#include <algorithm>
using namespace std;
 
int main() {
    long long n, a, b;
    cin >> n >> a >> b;
    long long ans = n / (a + b) * a;
    n %= (a + b);
    ans += min(n, a);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define F first
#define S second
#define pb push_back
mt19937 rnd;

#define div divi

const int mod = 998244353;

inline int add(int a, int b) {
    if (a + b >= mod) return a + b - mod;
    else return a + b;
}

inline int sub(int a, int b) {
    if (a - b < 0) return a - b + mod;
    else return a - b;
}

inline int mult(int a, int b) {
    return 1ll * a * b % mod;
}

inline int binpow(int a, int n) {
    int res = 1;
    while (n) {
        if (n & 1) {
            res = mult(res, a);
        }
        a = mult(a, a);
        n >>= 1;
    }
    return res;
}

inline int inv(int a) {
    return binpow(a, mod - 2);
}

inline int div(int a, int b) {
    return mult(a, inv(b));
}

const int N = 2e5 + 10;
int f[N];
int f_inv[N];

inline int C(int n, int k) {
    if (n < k) return 0;
    return mult(f[n], mult(f_inv[k], f_inv[n-k]));
}

void init() {
    f[0] = 1;
    for (int i = 1; i <= N - 1; i++) {
        f[i] = mult(f[i - 1], i);
    }
    f_inv[N - 1] = inv(f[N - 1]);
    for (int i = N - 2; i >= 0; i--) {
        f_inv[i] = mult(f_inv[i + 1], i + 1);
    }
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif

    init();
    int n, m, k;
    cin >> n >> m >> k;
    int ans = 0;
    for (int i = 0; i <= k; i++) {
        int cur = mult(C(n - 1, i), mult(m, binpow(m - 1, n - i - 1)));
        ans = add(ans, cur);
    }
    cout << ans << "\n";

#ifdef LOCAL
    cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    string s;
    getline(cin, s);
    rep(i, s.size()) if (s[i] == ',' || s[i] == '.') s[i] = ' ';
    stringstream ss(s);
    vector<string> ans;
    while (ss >> s)
        if (3 <= s.size() && s.size() <= 6)
            ans.push_back(s);

    rep(i, ans.size()) i != ans.size() - 1 ? cout << ans[i] << " " : OP(ans[i]);

    return 0;
}


Measured memory_bytes: 3148
import collections
n = int(input())
x = list(map(int, input().split()))

del x[n:]

# print(x)

now = float('inf')
new = 0

for i in range(100):
  new = 0
  for j in range(len(x)):
    new += (x[j] - (i + 1))** 2
  if new < now:
    now = new

print(now)


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

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef pair<LL, LL> PLL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())

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

#define FF first
#define SS second
template<class S, class T>
istream& operator>>(istream& is, pair<S,T>& p){
  return is >> p.FF >> p.SS;
}

const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL MOD = 1e9+7;

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

  int N, M; cin >> N >> M;
  VI xs(M);
  REP(i,M) cin >> xs[i];

  vector<bool> use(N+1);
  VI ans;
  for(int i=M-1;i>=0;--i)
	if(!use[xs[i]]){
	  use[xs[i]] = true;
	  ans.PB(xs[i]);
	}
  FOR(i,1,N+1)
	if(!use[i])
	  ans.PB(i);

  REP(i,N) cout << ans[i] << endl;
  
  return 0;
}

Measured memory_bytes: 4360
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <string>

using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)
#define repe(i,s,n)for(ll i = s;i<=n;i++)

ll a[2000010] = {};
ll sum[200010] = {};
int main() {
	ll N; cin >> N;

	ll s = 0;
	repe(i, 1, N) {
		cin >> a[i];
		sum[i] = a[i] + sum[i - 1];
		s += a[i];
	}

	ll minV = (ll)1 << 62;
	//repe(i, 1, N - 1) {
	//	ll x = sum[i];
	//	ll y = sum[N] - sum[i];
	//	minV = min(minV, abs(x - y));
	//}

	ll xsum = 0;
	repe(i, 1, N - 1) {
		xsum += a[i];
		minV = min(minV, abs(xsum * 2 - s));
	}
	cout << minV << endl;

	return 0;
}

Measured memory_bytes: 4352
#include <iostream>
#include <cmath>
#include <cfloat>
#include <iomanip>
using namespace std;
double f(double x, double q){
    return pow(x, 3.0) - q;
}

double df(double x){
    return 3.0 * pow(x, 2.0);
}

double newton(double x, double q){
    if(abs(f(x, q)) < 0.00001 * q){
        return x; 
    }
    return newton(x - f(x, q) / df(x), q);
}

int main(void){
    double q, x;
    while(cin >> q){
        if(q == -1) break;
        x = q / 2.0;
        cout << fixed << setprecision(6) << newton(x, q) << endl;
    }
    return 0;
}



Measured memory_bytes: 3340
import java.util.Scanner;

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

    char preC = s.charAt(0);
    int count = 0;
    for (char c : s.toCharArray()) {
      if (c != preC) {
        count += 1;
      }
      preC = c;
    }
    System.out.println(count);
  }
}


Measured memory_bytes: 25812
S = input()
T = input()
s_len = len(S)
t_len = len(T)
cnt = t_len
for idx in range(s_len - t_len + 1):
    # print(S[idx:idx+t_len],T)
    tmp_cnt = 0
    for in_idx in range(t_len):
        if T[in_idx] != S[idx + in_idx]:
            tmp_cnt += 1
    if tmp_cnt < cnt:
        cnt = tmp_cnt
print(cnt)


Measured memory_bytes: 9040
#include <stdio.h>

void selectionSort(int *,int);

int main(){
   int a[100],n,i;

  scanf("%d",&n);
  if(n < 1 || n > 100)return 0;
  
  for(i = 0; i < n; i++){
  scanf("%d",&a[i]);
  
  if(a[i] < 0 || a[i] > 100)return 0;
  }

  selectionSort(a,n);

  return 0;
}

void selectionSort(int a[], int n){
  int i,min,j,b,num = 0;

  for(i = 0;i < n-1; i++){
    min = i;
   for(j = i;j < n; j++){
    if(a[j] < a[min]){
      min = j;
     }
    }
   if(a[i] > a[min]){
    b = a[i];
      a[i] = a[min];
      a[min] = b;
      num++;
   }
  }

  for(j = 0; j < n; j++){
  printf("%d",a[j]);

  if(j != n-1)printf(" ");
  else printf("\n");
  }
  
  printf("%d\n",num);
  
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define maxn 500005
#define mod 1000000007
typedef pair<int,int> pii;
typedef map<int,int> mii;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<long long> vll;
typedef vector<bool> vb;
typedef set<int> si; 
#define fori(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i,b,a) for(int i = (b); i >= (a); --i)
#define all(a) (a).begin(), (a).end()
#define __builtin_popcountll bitCountLL
#define __builtin_popcount bitCount
//__builtin_ctz 末尾0的个数, __builtin_clz 前导0的个数
//__builtin_ffs 最后一个1的位置
const int INF = 2e9;
const ll ML = 4e18;
ll Pow(ll x, ll p) {
    ll res = 1;
    while(p) {
        if(p & 1) res = (res * x) % mod;
        p >>= 1;
        x = (x * x ) % mod;
    }
    return res;
}
ll fac[maxn], inv[maxn];
void init() {
    fac[0] = fac[1] = 1;
    fori(i,2,maxn) fac[i] = (fac[i-1] * i) % mod;
    inv[maxn-1] = Pow(fac[maxn-1],mod-2);
    rep(i,maxn-2,0) inv[i] = (inv[i+1] * (i + 1)) % mod;
}
ll C(int a, int b) {
    return (fac[b] * inv[a] % mod * inv[b - a] % mod) % mod;
}
ll A(int a, int b) {
    return fac[b] * inv[b-a] % mod;
}
void solve() {
    int n,m;
   cin >> n >> m;
   //cout << A(n,m);
    ll ans = 0, flag = 1;
    fori(i,0,n+1) {
        ans = (mod + ans + flag * (A(n-i,m-i) * C(i,n) % mod)) % mod;
        flag *= -1;
    }
    ans = ans * A(n,m) % mod;
    cout << ans << endl;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
	//cout.precision(30); cout << fixed;
	//freopen("D:\\data_in.txt", "r", stdin);
    init();
   solve();
    
    /*clock_t start,finish;
    start = clock();
   
    finish = clock();
    cout << "\n" << (double)(finish - start) / (double)(CLOCKS_PER_SEC) * 1000 << "ms" << endl;
    */
    return 0;
}

/***************************************************************
 question:
 idea:
 tag:
 record:
 ***************************************************************/


Measured memory_bytes: 11440
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n, m;
    cin >> n >> m;

    ll r = 1LL<<m, res = (1900 * m + (n - m) * 100) * r;
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
a,b,m=map(int,input().split())
als=list(map(int,input().split()))
bls=list(map(int,input().split()))
mls=[list(map(int,input().split())) for i in range(m)]

ans=min(als)+min(bls)
for i in mls:
    aidx = i[0]-1
    bidx = i[1]-1
    cost = als[aidx]+bls[bidx]-i[2]
    if cost < ans:
        ans = cost
print(ans)

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

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

template <typename T>
void print(const vector<T> &v) {
    for (auto e : v) cout << e << ' ';
    cout << endl;
}

//------------------------- Libraries -------------------------//

//--------------------------- Solve ---------------------------//

void solve() {
    int N; cin >> N;
    vector<int> L(N);
    for (int i = 0; i < N; i++) cin >> L[i];

    int ans = 0;
    for (int i = 0; i < N-2; i++) {
        for (int j = i+1; j < N-1; j++) {
            for (int k = j+1; k < N; k++) {
                if (L[i] != L[j] && L[j] != L[k] && L[k] != L[i]) {
                    vector<int> l(3);
                    l[0] = L[i];
                    l[1] = L[j];
                    l[2] = L[k];
                    sort(l.begin(), l.end());
                    if (l[2] < l[0] + l[1]) ans++;
                }
            }
        }
    }

    cout << ans << '\n';
}

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

    solve();

    return 0;
}

Measured memory_bytes: 3588
n = gets.to_i
num = gets.strip.split.map(&:to_i)
ary = Array.new(n,0)
ary[0] = num[0]
ary[n-1] = num[n-2]
i = 1
if n != 2
  while i < n-1 do
    ary[i] = [num[i-1],num[i]].min
    i += 1
  end
end
puts ary.sum

Measured memory_bytes: 14284
#include <iostream>
using namespace std;
typedef long long ll;
ll K,N,inf = 998244353;
ll func[4010] = {0};
ll inv[4010] = {0};

ll mult(ll n, ll m){
	if(n==0 || m==0) return 1;
	if(m==1) return n%inf;
	else if(m%2==0){
		ll t = mult(n,m/2);
		return (t*t)%inf;
	}else{
		ll t = mult(n,m-1);
		return (t*n)%inf;
	}
}

void factorial(ll N){
	for(ll i=0;i<=N;i++){
		if(i==0){
			func[i] = 1;
			inv[i] = 1;
		}
		else{
			func[i] = (i*func[i-1])%inf;
			inv[i] = mult(func[i],inf-2);
		}
	}
}

ll comb(ll n,ll k){
	if(n<k || n<0 || k<0) return 0;
	else return (((func[n]*inv[k])%inf)*inv[n-k])%inf;
}

ll hcomb(ll n,ll k){
	if(n==0 && k==0) return 1;
	return comb(n+k-1,k);
}

int main(){
	cin >> K >> N;
	factorial(4000);
	for(ll i=2;i<=2*K;i++){
		ll ans = 0;
		ll n = min(i,(2*K+2-i))/2;
		if(i%2==1){
			for(ll j=1;j<=n;j++){
				ans = (ans+(j%2==0? -1:1)*hcomb(K,N-2*j)*comb(n,j))%inf;
			}
		}else{
			for(ll j=1;j<=n;j++){
				ll t = hcomb(K,N-2*j);
				ans = (ans+(j%2==0? -1:1)*t*comb(n,j))%inf;
			}
		}
		ans = (hcomb(K,N)-ans)%inf;
		cout << (ans+inf)%inf << endl;
	}
}

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

using namespace std;

#define all(x) x.begin(), x.end()
typedef vector <int> vi;
typedef pair<int,int> ii;
typedef long long ll;

const int mod = 1e9 + 7;
const ll inf = 3e18 + 5;

ll dp[3005][3005][2];
int a[3005];

ll f(int i, int j, int t){
	if(i > j) return 0;
	if(dp[i][j][t] != -1) return dp[i][j][t];
	if(t == 0){ 
		return dp[i][j][t] = max(f(i + 1, j, !t) + a[i], f(i, j - 1, !t) + a[j]);
	}
	else return dp[i][j][t] = min(f(i + 1, j, !t) - a[i], f(i, j - 1, !t) - a[j]);
}

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

	int n;
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	memset(dp, -1, sizeof dp);
	cout << f(0, n - 1, 0);
}

Measured memory_bytes: 141568
S = input()
_S = list(S)
for s in range(len(_S)):
    if _S[s] != ('A'):
        if _S[s] != ('C'):
            if _S[s] != ('G'):
                if _S[s] != ('T'):
                    _S[s] = ','
s_changed = "".join(_S)
_s = s_changed.split(',')
most = 0
for v in _s:
    if len(v) >= most:
        most = len(v)
print(most)

Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>

#define INT_MAX 2147483647
#define INT_MIN -2147483648

int max(int a, int b);
int min(int a, int b);
int abs(int a);

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

	int flag = 0;
	for(int i = 1; i <= 9; i++) {
		if(n % i == 0) {
			if(n / i < 10) {
				flag = 1;
				break;
			}
		}
	}

	(flag) ? puts("Yes") : puts("No");
	return 0;
}

void swap(int *a, int *b) {
	int temp = *a;
	*a = *b;
	*b = temp;	
}

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

int min(int a, int b) {
	return (a < b) ? a : b;
}

int abs(int a) {
	return (a < 0) ? -a : a;
}


Measured memory_bytes: 1604
#include<cstdio>
#include<algorithm>
using namespace std;
#define MAXN 100010
#define LL long long
int n,Q,r;
LL q[MAXN],st[MAXN],a[MAXN],c[MAXN];
void Solve(LL x,LL y)
{
	int p=upper_bound(st,st+1+r,x)-st-1;
	if(!p) a[1]+=y,a[x+1]-=y;
	else c[p]+=y*(x/st[p]),Solve(x%st[p],y);
}
int main()
{
	scanf("%d%d",&n,&Q);
	if(Q==0)
	{
		for(int i=1;i<=n;i++)
			printf("1\n");
		return 0;
	}
	for(int i=1;i<=Q;i++)
		scanf("%lld",&q[i]);
	st[++r]=q[Q];
	q[0]=n;
	for(int i=Q-1;i>=0;i--)
		if(st[r]>q[i])
			st[++r]=q[i];
	for(int i=1;i<r-i+1;i++)
		swap(st[i],st[r-i+1]);
	c[r]=1;
	for(int i=r;i>1;i--)
	{
		c[i-1]+=c[i]*(st[i]/st[i-1]);
		Solve(st[i]%st[i-1],c[i]);
	}
	for(int i=1;i<=n;i++)
		a[i]+=a[i-1];
	for(int i=1;i<=st[1];i++)
		a[i]+=c[1];
	for(int i=1;i<=n;i++)
		printf("%lld\n",a[i]);
}

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

ll GCD(ll a, ll b)
{
	if (b == 0) return a;
	else return GCD(b, a%b);
}


int main(int argc, char **argv)
{
	ll N, M; cin >> N >> M;
	string S, T; cin >> S >> T;

	
	bool flag{true};
	ll g = GCD(N, M);
	ll res = M / g * N;
	ll m = M / g;
	ll n = N / g;
	for (ll i = 0; i < g; ++i)
	{
		if (S[i*n] != T[i*m]) flag = false;
	}

	std::cout << (flag ? res : -1) << std::endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a;
  cin >> a;
  string s;
  cin >> s;
  if(a>=3200){
  	cout << s << endl;
  }else{
  	cout << "red" << endl;
  }
  
  
  
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)
#define all(x) (x).begin(), (x).end()

int main()
{
    int a, b;
    cin >> a >> b;
    cout << max(max(a * 2 - 1, b * 2 - 1), a + b) << endl;
    return 0;
}

Measured memory_bytes: 256
def selectionSort(A, N):
    cnum = 0
    for i in range(0, N):
        minj = i
        for j in range(i, N):
            if A[j] < A[minj]:
                minj = j
        if i != minj:
            tmp = A[i]
            A[i] = A[minj]
            A[minj] = tmp
            cnum += 1
    print " ".join(str(t) for t in A)
    print cnum

if __name__ == "__main__":
    N = input()
    A = map(int, raw_input().split())
    selectionSort(A, N)

Measured memory_bytes: 6336
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <functional>
#include <utility>
#include <queue>
#include <vector>
#include <string>
#include <stack>
#define rep(i,n) for(ll i=0;i<n;i++)
using namespace std;
typedef long long int ll;
const ll  MOD = 1000000007;
typedef pair<ll,ll> P;

int main(){
  ll X,Y;
  cin >> X >> Y;
  if(abs(X-Y) >= 2){
    cout << "Alice" << endl;
  }
  else{
    cout << "Brown" << endl;
  }
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep0(i, n) for (long long i = 0; i < (long long)(n); i++)
#define rep1(i,n) for(long long i=1;i<=(long long)(n);i++)
#define all(v) v.begin(),v.end()
#define Sort(v) sort(all(v))
#define Reverse(v) reverse(all(v))
#define Rsort(v) sort(all(v),greater)
#define pub(v) push_back(v)
#define pob(v) pop_back(v)
typedef long long ll;
typedef vector<ll> vel;
typedef vector<vector<ll>> vel2d;
typedef string str;
typedef pair<ll,ll> pal;
typedef vector<str> ves;
typedef vector<char> vech;


int main() {
    str S;cin>>S;
    map<char,ll> data;
    ll n=S.size();
    rep0(i,n){
        data[S[i]]++;
    }
    bool flag=false;
    rep0(i,26){
        if(data.count((char)('a'+i))&&data['a'+i]%2!=0){flag=true;}
    }
    if(flag){cout<<"No"<<endl;}
    else{cout<<"Yes"<<endl;}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define Graph vector<vector<int>>
typedef long long ll;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int inf=1000000000; //10^9

int main(){
    int N;cin>>N;
    vector<int>X(N);
    rep(i,N)cin>>X[i];

    int ans=inf;
    for(int i=1;i<101;i++){
        int count=0;
        rep(j,N){
            count+=(X[j]-i)*(X[j]-i);
        }
        chmin(ans,count);
    }
    cout<<ans;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <cstdlib>
#include <bitset>
#include <tuple>
#include <assert.h>
#include <deque>
#include <bitset>
#include <iomanip>
#include <limits>
#include <chrono>
#include <random>
#include <array>
#include <unordered_map>
#include <functional>
#include <complex>

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

constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int inf = 1 << 28;
constexpr long long mod = 1000000007LL;
//constexpr long long mod = 998244353LL;

using namespace std;
typedef unsigned long long ull;
typedef long long ll;


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

	ll n, kkt; scanf("%lld %lld", &n, &kkt);
	ll now = 0;
	for (int i = 0; i < n - 1; i++) now = now + 1 + now / (kkt - 1);
	cout << now << endl;
	return 0;

}


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

int main(){
    double a, b, x;
    cin >> a >> b >> x;
    if(a * a * b / 2.0 <= x){
        double c = 2 * b - (2 * x / (a * a));
        printf("%.10f\n", atan(c / a) / M_PI * 180.0);
    }
    else{
        double c = 2.0 * x / (a * b);
        printf("%.10f\n", atan(b / c) / M_PI * 180.0);
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using pii = pair<int, int>;
 
 
vector<ll> x, y;
vector<pair<ll, ll>> ps1, ps2;
set<pair<ll, ll>> s1, s2;
map<pair<ll, ll>, int> idx;
vector<bool> vis;
 
ll calc(int i, int type, pair<ll, ll> l, pair<ll, ll> r, queue<int>& que) {
    ll res = 0;
    auto& ps = (type == 0 ? ps1 : ps2);
    auto& t1 = (type == 0 ? s1 : s2);
    auto& t2 = (type == 1 ? s2 : s1);
    res += upper_bound(ps.begin(), ps.end(), r) - lower_bound(ps.begin(), ps.end(), l);
    auto first = t1.lower_bound(l), last = t1.upper_bound(r);
    vector<pair<ll, ll>> remove_p;
    for(auto it = first; it != last; ++it) {
        auto rev_p = make_pair(it->second, it->first);
        int id = (type == 0 ? idx[*it] : idx[rev_p]);
        if(!vis[id]) {
            vis[id] = true;
            remove_p.emplace_back(it->second, it->first);
            que.push(id);
        }
    }
    t1.erase(first, last);
    for(auto& p : remove_p) {
        t2.erase(p);
    }
 
    return res;
}
 
int main() {
    int N, a, b;
    cin >> N >> a >> b;
    a--; b--;
    x.resize(N), y.resize(N);
    ps1.resize(N), ps2.resize(N);
    vis.resize(N);
    for(int i = 0; i < N; ++i) {
        cin >> x[i] >> y[i];
        ll xx = x[i] - y[i];
        ll yy = x[i] + y[i];
        x[i] = xx;
        y[i] = yy;
        ps1[i] = make_pair(xx, yy);
        ps2[i] = make_pair(yy, xx);
        s1.insert(ps1[i]);
        s2.insert(ps2[i]);
        idx[make_pair(xx, yy)] = i;
    }
    sort(ps1.begin(), ps1.end());
    sort(ps2.begin(), ps2.end());
 
    ll const D = max(abs(x[a] - x[b]), abs(y[a] - y[b]));
    vis[a] = true;
    s1.erase(make_pair(x[a], y[a]));
    s2.erase(make_pair(x[a], y[a]));
    queue<int> que;
    que.push(a);
    ll res = 0;
    while(!que.empty()) {
        auto p = que.front();
        que.pop();
        ll cur_x = x[p], cur_y = y[p];
        ll corner = idx.count(make_pair(cur_x + D, cur_y + D));
        corner += idx.count(make_pair(cur_x + D, cur_y - D));
        corner += idx.count(make_pair(cur_x - D, cur_y + D));
        corner += idx.count(make_pair(cur_x - D, cur_y - D));
 
        auto upper_left = make_pair(cur_x - D, cur_y + D);
        auto upper_right = make_pair(cur_x + D, cur_y + D);
        auto lower_left = make_pair(cur_x - D, cur_y - D);
        auto lower_right = make_pair(cur_x + D, cur_y - D);
 
        res += calc(p, 0, lower_right, upper_right, que); // right side
        res += calc(p, 0, lower_left, upper_left, que);   // left side
 
        swap(upper_left.first, upper_left.second);
        swap(upper_right.first, upper_right.second);
        swap(lower_left.first, lower_left.second);
        swap(lower_right.first, lower_right.second);
 
        res += calc(p, 1, upper_left, upper_right, que);  // upper side
        res += calc(p, 1, lower_left, lower_right, que);  // lower side
 
        res -= corner;
    }
 
    cout << res / 2 << endl;
}


Measured memory_bytes: 25456
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cmath>
#include<queue>
#define int long long
#define mod 1000000007
#define for0(i, n) for(int i = 0; i < (n); i++)
#define for1(i, n) for(int i = 1; i <= (n);i++)
#define mp make_pair
using namespace std;
int ans[567890], p;
signed main() {
	string s; cin >> s;
	p = 0; ans[0] = 0;
	while (s[p] == '<') {
		p++; ans[p] = p;
	}
	p = s.size(); p--;
	while (s[p] == '>') {
		ans[p] = ans[p + 1] + 1; p--;
	}
	for0(i, s.size() - 1) {
		if (s[i] == '>'&&s[i + 1] == '<') {
			ans[i + 1] = 0;
			p = i;
			while (s[p] == '>') {
				ans[p] = max(ans[p], ans[p + 1] + 1); p--;
			}
			p = i + 1;
			while (p < s.size() && s[p] == '<') {
				p++; ans[p] = max(ans[p], ans[p - 1] + 1);
			}
			i = p - 1;
		}
	}
	int cnt = 0;
	for0(i, s.size() + 1)cnt += ans[i]; cout << cnt << endl;
}

Measured memory_bytes: 4996
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define pi (double) acos(-1)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
using namespace std;
 
int main() {
    string s;
    cin >> s;
    int ans=10000;
    for(int i = 0; i < s.size()-2; i++){
        ans = min(ans, abs(753-atoi(s.substr(i,3).c_str())));
    }
    cout << ans;
}

Measured memory_bytes: 256
from collections import deque
n=int(input())
v=tuple(tuple(map(lambda x: int(x)-1,input().split())) for _ in range(n-1))

node=[{} for _ in range(n)]
d=deque()
ans= [-1] * n
ans[0]=0
d.append(0)
for pair in v:
    node[pair[0]][pair[1]]=pair[2]
    node[pair[1]][pair[0]]=pair[2]
    
while True:
    if not d:
        break
    i=d.pop()
    for k in node[i].keys():
        if ans[k]!=-1:
          continue
        d.append(k)
        if node[i][k]%2==1:
            ans[k]=ans[i]
        else:
            ans[k]=1-ans[i]
print(*ans)

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

ll dp[101010];

int main() {
    int n;
    cin >> n;

    vector<ll> h(n);
    rep(i, n) cin >> h[i];

    fill(dp, dp+n, 1e10);
    dp[0] = 0;
    for (int i=1; i<n; ++i) {
        if (i-1 >= 0) dp[i] = min(dp[i], dp[i-1] + abs(h[i] - h[i-1]));
        if (i-2 >= 0) dp[i] = min(dp[i], dp[i-2] + abs(h[i] - h[i-2]));
    }

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


Measured memory_bytes: 1792
n = int(input())
s = [int(input()) for i in range(n)]
list.sort(s , reverse = True)
t = sum(s)

if t % 10 != 0:
    print(t)
else:
    i = -1
    j = True
    while j:
        if s[i] % 10 == 0:
            i -= 1
            if abs(i) > n:
                print(0)
                j = False
        else:
            print(t - s[i])
            j = False

Measured memory_bytes: 3064
const main = (input: string) => {
  const [A, B, K] = input.split(" ").map(str => parseInt(str))
  let divisorList = [];
  const largeNum  = Math.max(A, B)

  for (let i = 1; i <= largeNum; i++) {
    if(A % i === 0 && B % i === 0) {
      divisorList.push(i)
    }
  }

  const answer = divisorList.reverse();
  console.log(answer[K - 1])
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));


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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    string s; cin >> s;
    vector<int> v;
    bool all_even = true;
    for (int i = 0; i < n-1; i++) {
        v.emplace_back(abs(s[i]-s[i+1]));
        if (v.back() % 2 == 1) all_even = false;
    }
    vector<int> d(n+1, 0);
    for (int k = 1; (1 << k) <= n; k++) {
        int c = 1 << k;
        for (int i = c; i <= n; i += c) d[i]++;
    }
    int ans = 0; int two_cnt = 0;
    for (int i = 0; i < n-1; i++) {
        if (!all_even && v[i] == 2) v[i] = 0;
        if (two_cnt == 0) ans ^= v[i];
        //cout << " " << two_cnt << " " << v[i] << "\n";
        two_cnt += d[n-2-i] - d[i+1];
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 10132
#define _LIBCPP_DEBUG 0
#include <bits/stdc++.h>
using namespace std;

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

    swap(a, b); swap(a, c);
    cout << a << " " << b << " " << c << endl;

    return 0;
}

Measured memory_bytes: 256
n = int(input())
lst = list(map(int, input().split()))

count = 0
index = 0
while True:
    flag = True
    for i in range(n-1, index, -1):
        if lst[i] < lst[i-1]:
            count += 1
            lst[i],lst[i-1] = lst[i-1],lst[i]
            flag = False
    index += 1
    if flag:
        break

print(*lst)
print(count)



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

int main() {
	ll v[4], N;
	cin >> v[0] >> v[1] >> v[2] >> v[3] >> N;

	ll cost1 = min(4 * v[0], min(2 * v[1], v[2]));
	ll cost2 = min(cost1 * 2, v[3]);

	if (N < 2) {
		cout << cost1 << endl;
	} else {
		ll res = (N/2) * cost2;
		if (N%2 == 1) res += cost1;

		cout << res << endl;
	}

	return 0;
}


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int main() {
    //cout.precision(10);
    int M;
    cin >> M;
    cout << 48 - M << endl;
    return 0;
}


Measured memory_bytes: 256