akhauriyash/Code-Regression huggingface dataset:
n, m, q = map(int, input().split())
queries = [tuple(map(int, input().split())) for _ in range(q)]

def calc_score(p):
    score = 0
    for a, b, c, d in queries:
        if p[b-1] - p[a-1] == c:
            score += d
    return score

def f(p):
    if len(p) == n:
        return calc_score(p)
    ans = 0
    l = p[-1] if len(p) else 1
    for x in range(l, m+1):
        p.append(x)
        ans = max(ans, f(p))
        p.pop()
    return ans

print(f([]))


Measured memory_bytes: 9144
while 1:
	n = input()
	if n == 0: break
	xy = [map(int,raw_input().split()) for i in range(n)]
	S = set(map(tuple,xy))
	ans = 0
	for i in range(n-1):
		x1,y1 = xy[i]
		for j in range(i+1,n):
			x2,y2 = xy[j]
			a = (x2-y2+y1,y2+x2-x1)
			b = (x1-y2+y1,y1+x2-x1)
			if a in S and b in S:
				ans = max(ans,(x1-x2)**2 + (y1-y2)**2)
	print ans

Measured memory_bytes: 5784
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rea(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())
#define PRINT(V) for (auto v:(V)) {cerr << v << " ";} cerr << endl
#define dump(x) cerr << #x << " : " << (x) << endl
#define dump2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl
inline ll GCD(ll a, ll b){return b ? GCD(b, a % b) : a;}
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
/* END OF TEMPLATE */

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    string s;
    cin >> s;
    char stemp = s[0];
    ll ans = 0;
    rep(i, s.size()){
        if(s[i] != stemp){
            ans++;
            stemp = s[i];
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
import java.util.*;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] V = new int[N];
		int[] C = new int[N];
		int[] ans = new int[N];
		for (int i=0;i<N;i++) {
			V[i]=sc.nextInt();
		}
		for (int i=0;i<N;i++) {
			C[i]=sc.nextInt();
		}
		for (int i=0;i<N;i++) {
			ans[i]=Math.max(0,V[i]-C[i]);
		}
		int sum=0;
		for (int i=0;i<N;i++) {
			sum+=ans[i];
		}
		System.out.println(sum);
	}
}

Measured memory_bytes: 21844
nums = [int(x) for x in input().split()]

pic = []
for i in range(nums[0]):
	line = input()
	pic.append(line)

for i in range(nums[1]+2):
	print("#", end="")
print("\n", end="")
for words in pic:
	print("#", end="")
	print(words, end="")
	print("#")

for i in range(nums[1]+2):
	print("#", end="")
print("\n", end="")

Measured memory_bytes: 3064
from itertools import product as pro

n = int(input())
xy = []
for i in range(n):
    a_i = int(input())
    xy.append([tuple(map(int, input().split())) for _ in range(a_i)])

ans = 0
for l in pro([0, 1], repeat=n):
    for i, t in enumerate(l):
        if t == 1:
            if not all(l[x-1] == y for x, y in xy[i]):
                break
    else:
        ans = max(ans, sum(l))

print(ans)

Measured memory_bytes: 3064
def gcd(x,y):
    while y>0:
        x,y = y,x%y
    return x
N = int(input())
T = [int(input()) for _ in range(N)]
a = T[0]
for i in range(1,N):
    b = T[i]
    c = gcd(a,b)
    a = (a//c)*b
print(a)

Measured memory_bytes: 62420
import std.algorithm;
import std.bigint;
import std.bitmanip;
import std.concurrency;
import std.container;
import std.conv;
import std.functional;
import std.format;
import std.math;
import std.meta;
import std.numeric;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.traits;
import std.typecons;


auto solve(long A, long B) {
    return A < 10 && B < 10 ? A * B : -1;
}


void main() {
    auto input = stdin.byLine.map!split.joiner;

    long A;
    A = input.front.to!long;
    input.popFront;

    long B;
    B = input.front.to!long;
    input.popFront;

    static if (is(ReturnType!solve == void))
        solve(A, B);
    else {
        auto ans = solve(A, B);

        static if (isFloatingPoint!(ReturnType!solve))
            writeln(format("%.9f", ans));
        else static if (is(ReturnType!solve == bool))
            writeln(ans ? YES : NO);
        else
            writeln(ans);
    }
}


Measured memory_bytes: 256
// यथा चतुर्भिः कनकं परीक्ष्यते निघर्षणच्छेदनतापताडनैः।
// तथा चतुर्भिः पुरुषः परीक्ष्यते त्यागेन शीलेन गुणेन कर्मणा॥
#include <bits/stdc++.h>
using namespace std;
#define lld long long int
#define M 1000000007
#define fors(i,n) for(int i=0;i<n;++i)
#define fore(i,a,b) for(int i=a;i<=b;++i)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define vv std::vector<int>
#define mapii std::map<int,int>
#define mpaci std::map<char,int>
#define umapii std::unordered_map<int,int>
#define umapci std::unordered_map<char,int>
#define seti std::set<int>
#define useti std::unordered_set<int>
#define qi std::queue<int>
#define qc std::queue<char>
#define sti std::stack<int>
#define stc std::stack<char>
#define endl "\n"
#define test(i) cout<<i<<endl
#define tests(i) cout<<"i: "<<i<<endl;
#define itrt int t; cin>>t; fors(i,t)
#define itr1 int t; cin>>t;
#define ff first
#define ss second
#define pb push_back
#define vmp make_pair
#define ppb pop_back
#define sorta(a,n) sort(arr,arr+n)
#define sortv(x) sort(x.begin(),x.end())
#define all(x) x.begin(),x.end() 
#define printv(v) for(auto x: v){ cout<< x << " ";}
#define pi 3.14159265358979323846
#define setprc(x) setprecision(x)
void file(){
    #ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
}
bool sortdesk(const pair<int,int> &a, const pair<int,int> &b){return a.ff>b.ff;}
bool sortdesv(const pair<int,int> &a, const pair<int,int> &b){return a.ss>b.ss;}
bool sortascv(const pair<int,int> &a, const pair<int,int> &b){return a.ss<b.ss;}
bool sortasck(const pair<int,int> &a, const pair<int,int> &b){return a.ff<b.ff;}
bool is_prime(int n){if(n==1){return false;}int i=2;while(i*i<=n){if(n%i==0){return false;}i+=1;}return true;}
int gcd(int a, int b){if (b == 0){return a;} return gcd(b, a % b);}
int cntdiv(int n){int cnt=0;for(int i=1;i<=sqrt(n);++i){if(n%i==0){if(n/i==i)++cnt;else{cnt = cnt + 2;}}}return cnt;}
lld posnegmod(lld x,lld mod){return (x%mod+mod)%mod;}
// cout<<fixed<<setprecision(20)
// lld fact(lld n);
// lld nCr(lld n,lld r){return fact(n) / (fact(r) * fact(n - r));}
// lld fact(lld n){ lld res = 1; for(lld i = 2; i <= n; i++){res = res * i;}return res;} 
// const int maxi = 1e6+10;
// vector<int> v[maxi];
// vector<long long> a(maxi,0);
// void dfs(int x){
//     if(a[x]){return;}
//     a[x]=1;
//     for(int i=0;i<v[x].size();++i){
//         dfs(v[x][i]);
//     }
// }

void test_case(){
    int n;
    cin>>n;
    lld sum=0;
    vector<lld> v(n);
    fors(i,n){
        cin>>v[i];
    }
    sortv(v);
    reverse(all(v));
    lld mini =v[0];
    for(int i=1;i<n;++i){
        sum+=v[i/2];
    }
    cout<<sum;
}

int main(){
    fastio;
    file();
    int T=1;
    // int T;
    // cin>>T;
    for(int nr=1;nr<=T;++nr) {
        // cout<<"Case #"<<nr<<": ";
        test_case();
    }
}


Measured memory_bytes: 4704
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr double eps = 1e-9;
constexpr ll MOD = 1000000007LL;
template <typename T> bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T> ostream &operator<<(ostream &os, vector<T> v) {
    for (int i = 0; i < v.size(); i++) {
        os << v[i] << (i + 1 == v.size() ? "\n" : " ");
    }
    return os;
}
template <typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) {
    t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) {
    for (auto &e : t) {
        fill_v(e, v);
    }
};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, k;
    cin >> n >> k;
    k *= n;
    vector<ll> a(n);
    vector<vector<ll>> v(200010);
    vector<int> t(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        v[a[i]].push_back(i);
        t[i] = v[a[i]].size();
        t[i]--;
    }
    int id = 0;
    ll st, cy;
    vector<int> vis(n), vs;
    vector<ll> lo(n);
    vis[0] = 1;
    vs.push_back(0);
    lo[0] = 0;
    while (1) {
        ll c = 0;
        int to = v[a[id]][(t[id] + 1) % v[a[id]].size()] + 1;
        // cout << id << " " << to << endl;
        if ((t[id] + 1) % v[a[id]].size() == 0) {
            c += n - id;
            c += to;
        } else {
            c += to - id;
        }
        to %= n;
        if (vis[to]) {
            st = lo[to];
            cy = lo[id] + c - st;
            break;
        }
        vis[to] = 1;
        vs.push_back(to);
        lo[to] = lo[id] + c;
        id = to;
    }
    //  cout << st << " " << cy << endl;
    int idx;
    if (k >= st) {
        k -= st;
        k %= cy;
        k += st;
    }
    for (int i = 0; i < vs.size(); i++) {
        if (lo[vs[i]] > k) {
            idx = vs[i - 1];
            k -= lo[vs[i - 1]];
            break;
        }
    }
    // cout << idx << " " << k << endl;
    vector<int> s;
    set<int> ss;
    while (k--) {
        if (ss.count(a[idx])) {
            while (s.back() != a[idx]) {
                ss.erase(ss.find(s.back()));
                s.pop_back();
            }
            ss.erase(ss.find(s.back()));
            s.pop_back();
        } else {
            s.push_back(a[idx]);
            ss.insert(a[idx]);
        }
        idx++;
        idx %= n;
    }
    cout << s;
}


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

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                Solve.Answer();
            }
            catch (Exception ex)
            {
                WriteLine(ex.ToString());
            }
        }
    }

    public class Solve
    {
        public static void Answer()
        {
            var L = IO_ShortCut.ReadDouble;
            var L3 = (double)L / 3;

            WriteLine(L3 * L3 * L3);
        }
    }

    public class IO_ShortCut
    {
        #region Input
        public static string ReadString => ReadLine();
        public static int ReadInt => int.Parse(ReadLine());
        public static long ReadLong => long.Parse(ReadLine());
        public static double ReadDouble => double.Parse(ReadLine());

        public static List<string> ReadSplitString => ReadLine().Split().ToList();
        public static List<int> ReadSplitInt => ReadLine().Split().Select(s => int.Parse(s)).ToList();
        public static List<long> ReadSplitLong => ReadLine().Split().Select(s => long.Parse(s)).ToList();
        public static List<double> ReadSplitdouble => ReadLine().Split().Select(s => double.Parse(s)).ToList();
        #endregion

        #region Output
        public static void OutJoinSpace<T>(IEnumerable<T> list) => WriteLine(string.Join(" ", list));
        public static void WriteLineYes_or_No(bool flag) => WriteLine(flag ? "Yes" : "No");

        #endregion
    }

    /// <summary>
    /// 正の数の四則演算のみ対応
    /// </summary>
    public class Mod
    {
        // 割る数の定義
        private readonly static long M = 1000000007;

        // 足し算
        public static long Add(long a, long b) => (a * b) % M;
        // 引き算
        public static long Sub(long a, long b) => (a - b) % M >= 0 ? (a - b) % M : (a - b) % M + M;
        // 掛け算
        public static long Multi(long a, long b) => (a * b) % M;
    }

    public class MathLib
    {
        public static int Cmb(int n, int k)
        {
            var a = 1;
            for (int i = 0; i < k; i++)
            {
                a *= n;
                n--;
            }
            return k == 0 ? 1 : a / k;
        }
    }
}

Measured memory_bytes: 11220
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using namespace std;

int uf[101010];

int find(int u) {
  if (uf[u] < 0) return u;
  return uf[u] = find(uf[u]);
}

void unite(int u, int v) {
  u = find(u);
  v = find(v);
  if (u == v) return;
  if (uf[u] > uf[v]) swap(u, v);
  uf[u] += uf[v];
  uf[v] = u;
}

int main() {
  int n, m;
  cin >> n >> m;
  for (int i = 0; i < n; i++) uf[i] = -1;

  vector<int> p(n);
  for (int i = 0; i < n; i++) {
    cin >> p[i];
    p[i]--;
  }
  for (int i = 0; i < m; i++) {
    int x, y;
    cin >> x >> y;
    x--;
    y--;
    unite(x, y);
  }

  int ans = 0;
  for (int i = 0; i < n; i++) {
    if (find(p[i]) == find(i)) {
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;
using namespace std;


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

    vector<int> a(n);
    int i;
    for(i=0; i<n; i++) {
        scanf("%d", &a[i]);
    }
    int curr=0;
    for(i=0; i<n; i++) {
        if(a[i]==curr+1) curr++;
    }
    if(curr>0) {
        printf("%d\n", n-curr);
    }
    else {
        printf("-1\n");
    }

    return 0;
}

Measured memory_bytes: 1024
/*
 _    _    _______   _    _
| |  / /  |  _____| | |  / /
| | / /   | |       | | / /
| |/ /    | |_____  | |/ /
| |\ \    |  _____| | |\ \
| | \ \   | |       | | \ \
| |  \ \  | |_____  | |  \ \
|_|   \_\ |_______| |_|   \_\

*/
#include <bits/stdc++.h>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef pair <int, int> PII;
typedef pair <ll, ll> PLL;

#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define right(x) x << 1 | 1
#define left(x) x << 1
#define forn(x, a, b) for (int x = a; x <= b; ++x)
#define for1(x, a, b) for (int x = a; x >= b; --x)
#define mkp make_pair
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end()
#define y1 kekekek

const ll ool = 1e18 + 9;
const int oo = 1e9 + 9, base = 1e9 + 7;
const ld eps = 1e-7;
const int N = 2e6 + 6;

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

	int n, K, mx = 0, g = 0;
    cin >> n >> K;
    forn(i, 1, n) {
        int x;
        cin >> x;
        if (i == 1) g = x;
        else g = __gcd(g, x);
        mx = max(mx, x);
    }

    if (K > mx || K % g != 0) cout << "IMPOSSIBLE\n";
    else cout << "POSSIBLE\n";

	return 0;
}


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

using ll = long long;

#define for_(i,a,b) for(int i = (a);i < (b);i++)
#define rfor_(i,a,b) for(int i = (b)-1;i >= (a);i--)
#define rep(i,n) for_(i,0,(n))
#define rrep(i,n) rfor_(i,0,(n))

using di = deque<int>;

di a;

int q;

int main(){
	cin.tie(0);
	
	cin>>q;
	rep(i, q) {
		int c, x, y;
		cin>>c;
		if(c==0) {
			cin>>x>>y;
			if(x==0)a.push_front(y);
			else a.push_back(y);
		}else if(c==1) {
			cin>>x;
			cout<<a[x]<<endl;
		}else {
			cin>>x;
			if(x==0)a.pop_front();
			else a.pop_back();
		}
	}

	return 0;
}



Measured memory_bytes: 4564
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

/* --------------------------------------------------- */

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

    vector<int> dp(n + 1);
    dp[0] = 0;
    dp[1] = abs(h[1] - h[0]);
    forr(i, 2, n) {
        dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
    }
    cout << dp[n - 1] << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<iomanip>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>

#define rep(i,p) for(int i=1;i<=p;i++)
#define ll long long

using namespace std;

int main(){

 ll int N;
 cin >> N;

 ll int P[N+1];
 rep(i,N){
	 cin >> P[i];
 }

 ll int ans;
 ans =0;
 ll int  max;
 max = P[1];
 rep(i,N){
   if(max >= P[i]){
	   ans += 1;
	   max = P[i];
   }
 }
 cout << ans;










	return 0;

}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;


ll a[200010], b[200010];

int main(){
    int n;
    cin >> n;
    rep(i, n){
        cin >> a[i] >> b[i];
        a[i] *= 2;
        b[i] *= 2;
    }

    sort(a, a+n);
    sort(b, b+n);

    ll medl, medr, ans;

    if (n%2 == 0){
        medl = (a[n/2-1] + a[n/2]) / 2;
        medr = (b[n/2-1] + b[n/2]) / 2;
        ans = medr - medl + 1;
    }
    else{
        medl = a[(n-1)/2];
        medr = b[(n-1)/2];
        ans = (medr - medl)/2 + 1;
    }


    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 6692
#include <bits/stdc++.h>
#define N 100010
using namespace std;
int main(){
	int n,d,i,a,b;
	vector<int> p;
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>d;
		p.push_back(d);
	}
	if(n%2==1)
	{
		cout<<0<<endl;
		return 0;
	}
	sort(p.begin(),p.end());
	a=p[n/2-1];
	b=p[n/2];
	cout<<b-a<<endl;
	return 0;
}

Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
#define fi first
#define se second
#define pb push_back
#define forn(i,n) for(int i=0;i<(n);i++)
#define for1(i,n) for(int i=1;i<=n;i++)
#define forr(i,n) for(int i=n;i>=0;i--)
#define all(x) x.begin(), x.end()
const int MAXN = 1e5 +5;

void fio(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
}
 LL cnt[3];
int main(){
  fio();
  int n; cin>>n;

  string s; cin>>s;

  for(auto i:s){
  	if(i=='R') cnt[1]++;
  	if(i=='G') cnt[2]++;
  	if(i=='B') cnt[0]++;
  }
  LL an = (cnt[1]*cnt[2]*cnt[0]);
//  cout<<an<<endl;
  for(int i=0;i<=(n-3);i++){
  	for(int j=i+2;j<n;j+=2){
  		if(s[i]!=s[j] && s[(i+j)/2]!=s[i] && s[(i+j)/2]!=s[j] ){
  			an--;
  		}
  	}
  }
  cout<<an<<endl;
  return 0;
}

Measured memory_bytes: 3624
import math
A, B, H, M = map(int, input().split())

m = math.pi * 2 * M / 60
h = math.pi * 2 * (H * 60 + M) / (12 * 60)

kakudo = abs(m - h)
if kakudo > math.pi:
    kakudo = 2 * math.pi - kakudo

s = A ** 2 + B ** 2 - (2 * A * B) * math.cos(kakudo)
print(math.sqrt(s))

Measured memory_bytes: 9512
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << "\n\n"
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      cout << '\n';
  }
  return s;
}

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

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

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

signed main() {
  int M;
  cin >> M;
  vector<ll> d(M), c(M);
  rep(i, M) {
    cin >> d[i] >> c[i];
  }

  ll D = 0;
  ll S = 0;
  rep(i, M) {
    D += c[i];
    S += d[i] * c[i];
  }

  ll ans = (D - 1) + (S - 1) / 9;
  cout << ans << "\n";
}

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

using namespace std;

using i64 = long long;

const i64 MOD = 1e9 + 7;
const i64 INF = i64(1e18) + 7;


template <typename T>
bool chmin(T& x, T y){
    if(x > y){
        x = y;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T& x, T y){
    if(x < y){
        x = y;
        return true;
    }
    return false;
}


template <typename T>
// T f(T, T): 子の累積に使うもの 直径ならf(x, y): max(x, y)
// T g(T, int): 子の累積を元に適用する際に使うもの 直径ならg(x, idx): x + 1
vector<T> rerooting(vector<vector<int>>& edges, vector<T> v, function<T(T, T)> f, function<T(T, int)> g, T op){
    int n = edges.size();
    vector<int> visit(n, 0);
    vector<T> dp1(v), dp2(n);
    vector<vector<int>> childs(n);
    vector<vector<T>> child_val(n), child_l(n), child_r(n);
    function<void(int)> f1 = [&](int x){
        visit[x] = true;
        T res = op;
        for(auto y : edges[x]){
            if(visit[y])
                continue;
            f1(y);
            childs[x].push_back(y);
            child_val[x].push_back(dp1[y]);
            res = f(res, dp1[y]);
        }
        dp1[x] = g(res, x);
        child_l[x].push_back(op);
        child_r[x].push_back(op);
        for(int i = 0; i < childs[x].size(); ++i){
            child_l[x].push_back(f(child_l[x].back(), child_val[x][i]));
            child_r[x].push_back(f(child_r[x].back(), child_val[x][childs[x].size() - i - 1]));
        }
    };
    f1(0);
    function<void(int, T)> f2 = [&](int x, T par_val){
        T res = par_val;
        for(int i = 0; i < childs[x].size(); ++i){
            int y = childs[x][i];
            auto p = f(par_val, f(child_l[x][i], child_r[x][childs[x].size() - i - 1]));
            T val = g(f(par_val, f(child_l[x][i], child_r[x][childs[x].size() - i - 1])), y);
            res = f(res, dp1[y]);
            f2(y, val);
        }
        dp2[x] = g(res, x);
    };
    f2(0, op);
    return dp2;
};

signed main(){
    int n;
    cin >> n;
    vector<int> a(n - 1), b(n - 1), c(n - 1);
    vector<vector<int>> edges(2 * n - 1);
    vector<int> v(2 * n - 1, 0);
    for(int i = 0; i < n - 1; ++i){
        cin >> a[i] >> b[i] >> c[i];
        edges[a[i]].emplace_back(n + i);
        edges[n + i].emplace_back(b[i]);
        edges[b[i]].emplace_back(n + i);
        edges[n + i].emplace_back(a[i]);
        v[i + n] = c[i];
    }

    function<int(int,int)> f = [&](int x, int y){return max(x, y);};
    function<int(int,int)> g = [&](int x, int idx){return x + v[idx];};

    auto res = rerooting(edges, v, f, g, 0);
    cout << *max_element(res.begin(), next(res.begin(), n)) << endl;
}


Measured memory_bytes: 90688
N, A, B, C = map(int, input().split())
t = [int(input()) for i in range(N)]
INF = 10**9

def dfs(cur, a, b, c):
  if cur == N:
    return abs(a-A)+abs(b-B)+abs(c-C) - 30 if min(a,b,c) >0 else INF
  ret0 = dfs(cur+1, a, b, c)
  ret1 = dfs(cur+1, a+t[cur], b, c) + 10
  ret2 = dfs(cur+1, a, b+t[cur], c) + 10
  ret3 = dfs(cur+1, a, b, c+t[cur]) + 10
  return min(ret0, ret1, ret2, ret3)
print(dfs(0,0,0,0))

Measured memory_bytes: 3064
#include <string>
#include <vector>
#include <iostream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <utility>
#include <numeric>
#include <map>
using namespace std;


#define prec(i) cout << fixed << setprecision(i)

const long long MOD = 1000000007;

long long fact(long long k) {
	long long sum = 1;
	for (long long i = 2; i <= k; i++)
		sum *= i;

	return sum;
}

long long fact_mod(long long k) {
	long long sum = 1;
	for (long long i = 2; i <= k; i++)
		sum = (sum * i) % MOD;

	return sum;
}

int ctoi(char c) {
	if (c >= '0' && c <= '9')
		return c - '0';
	else
		return -1;
}

long long pow_mod(int a, int b) {
	long long ans = 1;
	for (int i = 0; i < b; i++)
		ans = (ans * a) % MOD;

	return ans;
}

long long powll(long long a, long long  b) {
	long long ans = 1;
	for (long long i = 0; i < b; i++)
		ans = ans * a;

	return ans;
}

long long modinv(long long a) {
	long long b = MOD, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= MOD;
	if (u < 0) u += MOD;
	return u;
}




int main()
{
	long long h, w, n, sum = 0;

	cin >> h;
	cin >> w;
	cin >> n;

	cout << (int)ceil((float)n / max(h, w)) << endl;

	return 0;
}

Measured memory_bytes: 256
def check():
    N,K = map(int,input().split())

    #中心1
    m_list = []
    for i in range(2,N+1):
        m_list.append([1,i])

    saidai = int((N-1)*(N-2)/2)

    if K > saidai:
        return False

    herasu = saidai - K

    if herasu == 0:
        return m_list

    cnt = 0
    for i in range(2,N+1):
        for j in range(i+1,N+1):
            m_list.append([i,j])
            cnt += 1
            if cnt == herasu:
                return m_list

result = check()
if result == False:
    print(-1)
else:
    print(len(result))
    for a,b in result:
        print(a,b)

Measured memory_bytes: 45040
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
#include<climits>
using namespace std;

int main() {
  int cnt=0;
  int N, K;
  string S;
  string tmp;

  cin >> N >> K;
  cin >> S;

  tmp = S[K-1];
  if(tmp == "A" ){
    S.replace(K-1, 1, "a");
  }else if(tmp == "B"){
    S.replace(K-1, 1, "b");
  }else if(tmp == "C"){
    S.replace(K-1, 1, "c");
  }

  cout << S << endl;
}

Measured memory_bytes: 256
N, M, K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
Asum = [0]
Bsum = [0]
a = 0
b = 0
for i in range(N):
    a += A[i]
    Asum.append(a)
for i in range(M):
    b += B[i]
    Bsum.append(b)
Asum.append(0)
Bsum.append(0)
res, j = 0, M
for i in range(N+1):
    if Asum[i] > K:
        break
    while Asum[i] + Bsum[j] > K:
        j -= 1
    res = max(res,i+j)
print(res)

Measured memory_bytes: 47444
#include <bits/stdc++.h>
using namespace std;
int main() {
  int k,a,b;
  cin >> k >> a >> b;
  bool bl = false;
  for(int i = a; i <= b; i++) {
    if(i%k==0) {
      bl = true;
      break;
    }
  }
  if(bl) cout << "OK";
  else cout << "NG";
}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
int x,g;
int gcd(int a, int b) { return b?gcd(b,a%b):a; }
int main() {
  scanf("%d",&x);
  g=gcd(x,360);
  printf("%d\n",360/g);
  return 0;
}


Measured memory_bytes: 3864
# include <iostream>
using namespace std;
int w,x,y,z,s;
void work (void)
{
	int p,q,u,v;
	p=0;
	q=0;
	if (x>y)
	p=x-y;
	if (z>w)
	q=z-w;
	if (p<=q)
	s=p;
else s=q;
    u=x-w;
	v=z-y;
	if (u>v)
	u=v;
    if (s>u)
    s=u;
    cout<<s;
}
int main (void)
{
	cin>>w>>x>>y>>z;
	work ();
	return 0;
}


Measured memory_bytes: 256
#Take a dictionary of operators
operators = {
"+": (lambda a, b: a + b),
"-": (lambda a, b: a - b),
"*": (lambda a, b: a * b),
"/": (lambda a, b: a / b)
}

def evaluate(tokens):
    #Take empty Stack
    stack = []
    
    #Loop through each token
    for token in tokens:
    #If it is a token , then perform operation
        if token in operators:
            # Take the top 2 arguments and perform operation
            arg2 = stack.pop()
            arg1 = stack.pop()
            result = operators[token](arg1, arg2)
            stack.append(result)
        else:
            #Else, append it to the stack
            stack.append(int(token))
    
    return stack.pop()
  
#Read input   
expression = input()

#Split the tokens
tokens = expression.split()

#Print the result
print(evaluate(tokens))


Measured memory_bytes: 5596
import math

def clockangles(hour, minute):
    ans = abs((hour * 30 + minute * 0.5) - (minute * 6))
    return min(360-ans,ans)

a, b, h, m = input ().split() 
a = float (a)
b = float (b)
h = float (h)
m = float (m)
angle = math.cos (clockangles (h, m) * math.pi / 180.0) 
ans = ((a ** 2) + (b ** 2) - ((2 * a * b) * angle))
print (math.sqrt(ans))


Measured memory_bytes: 9456
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var arr=input.trim().split("\n");
var ans = "";
while (arr.shift() != 0) {
   var a = arr.shift().split(" ");
   var obj = {};
   for (var i = 0; i < a.length; i++) {
      obj[a[i]] = obj[a[i]] + 1 || 1;
      var s = [];
      for (var k in obj) s.push([obj[k], k]);
      s.sort(function(a, b) {
         return b[0] - a[0];
      });
      if (s.length == 1) s[1] = [0];
      if (s[0][0] > s[1][0] + a.length - (i + 1)) {
         ans+=s[0][1]+" "+ (i + 1)+"\n";
         break;
      }
   }
   if (i == a.length) ans+="TIE"+"\n";
}
console.log(ans.trim());

Measured memory_bytes: 20780
#include<iostream>
#include<vector>
#include<cstdlib>
using namespace std;

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

const long long INF = 1LL << 60;
long long h[100010];
long long dp[100010];


int main() {
	int N; cin >> N;
	int K; cin >> K;
	for (int i = 0;i < N;i++)cin >> h[i];
	for (int i = 0;i < N;i++) dp[i] = INF;

	dp[0] = 0;

	for (int i = 0;i < N;i++) {
		for (int j = 1;j <= K;j++) {
			chmin(dp[i + j], dp[i] + abs(h[i] - h[i + j]));

		}
	}

	cout << dp[N - 1] << endl;

}

Measured memory_bytes: 1792
#include <iostream>
#include <climits>
#include <stack>
#include <queue>
#include <string>
#include <utility>
#include <string.h>
#include <iomanip>
#include <stdlib.h>
#include <algorithm>
#include<vector>
#include<cmath>

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



int main()
{
	int i,j,k,l,m,n,A,B,C,Y,flag,N,M,X,H, W;
	k = 0;
	long long int sum = 0;
	cin >>A>>B>>C>>X>>Y;
	if (2 * C <= A + B) {
		if (2 * C > A && 2 * C > B) {
			if (X > Y) {
			 sum=Y * 2 * C + A * (X - Y);
			}
			else {
				sum= X * 2 * C + B * (Y - X);
			}
		}
		else if (2 * C <= A&&2*C>B) {
			if (X > Y) {
				sum= X * 2 * C ;
			}
			else {
				sum= X * 2 * C + B * (Y - X) ;
			}
		}
		else if (2 * C <= B&&2*C>A) {
			if (X > Y) {
				sum=Y * 2 * C + A * (X - Y);
			}
			else {
				sum=Y * 2 * C;
			}
		}
		else {
			sum=fmax(X, Y)*C * 2;
		}

	}
	else {
		sum=A * X + B * Y;
	}


	flag = 0;
	cout << sum << endl;
	return 0;
}



Measured memory_bytes: 384
import sys
sys.setrecursionlimit(10**7)

def main():
    N, M = map(int, input().split())
    V = [[] for _ in range(N)]
    for _ in range(M):
        a, b = map(int, input().split())
        V[a - 1].append(b - 1)
    C = [0] * N
    loop = []
    def dfs(n):
        if C[n] == 2:
            return False
        if C[n] == 1:
            loop.append(n)
            return True
        C[n] = 1
        for i in V[n]:
            if dfs(i):
                loop.append(n)
                return True
        C[n] = 2
        return False
    for i in range(N):
        if dfs(i):
            break
    if len(loop) == 0:
        print('-1')
        return
    for i in range(1, len(loop)):
        if loop[i] == loop[0]:
            break
    loop = loop[:i][::-1]

    def minimize(l):
        s = set(l)
        for i in range(len(l)):
            for j in V[l[i]]:
                if j == l[(i + 1) % len(l)]:
                    continue
                if j in s:
                    break
            else:
                continue
            break
        else:
            return l
        I = {m: k for k, m in enumerate(l)}
        j = I[j]
        if i < j:
            l = l[0:i + 1] + l[j:]
        else:
            l = l[j:i + 1]
        return l
    while True:
        t = len(loop)
        loop = minimize(loop)
        if len(loop) == t:
            break
    print(t)
    print('\n'.join(str(i + 1) for i in loop))
main()


Measured memory_bytes: 4084
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;

#define ff              first
#define ss              second
#define int             long long
#define ll              long long
#define pb              push_back
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zerobits(x)      __builtin_ctzll(x)
#define mod             998244353
#define Mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define vpii            vector<pair<int,int> >
#define all(x)          x.begin(),x.end()
#define gcd(m,n)        __gcd(m,n)
#define matrixprint(arr,a,b,c,d) for(int i=a;i<=c;i++){for(int j=b;j<=d;j++){cout<<arr[i][j]<<" ";}cout<<"\n";}
#define show(arr,x,y)   for(int i=x;i<=y;i++){cout<<arr[i]<<" ";}cout<<"\n"
#define sz               size()
#define inc(i,x,y)      for(int i=x;i<=y;i++)
#define dec(i,x,y)      for(int i=x;i>=y;i--)



#define TRACE
#ifdef TRACE
#define deb(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cout << name << " : " << arg1 << std::endl;
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ','); cout.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
    }
#else
#define deb(...)
#endif

void fast()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//#ifndef ONLINE_JUDGE
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
//#endif
}

//////////////////////////////code//////////////////////////////

int32_t main()
{
  fast();

  int n,w;
  cin>>n>>w;

  vi wt(n+1),val(n+1);

  for(int i=1;i<=n;i++)
  {
      cin>>wt[i];
      cin>>val[i];
  }

  int dp[101][100001]={0};

  for(int i=1;i<=n;i++)
  {
      for(int j=0;j<=w;j++)
      {
          if(j-wt[i]>=0)
            dp[i][j]=max(dp[i-1][j-wt[i]]+val[i],dp[i-1][j]);
          else
            dp[i][j]=dp[i-1][j];
      }

  }

  int ans=INT_MIN;
  
  //matrixprint(dp,0,0,n,w);
  for(int i=0;i<=w;i++)
    ans=max(dp[n][i],ans);

  cout<<ans;


}


Measured memory_bytes: 79360
#include <stdio.h>
#include <math.h>



int main(){
	int n,s[110];
	int i,j,k,l,m;
	int max,min;
	int sum;
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		max=-1;
		min=-1;
		sum=0;
		for(i=0; i<n; i++){
			scanf("%d",&s[i]);
			if(max==-1)max=s[i];
			if(min==-1)min=s[i];
			if(max<s[i])max=s[i];
			if(min>s[i])min=s[i];
			sum+=s[i];
		}
		sum-=max;
		sum-=min;
		printf("%d\n",sum/(n-2));
	}

	return 0;
}

Measured memory_bytes: 600
Q = int(input())
#エラトスてねす

M = 55560
prime=[True]*M
prime[0]=False
prime[1]=False
ans =[]
for i in range(2,M):
    if prime[i]:
        for j in range(2,(M-1)//i+1):
            prime[i*j]=False
    if i%10 ==1 and prime[i]:
        ans.append(i)
        Q-=1
    if Q==0:
        break
print(' '.join(map(str, ans)))

Measured memory_bytes: 3444
#include <stdio.h>

int main(void)
{
    int R;

    scanf("%d",&R);

    if(R<1200){
        printf("ABC\n");
    }else if(1200<=R&&R<2800){
        printf("ARC\n");
    }else{
        printf("AGC\n");
    }

    return 0;
}

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

using namespace std;
typedef long long llong;

#define MAX 13
const llong mod = 1000000000 + 7;
const int sumOver = 1e5 * 13;

int main()
{
  int N, M, X;
  int A[MAX][MAX], C[MAX], Y[MAX];

  scanf("%d%d%d", &N, &M, &X);

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

  // bitを利用
  // 2のN+1乗
  int size = 1;
  for (int i = 0; i < N; i++)
  {
    size *= 2;
  }
  int ans = sumOver;
  for (int i = 0; i < size; i++)
  {
    int cSum = 0, flag = 1;
    for (int i = 0; i < M; i++)
    {
      Y[i] = 0;
    }
    for (int j = 0; j < N; j++)
    {
      // bitが立ってたら
      if ((i >> j) % 2)
      {
        cSum += C[j];
        for (int k = 0; k < M; k++)
        {
          Y[k] += A[j][k];
        }
      }
    }
    for (int j = 0; j < M; j++)
    {
      if (Y[j] < X)
      {
        flag = 0;
        break;
      }
    }

    if (flag)
    {
      ans = min(cSum, ans);
    }
  }
  if (ans == sumOver)
  {
    printf("-1\n");
    return 0;
  }

  printf("%d", ans);

  return 0;
}

Measured memory_bytes: 1712
import java.io.*;
import java.util.StringTokenizer;

class Main {
	public static void main(String args[]) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String buf;
		int start_year[] = {1868,1912,1926,1989};

		try {
			while ((buf = br.readLine())!=null) {
				StringTokenizer st = new StringTokenizer(buf);
				int y = Integer.parseInt(st.nextToken());
				int m = Integer.parseInt(st.nextToken());
				int d = Integer.parseInt(st.nextToken());
				String gengo;
				int pass = 0;
				if (y<=1867) {
					gengo = "pre-meiji";
				} else if (y==1868) {
					if (m<=8) gengo = "pre-meiji";
					else if (m==9&&d<=7) gengo = "pre-meiji";
					else {
						gengo = "meiji";
						pass = start_year[0];
					}
				} else if (y<=1911) {
					gengo = "meiji";
					pass = start_year[0];
				} else if (y==1912) {
					if (m<=6) {
						gengo = "meiji";
						pass = start_year[0];
					} else if (m==7&&d<=29) {
						gengo = "meiji";
						pass = start_year[0];
					} else {
						gengo = "taisho";
						pass = start_year[1];
					}
				} else if (y<=1925) {
					gengo = "taisho";
					pass = start_year[1];
				} else if (y==1926) {
					if (m==12&&d>=25) {
						gengo = "showa";
						pass = start_year[2];
					} else {
						gengo = "taisho";
						pass = start_year[1];
					}
				} else if (y<=1988) {
					gengo = "showa";
					pass = start_year[2];
				} else if (y==1989) {
					if (m==1&&d<=7) {
						gengo = "showa";
						pass = start_year[2];
					} else {
						gengo = "heisei";
						pass = start_year[3];
					}
				} else {
					gengo = "heisei";
					pass = start_year[3];
				}

				if (pass!=0) {
					System.out.println(gengo+" "+(y-pass+1)+" "+m+" "+d);
				} else {
					System.out.println(gengo);
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

Measured memory_bytes: 16876
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main(int argc, char const *argv[]) {
	string input;
	std::cin >> input;
	int length = input.size();
	// とりあえず1文字減らす
	length--;
	length /= 2;
	bool flag;
	for (size_t i = length; i > 0 ; i--) {
		flag = true;
		for (size_t j = 0; j < i; j++) {
			if (input[j] != input[j+i]) {
				flag = false;
				break;
			}
		}
		if (flag) {
			std::cout << i*2 << '\n';
			break;
		}
	}
	return 0;
}


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

int main() {
    int N,D;
    cin >> N >> D;
    vector<vector<int>> V (N,vector<int>(D));
    for (int i=0 ; i<N ; i++){
        for (int j=0 ; j<D ; j++){
            cin >> V.at(i).at(j);
        }
    }
    int ans=0;   
    for (int i=0 ; i<N ; i++){
        for (int j=i+1 ; j<N ; j++){
            int nijo=0;
            for (int k=0 ; k<D ; k++){
                int dif=abs(V.at(i).at(k)-V.at(j).at(k));
                nijo+=dif*dif;
            }
            bool A=false;
            for (int l=0 ; l<=nijo ; l++){
                if (nijo==l*l)
                    A=true;
            }
            if (A)
                ans++;
        }
    }
    cout << ans <<endl;
}

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

// Insertion Sort

int main(){
    int N;
    cin >> N;
    vector<int> A(N,0);
    REP(i,N){
        cin >> A[i];
    }
    REP(i,N-1){
        cout << A[i] << " ";
    }
    cout << A[N-1] << endl;

    for(int i = 1; i < N; i++){
        int v = A[i];
        int j = i-1;
        while(j>=0 && A[j]>v){
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = v;
        REP(i,N-1){
            cout << A[i] << " ";
        }
        cout << A[N-1] << endl;
    }

    return 0;
}

Measured memory_bytes: 3088
a = int(input())
word = input()
b = int(input())
c = []
d = ""
for i in range(a):
  if word[i] != word[b-1]:
    c.append("*")
  else:
    c.append(word[i])
for i in range(a):
  d += c[i]
print(d)

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

using namespace std;

using pii = pair<int, int>;
using pll = pair<long long, long long>;

constexpr int INF = (int)1e9+7;
constexpr long long LLINF = (long long)1e18+7;

int main()
{
    int n, m;
    cin >> n >> m;
    int s = 0;
    for (int i = 0; i < m; i++) {
        int t;
        cin >> t;
        s += t;
    }
    if (n >= s) {
        cout << n - s << endl;
    }
    else {
        cout << -1 << endl;
    }
}


Measured memory_bytes: 3636
def divisors(N):
    res = []
    i = 1
    while i * i < N:
        if N % i == 0:
            res += [i, N // i]
        i += 1
    if i * i == N and N % i == 0:
        res.append(i)
    res.sort()
    return res

N, M = map(int, input().split())
print(max(d for d in divisors(M) if d * N <= M))


Measured memory_bytes: 3060
//#include <bits/stdc++.h>
#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
typedef long long LL;
const int Maxn=200005;
char s[Maxn];
int main()
{
    scanf("%s",s);
    int len=strlen(s);
    int ans=len;
    for(int i=1;i<len;i++)
    {
        if(s[i]!=s[i-1])
            ans=min(ans,max(i,len-i));
    }
    printf("%d\n",ans);
    //system("pause");  
    return 0;
}


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

using namespace std;

typedef long long ll;

int main()
{
	int x, y;
	cin >> x >> y;

	if((y - 2 * x) % 2)
	{
		cout << "No" << endl;
		return 0;
	}

	int t = (y - 2 * x) / 2;
	int c = x - t;

	if(t >= 0 && c >= 0)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}


Measured memory_bytes: 3636
#include <iostream>

typedef long long ll;

using namespace std;

int main() {
    ll n, k;
    cin >> n >> k;
    ll sum = (n / k) * (n / k) * (n / k);
    if (!(k % 2)) {
        n += k / 2;
        sum += (n / k) * (n / k) * (n / k);
    }
    cout << sum << endl;
    return 0;
}


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

int main() {
   int N,D,num;
   cin>> N >> D ;
  if(N%(D*2+1)>0){cout<< N/(D*2+1)+1 <<endl;}
  else if(N%(D*2+1)==0){cout<< N/(D*2+1) <<endl;}
return 0;
}


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

using namespace std;

int main(){
string s;
cin >> s;
int n = s.size();
int i,j,k;
k=0;
for(i=0; i<n; i++){
for(j=i+1; j<n; j++){
if(s[i]==s[j]){k=1;
break;}
}
}
if(k==1){
cout << "no";
}
else{
cout << "yes";
}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

signed main()
{
    int m, d;
    cin >> m >> d;
    int cnt = 0;
    for (int i = 2; i <= m; i++) {
        for (int j = 2; j <= d; j++) {
            int a = j % 10;
            int b = j / 10;
            if (a == 1 || b == 1)
                continue;
            if (a * b == i) {
                cnt++;
            }
        }
    }
    cout << cnt << "\n";
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
using ll = long long;

int main(){
    int n,ans=100000;
    cin >> n;
    vector<int> w(n);
    for(int i=0;i<n;i++)    cin >> w[i];
    for(int t=1;t<=n;t++){
        int sum1=0,sum2=0;
        for(int i=0;i<n;i++){
            if(i>=t) sum1+=w[i];
            else sum2+=w[i];
        }
        ans = min(abs(sum1-sum2),ans);
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 256
#pragma region
#pragma GCC target("avx2")
#pragma GCC optimize("03")
#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
using namespace std; typedef long double ld; typedef long long ll;
typedef unsigned long long ull;
#define endl "\n"
#define MP make_pair
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORR(x,arr) for(auto& x:arr)
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define VPII vector<PII>
#define VPLL vector<PLL>
#define FI first 
#define SE second
#define ALL(x) (x).begin(), (x).end()
constexpr int INF=1<<30; constexpr ll LINF=1LL<<60; constexpr ll mod=1e9+7; constexpr int NIL = -1;
template<class T>inline bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>inline bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
#pragma endregion
//-------------------
int n,q;
unordered_map<ll, ll> mp;
int main(){
    cin.tie(0); ios::sync_with_stdio(false); //cout << fixed << setprecision(15);
    cin >> n;
    ll ans = 0;
    FOR(i,1,n) {
        ll a; cin >> a;
        mp[a]++;
        ans += a;
    }
    cin >> q;
    FOR(i,1,q) {
        ll b,c; cin >> b >> c;
        mp[c] += mp[b];
        ans += -b*mp[b] + c*mp[b];
        mp[b] = 0;
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 6984
#include<bits/stdc++.h>
using namespace std;
long long n,m,i,j,k,len,ans=0;
char s1[1000005],s2[1000005];
int main(){
	cin>>s1>>s2;
	len=strlen(s1);
	//printf("%d\n",len);
	for(i=0;i<len;i++){
		if(s1[i]!=s2[i]){
			ans++;
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int64_t> A(N);
    for (int i = 0; i < N; i++) cin >> A.at(i);

    int zero = 0;
    for (int i = 0; i < N; i++) if (A.at(i) == 0) zero++;
    if (zero > 0) {
        cout << 0 << endl;
        return 0;
    }

    int64_t ans = 1;
    for (int i = 0; i < N; i++) {
        if (A.at(i) <= 1000000000000000000 / ans) {
            ans *= A.at(i);
        } else {
            cout << -1 << endl;
            return 0;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 3936