akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int pow(int x, int time) {
	int ans = 1;
	while(time) {
		ans *= x;
		time--;
	}
	return ans;
}

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

	if (a > b) {
		int c = b;
		b = a;
		a = c;
	}
	int big = 0;
	for (int i = 0; i < b; i++) {
		big += a * pow(10, i);
	}
	cout << big << endl;
}


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

ll sum(ll l, ll r){
  return (l+r)*(r-l+1)/2;
}

int main(){
  int n,k; cin >> n >> k;
  ll cnt = 0;
  for(int i = k; i <= n+1; i++){
    ll l = sum(0,i-1), r = sum(n-i+1,n);
    cnt += r-l+1;
  }
  ll ans = cnt % 1000000007;
  cout << ans << endl;
  return 0;
}

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

using namespace std;

int main()
{
	int A, B, C;
	cin >> A >> B >> C;
	if (max(A, B) > C && min(A, B) < C)
	{
		cout << "Yes";
	}
	else cout << "No";
	return 0;
}

Measured memory_bytes: 256
n = gets.to_i
money = Array.new(n,0.0)
ba = Array.new(n,"")
for i in 0..n-1
  inst = gets.chomp.split
  money[i] = inst[0].to_f
  ba[i] = inst[1]
end
ans = 0
for i in 0..n-1
  if ba[i] == "JPY"
    ans += money[i]
  else
    ans += money[i]*380000.0
  end
end
puts ans


Measured memory_bytes: 1788
strings = []
stringed = " "
flag = 0

num = int(input())

for i in range(num):
    string = input()
    if string[0] != stringed[-1] and i != 0:
        flag = 1
    for st in strings:
        if st == string:
            flag = 1
    if flag == 1:
        break
    stringed = string
    strings.append(string)

if flag == 0:
    print("Yes")
else:
    print("No")
    

Measured memory_bytes: 3060
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+10;
int vis[maxn];
int sets[maxn];
struct Node
{
    int x,y;
};
vector<Node>s[maxn];
void dfs(int num,int date)
{
    for(int i=0;i<s[num].size();i++)
    {
         Node no=s[num][i];
         if(vis[no.x]==0)
         {
             vis[no.x]=1;
             if(no.y%2==0)
            sets[no.x]=date,dfs(no.x,date);
            else
            sets[no.x]=date^1,dfs(no.x,date^1);

         }
    }
}
int main()
{
       int n,x,y,z;
       cin>>n;
       for(int i=1;i<=n;i++)
       sets[i]=-1;
       sets[1]=0;
       int vis[maxn];
       for(int i=0;i<n-1;i++)
       {
          cin>>x>>y>>z;
          s[x].push_back({y,z});
          s[y].push_back({x,z});
       }
       dfs(1,0);
       for(int i=1;i<=n;i++)
       cout<<sets[i]<<endl;





return 0;
    }


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

int main() {
  int h, w;
  cin>>h>>w;
  string c[h];
  for (int i=0; i<h; i++) cin>>c[i];
  for (int i=0; i<2*h; i++) {
    cout<<c[i/2]<<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<int(n);i++)
using namespace std;
int main() {
	int a,b,ans;

	cin >> a >> b;
	ans=-1;
	int c,d;
	for(int i=1;i<=1009;i++){
		c=int(i*0.08);
		d=int(i*0.1);
		if(c==a && d==b){
			ans=i;
			break;
		}
	}
	cout << ans <<endl;
	return 0;
}


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

using namespace std;

typedef long long lli;
typedef double lld;
typedef vector<lli> vll;
typedef vector<bool> vbl;
typedef vector<double> vdl;
typedef vector<vector<lli>> mat;
typedef vector<vdl> mad;
// typedef unordered_map<lli,unordered_map<lli,lli>> graph;
typedef complex<double> cmp;
typedef vector<cmp> vcl;

const lli e5 = 1 << 20;
const lli mod = 998244353;
const lli e3 = 1 << 12;

lli n;
lli a[e3];
lli b[e3];
lli graph[e3][e3];
unordered_set<lli> unuse;
lli ans;

void error(){
  cout << -1 << endl;
  exit(0);
}

int main(){
  cin >> n;
  for(lli i = 0;i < n;i++) cin >> a[i];
  for(lli j = 0;j < n;j++) cin >> b[j];
  for(lli i = 50;i >= 0;i--){
    unuse.insert(i);
    for(lli j = 0;j <= 50;j++){
      for(lli k = 0;k <= 50;k++){
        if(j == k) graph[j][k] = 1;
        else graph[j][k] = 0;
      }
    }
    for(lli j = 0;j <= 50;j++){
      for(lli k = 1;k <= 50;k++){
        if(!unuse.count(k)){
          graph[j][j%k] = 1;
        }
      }
    }
    // for(lli j = 0;j <= 50;j++){
    //   for(lli k = 0;k <= 50;k++){
    //     cerr << graph[j][k] << " ";
    //   }
    //   cerr << endl;
    // }
    for(lli i = 0;i <= 50;i++){
      for(lli j = 0;j <= 50;j++){
        for(lli k = 0;k <= 50;k++){
          if(graph[j][k] == 0) graph[j][k] = (graph[j][i] && graph[i][k]);
        }
      }
    }
    // for(lli j = 0;j <= 50;j++){
    //   for(lli k = 0;k <= 50;k++){
    //     cerr << graph[j][k] << " ";
    //   }
    //   cerr << endl;
    // }
    lli flag = 0;
    for(lli i = 0;i < n;i++){
      if(graph[a[i]][b[i]] == 0){
        flag = 1;
        break;
      }
    }
    if(flag){
      if(i == 50) error();
      unuse.erase(unuse.find(i));
    }
  }
  for(lli i = 0,b = 1;i <= 50;i++,b <<= 1){
    if(!unuse.count(i)) ans += b;
  }
  cout << ans << endl;

}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define LL long long
int n;
const int N = 300000;
const LL INF = 1e15;
#define pI pair <LL, int>
#define fr first
#define sc second
#define mp make_pair
int xi[N];
vector <int> bi[N], ci[N];
int fp[N];
int get_fp(int a)
{
    if (fp[a] == a) return a;
    else return fp[a] = get_fp(fp[a]);
}
struct PP
{
    pI a, b;
} O, edge[N], F[N], tmp[N], U[N];
LL ans;
PP merge(PP x, PP y)
{
    PP z;
    if (x.a > y.a) swap(x, y);
    z.a = x.a;
    if (x.a.sc == y.a.sc)
        if (x.a.sc == y.b.sc)
            z.b = x.b;
        else if (x.b < y.b)
            z.b = x.b;
        else z.b = y.b;
    else if (x.b < y.a)
        z.b = x.b;
    else z.b = y.a;
    return z;
}
PP ADD(PP x, int v)
{
    return (PP){mp(x.a.fr + v, x.a.sc), mp(x.b.fr + v, x.b.sc)};
}
PP dfs1(int t, int f)
{
    F[t] = O; F[t].a = mp(xi[t], get_fp(t));
    for (int i = 0; i < bi[t].size(); ++ i)
        if (bi[t][i] != f)
        {
            PP res = ADD(dfs1(bi[t][i], t), ci[t][i]);
            F[t] = merge(F[t], res);
        }
    edge[get_fp(t)] = merge(edge[get_fp(t)], ADD(F[t], xi[t]));
    return F[t];
}
void dfs2(int t, int f, PP u)
{
    edge[get_fp(t)] = merge(edge[get_fp(t)], ADD(u, xi[t]));
    tmp[bi[t].size()] = O;
    for (int i = bi[t].size() - 1; ~i; -- i)
    {
        tmp[i] = tmp[i + 1];
        if (bi[t][i] != f) tmp[i] = merge(tmp[i], ADD(F[bi[t][i]], ci[t][i]));
    }
    PP p = O; p.a = mp(xi[t], get_fp(t));
    for (int i = 0; i < bi[t].size(); ++ i)
        if (bi[t][i] != f)
        {
            U[bi[t][i]] = ADD(merge(merge(u, p), tmp[i + 1]), ci[t][i]);
            p = merge(p, ADD(F[bi[t][i]], ci[t][i]));
        }
    for (int i = 0; i < bi[t].size(); ++ i)
        if (bi[t][i] != f)
            dfs2(bi[t][i], t, U[bi[t][i]]);
}
int C;
int main()
{
    O = (PP){mp(INF, -1), mp(INF, -2)};
    scanf("%d", &n);
    for (int i = 1; i <= n; ++ i) scanf("%d", &xi[i]);
    for (int i = 1; i < n; ++ i)
    {
        int a, b, c;
        scanf("%d%d%d", &a, &b, &c);
        bi[a].push_back(b); ci[a].push_back(c);
        bi[b].push_back(a); ci[b].push_back(c);
    }
    for (int i = 1; i <= n; ++ i) fp[i] = i;
    while (C < n - 1)
    {
        for (int i = 1; i <= n; ++ i) edge[i] = O;
        dfs1(1, 0);
        dfs2(1, 0, O);
        for (int i = 1; i <= n; ++ i) if (fp[i] == i)
        {
            pI w;
            if (edge[i].a.sc == i) w = edge[i].b;
            else w = edge[i].a;
            if (get_fp(w.sc) != get_fp(i))
            {
                fp[i] = w.sc;
                ans += w.fr;
                C ++;
            }
        }
    }
    printf("%lld\n", ans);
}


Measured memory_bytes: 124928
(eval-when (:compile-toplevel :load-toplevel :execute)
  (defparameter OPT
    #+swank '(optimize (speed 3) (safety 2))
    #-swank '(optimize (speed 3) (safety 0) (debug 0)))
  #+swank (progn (ql:quickload '(:cl-debug-print))))
#+swank (cl-syntax:use-syntax cl-debug-print:debug-print-syntax)

(deftype int32 () '(signed-byte 32))
(deftype int64 () '(signed-byte 64))


;;macros
(defmacro println (n)
  `(format t "~a~%" ,n))
(defmacro vint-out (vec)
  `(progn
     (rep i (length ,vec)
          (princ (vref ,vec i))
          (princ " "))
     (fresh-line)))
(defmacro aif (test-form then-form &optional else-form)
  `(let ((it ,test-form))
     (if it ,then-form ,else-form)))

;;vector
(defmacro vec (type &optional (num 100) (val 0))
  (let* ((g (gensym)))
    `(let* ((,g ,num))
       (make-array ,g :element-type ',type :initial-element ,val
                   :adjustable nil :fill-pointer ,g))))

(defmacro double-vec (type &optional (dim1 100) (dim2 100) (val 0))
  `(make-array '(,dim1 ,dim2) :element-type ',type :initial-element ,val))

(defmacro vint (&optional (num 0) (val 0))
  `(vec int32 ,num ,val))

(defmacro double-vec (type &optional (dim1 100) (dim2 100) (val 0))
  `(make-array '(,dim1 ,dim2) :element-type ',type :initial-element ,val))

(defmacro vref (vector pos &optional value)
  (let ((g (gensym)))
    `(let ((,g ,value))
       (if ,g
           (setf (aref ,vector ,pos) ,g)
           (aref ,vector ,pos)))))

(defmacro chvar (sym comp predicate)
  (let ((g (gensym)))
    `(let ((,g ,comp))
       (if (or (null ,sym) (not (funcall ,predicate ,sym ,g)))
           (setf ,sym ,g)))))

(defmacro chmax (sym comp &optional (predicate #'>))
  `(chvar ,sym ,comp ,predicate))

(defmacro chmin (sym comp &optional (predicate #'<))
  `(chvar ,sym ,comp ,predicate))

(defmacro defchangef (name op default-val)
  `(defmacro ,name (var &optional (val ,default-val))
     `(setq ,var (,',op ,val ,var))))
(defmacro read-str ()
  `(write-to-string (read)))

;;本体
(defun main()
  (println
   (if (string< (sort (read-str) #'char<)
                 (sort (read-str) #'char>))
       "Yes" "No")))

#-swank(main)


Measured memory_bytes: 12776
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"
bool check(vector<int>v) {
	if (v[0] == v[1] && v[1] == v[2] && v[2] == v[3] && v[3] == v[4] && 
		v[4] == v[5] &&v[5] == v[6] && v[6] == v[7] && v[7] == v[8] &&

		v[9] == v[10] &&v[10] == v[11] && 
		v[12] == v[13] && v[13] == v[14] &&
		v[15] == v[16] && v[16] == v[17] &&
		v[18] == v[19] && v[19] == v[20] &&

		v[21] == v[22] && v[22] == v[23] && v[23] == v[24] && v[24] == v[25] &&
		v[25] == v[26] && v[26] == v[27] && v[27] == v[28] && v[28] == v[29])
		return true;
	else return false;
}
int main() {
	int N; cin >> N;
	while (N--) {
		set<vector<int>>cubes;
		vector<int>v(30);
		for (int i = 0; i < 30; ++i)cin >> v[i];
		cubes.emplace(v);
		int ans = -1;
		for (int t = 0; t < 10; ++t) {
			set<vector<int>>ncubes;
			for (auto cu : cubes) {
				if (check(cu)) {
					ans = t;
					break;
				}
				for (int i = 0; i < 4; ++i) {
					vector<int>n(cu);
					if (i == 0) {
						swap(n[0], n[23]);
						swap(n[3], n[26]);
						swap(n[6], n[29]);
						swap(n[9], n[20]);
						swap(n[15], n[17]);
					}
					else if (i == 1) {
						swap(n[0], n[27]);
						swap(n[1], n[28]);
						swap(n[2], n[29]);
						swap(n[14], n[15]);
						swap(n[18], n[20]);
					}
					else if (i == 2) {
						swap(n[2], n[21]);
						swap(n[5], n[24]);
						swap(n[8], n[27]);
						swap(n[11], n[18]);
						swap(n[12], n[14]);
					}
					else if (i == 3) {
						swap(n[6], n[21]);
						swap(n[7], n[22]);
						swap(n[8], n[23]);
						swap(n[12], n[17]);
						swap(n[9], n[11]);
					}
					ncubes.emplace(n);
				}
			}
			cubes = ncubes;
			if (ans != -1)break;
		}
		
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3156
import std.functional,
       std.algorithm,
       std.bigint,
       std.string,
       std.traits,
       std.array,
       std.range,
       std.stdio,
       std.conv;

int calc(int a, string op, int b) {
  if (op == "+") {
    return a + b;
  } else {
    return a - b;
  }
}

void main() {
  int[] ABCD = readln.chomp.split("").to!(int[]);
  int A = ABCD[0],
      B = ABCD[1],
      C = ABCD[2],
      D = ABCD[3];
  string[] op = ["+", "-"];

  foreach (op1; op) {
    foreach (op2; op) {
      foreach (op3; op) {
        int e = A.calc(op1, B).calc(op2, C).calc(op3, D);
        if (e == 7) {
          writefln("%d%s%d%s%d%s%d=7", A, op1, B, op2, C, op3, D);
          return;
        }
      }
    }
  }
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
typedef long long ll;
const int mod=2000003,base1=23,base2=47,base3=101,base4=211;
const int N=200010,L=2000010;
int n,pl[N],pr[N],Hash1[L],Hash2[L],Hash3[L],Hash4[L],mp[4][30][2100010],vis[26];
char s[L];
ll ans;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%s",s+pr[i-1]+2);
		pl[i]=pr[i-1]+2;
		for(pr[i]=pl[i];s[pr[i]+1]!='\0';pr[i]++);
		Hash1[pr[i]+1]=Hash2[pr[i]+1]=Hash3[pr[i]+1]=Hash4[pr[i]+1]=0;
		int bs1=base1,bs2=base2,bs3=base3,bs4=base4;
		for(int j=pr[i]+1;j>pl[i];j--){
			Hash1[j-1]=(Hash1[j]+(s[j-1]-'a'+1ll)*bs1)%mod;
			Hash2[j-1]=(Hash2[j]+(s[j-1]-'a'+1ll)*bs2)%mod;
			Hash3[j-1]=(Hash3[j]+(s[j-1]-'a'+1ll)*bs3)%mod;
			Hash4[j-1]=(Hash3[j]+(s[j-1]-'a'+1ll)*bs4)%mod;
			bs1=1ll*bs1*base1%mod;
			bs2=1ll*bs2*base2%mod;
			bs3=1ll*bs3*base3%mod;
			bs4=1ll*bs4*base4%mod;
		}
		mp[0][s[pl[i]]-'a'][Hash1[pl[i]+1]]++;
		mp[1][s[pl[i]]-'a'][Hash2[pl[i]+1]]++;
		mp[2][s[pl[i]]-'a'][Hash3[pl[i]+1]]++;
		mp[3][s[pl[i]]-'a'][Hash4[pl[i]+1]]++;
	}
	for(int i=1;i<=n;i++){
		for(int j=0;j<26;j++)
			vis[j]=0;
		for(int j=pl[i];j<=pr[i]+1;j++){
			for(int k=0;k<26;k++)
				if(vis[k])
					ans+=min(min(mp[0][k][Hash1[j]],mp[1][k][Hash2[j]]),min(mp[2][k][Hash3[j]],mp[3][k][Hash4[j]]));
			if(j<=pr[i])
				vis[s[j]-'a']=1;
		}
	}
	printf("%lld\n",ans-n);
	return 0;
}

Measured memory_bytes: 794684
#include <string.h>
#include <queue>
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double



int main()
{
#ifndef Phuong
    //freopen("input.txt", "r", stdin);
#endif // Phuong
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    string s;
    string t;
    cin >> s;
    cin >> t;
    int n= s.size();
    int m= t.size();
    vector<vector<int>> dp(n+1, vector<int> (m+1,0));
    vector<vector<int>> trace (n+1, vector<int> (m+1,0));
    for(int i=1; i<=n; ++i)
    {
        for(int j=1; j<=m; ++j)
        if (s[i-1]==t[j-1])
        {
            dp[i][j]=1+dp[i-1][j-1];
            trace[i][j]=3;
        } else
        {
            dp[i][j]=max(dp[i-1][j], dp[i][j-1]);
            trace[i][j]=(dp[i-1][j]>dp[i][j-1])?(2):(1);
        }
    }
    int x=n,y=m;
    string ans;
    while(x>=1 && y>=1)
    {
        if (trace[x][y]==3)
        {
            ans=s[x-1]+ans;
            x--;
            y--;
        } else
        {
            if (trace[x][y]==2) x--; else y--;
        }
    }
    cout << ans;

    return(0);
}


Measured memory_bytes: 70912
let rec divisors acc acc' i n =
  match compare n (i * i) with
  | -1 -> List.rev_append acc acc'
  | 0 -> List.rev_append acc (i :: acc')
  | 1 ->
      ( if 0 < n mod i
        then divisors acc acc'
        else divisors (i :: acc) (n / i :: acc') ) (i + 1) n
let divisors = divisors [] [] 1

let () = Scanf.scanf "%d %d\n" @@ fun n k ->
  let as_ = Array.init n @@ fun _ -> Scanf.scanf "%d " @@ fun a -> a in
  let ms = Array.make n 0 in
  let acc = Array.make (n + 1) 0 in
  let acc' = Array.make (n + 1) 0 in
  Printf.printf "%d\n" @@
  List.fold_left max min_int @@
  List.filter (fun d ->
    for i = 0 to n - 1 do
      ms.(i) <- as_.(i) mod d;
    done;
    Array.sort compare ms;
    for i = 0 to n - 1 do
      acc.(i + 1) <- acc.(i) + ms.(i)
    done;
    for i = n - 1 downto 0 do
      acc'.(i) <- acc'.(i + 1) + d - ms.(i)
    done;
    Array.fold_left ( || ) false @@
    Array.init (n + 1) @@ fun i ->
      acc.(i) = acc'.(i) && acc.(i) <= k) @@
  divisors @@
  Array.fold_left ( + ) 0 as_

Measured memory_bytes: 6400
import itertools
from collections import deque,defaultdict,Counter
from itertools import accumulate
import bisect
from heapq import heappop,heappush,heapify
import math
from copy import deepcopy
import queue
#import numpy as np
# sympy as syp(素因数分解とか)
Mod = 1000000007
fact = [1, 1]
factinv = [1, 1]
inv = [0, 1] 
for i in range(2, 10**5 + 1):
    fact.append((fact[-1] * i) % Mod)
    inv.append((-inv[Mod % i] * (Mod // i)) % Mod)
    factinv.append((factinv[-1] * inv[-1]) % Mod)
    
def cmb(n, r, p):
    if (r < 0) or (n < r):
        return 0
    r = min(r, n - r)
    return fact[n] * factinv[r] * factinv[n - r] % p
    
def sieve_of_eratosthenes(n):
    if not isinstance(n,int):
        raise TypeError("n is not int")
    if n<2:
        raise ValueError("n is not effective")
    prime = [1]*(n+1)
    for i in range(2,int(math.sqrt(n))+1):
        if prime[i] == 1:
            for j in range(2*i,n+1):
                if j%i == 0:
                    prime[j] = 0
    res = []
    for i in range(2,n+1):
        if prime[i] == 1:
            res.append(i)
    return res

 
class UnionFind:
    def __init__(self,n):
        self.parent = [i for i in range(n+1)]
        self.rank = [0 for i in range(n+1)]
    
    def findroot(self,x):
        if x == self.parent[x]:
            return x
        else:
            y = self.parent[x]
            y = self.findroot(self.parent[x])
            return y
    
    def union(self,x,y):
        px = self.findroot(x)
        py = self.findroot(y)
        if px < py:
            self.parent[y] = px
        else:
            self.parent[px] = py
 
    def same_group_or_no(self,x,y):
        return self.findroot(x) == self.findroot(y)
def pow_k(x, n):

    if n == 0:
        return 1

    K = 1
    while n > 1:
        if n % 2 != 0:
            K *= x
        x *= x
        n //= 2

    return K * x
def main():  #startline-------------------------------------------
    n = int(input())
    a = list(map(int, input().split()))
    d = defaultdict(int)
    ans = 0
    for i in range(n):
        l = i - a[i]
        ans += d[l]
        d[a[i] + i] += 1
        
    print(ans)
if __name__ == "__main__":
    main() #endline===============================================

Measured memory_bytes: 73948
#include <cstdio>
#include <map>

const int MaxN = 200000 + 5;

int N, K;
long long A[MaxN], Pre[MaxN];
std::map<int, int> Mp;

void init() {
  scanf("%d %d", &N, &K);
  for (int i = 1; i <= N; ++i)
    scanf("%lld", &A[i]);
}

inline int getValue(int pos) {
  return ((Pre[pos] - pos) % K + K) % K;
}

void solve() {
  for (int i = 1; i <= N; ++i)
    Pre[i] = Pre[i - 1] + A[i];
  Mp[0]++;
  long long ans = 0;
  for (int i = 1; i <= N; ++i) {
    if (i >= K) Mp[getValue(i - K)]--;
    ans += Mp[getValue(i)];
    Mp[getValue(i)]++;
  }
  printf("%lld\n", ans);
}

int main() {
  init();
  solve();
  return 0;
}

Measured memory_bytes: 12800
#include<iostream>
#include<vector>
#include<string>
#include<stdlib.h>
#include<algorithm>
using namespace std;

int main() {

	int N,K;
	string S;

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

	if (S[K - 1] == 'A')
		S[K - 1] = 'a';
	else if (S[K - 1] == 'B')
		S[K - 1] = 'b';
	else if (S[K - 1] == 'C')
		S[K - 1] = 'c';

	cout << S << endl;

	return 0;


	return 0;
}

Measured memory_bytes: 256
x, n = list(map(int, input().split()))
p = set(map(int, input().split()))
i = 0
while True:
  if x-i >= 0 and x-i not in p:
    print(x-i)
    break
  if x+i not in p:
    print(x+i)
    break
  i += 1


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

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

  int N, M;
  cin >> N >> M;
  int P;
  string S;
  vector<bool> AC(N + 1, false);
  vector<int> WA(N + 1, 0);

  int WA_cnt = 0, AC_cnt = 0;
  for(int i = 0; i < M; ++i) {
    cin >> P >> S;

    if(AC.at(P) == false && S == "WA") {
      WA.at(P)++;
    }
    else if(AC.at(P) == false && S == "AC") {
      AC.at(P) = true;
      AC_cnt++;
      WA_cnt += WA.at(P);
    }
  }

  cout << AC_cnt << " " << WA_cnt << endl;
  return 0;
}


Measured memory_bytes: 640
def solve():
    N, M, X, Y = map(int, input().split())
    x = list(map(int, input().split()))
    y = list(map(int, input().split()))
    
    max_x = max(X, max(x))
    min_y = min(Y, min(y))
    if max_x < min_y:
        print('No War')
    else:
        print('War')


if __name__ == '__main__':
    solve()


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

#define MOD 10000007
#define f first
#define s second
#define es " "
#define pb push_back
#define endl "\n"
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define ll long long int
#define fastio ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0)

int main(){
    fastio;
    int n, v1[105], v2[105], cont=0, cont1=0;
    string att;
    cin >> n >> att;
    for(int i=0; i<n/2; i++){
        v1[cont]=(int)att[i];
        cont++;
    }
    /*for(int i=0; i<cont; i++){
        cout << v1[i] << es;
    }*/
    //cout << endl;
    for(int i=n/2; i<n; i++){
        v2[cont1]=(int)att[i];
        cont1++;
    }
    /*for(int i=0; i<cont1; i++){
        cout << v2[i] << es;
    }
    cout << endl;
    */for(int i=0; i<cont1; i++){
        if(v1[i]!=v2[i]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    long long N;
    cin >> N;
    map<string,long long> m;
    rep(i,N){
        string x;
        cin >> x;
        sort(x.begin(),x.end());
        m[x]++;
    }
    long long ans=0;
    for(auto p:m){
        ans+=p.second*(p.second-1)/2LL;
    }
    cout << ans << endl;



}


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

//define ll long long;
//define ar array;

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

    int n;
    cin >> n;
    unsigned long long ans;
    unsigned long long arr[100020];
    for (int i = 0; i < n; i++){
        cin >> arr[i];
    }
    sort(arr, arr+n);
    ans = arr[0];
    unsigned long long prv = ans;
    unsigned long long maxll = (long long) 1e18;
    for (int i = 1; i < n; i++){
        ans =  ans * arr[i];
        if (ans > maxll || ((prv > 0) && ((ans / prv) != arr[i]))){
            cout << -1 << endl;
            return 0;
        }
        prv = ans;
    }
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 4328
using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Linq;

partial class Solver
{
    public void Run()
    {
        var N = ni();
        var K = ni();
        double ans = 0;
        for (int i = 1; i <= N; i++)
        {
            long current = i;
            double percent = 1.0;
            while (current < K)
            {
                current *= 2;
                percent /= 2.0;
            }
            ans += percent / N;
        }
        cout.WriteLine(ans);
    }
}


// PREWRITEN CODE BEGINS FROM HERE
partial class Solver : Scanner
{
    public static void Main(string[] args)
    {
        new Solver(Console.In, Console.Out).Run();
    }

    TextReader cin;
    TextWriter cout;

    public Solver(TextReader reader, TextWriter writer)
        : base(reader)
    {
        this.cin = reader;
        this.cout = writer;
    }
    public Solver(string input, TextWriter writer)
        : this(new StringReader(input), writer)
    {
    }

    public int ni() { return NextInt(); }
    public int[] ni(int n) { return NextIntArray(n); }
    public long nl() { return NextLong(); }
    public long[] nl(int n) { return NextLongArray(n); }
    public double nd() { return NextDouble(); }
    public string ns() { return Next(); }
}

public class Scanner
{
    private TextReader Reader;
    private Queue<String> TokenQueue = new Queue<string>();
    private CultureInfo ci = CultureInfo.InvariantCulture;

    public Scanner()
        : this(Console.In)
    {
    }

    public Scanner(TextReader reader)
    {
        this.Reader = reader;
    }

    public int NextInt() { return Int32.Parse(Next(), ci); }
    public long NextLong() { return Int64.Parse(Next(), ci); }
    public double NextDouble() { return double.Parse(Next(), ci); }
    public string[] NextArray(int size)
    {
        var array = new string[size];
        for (int i = 0; i < size; i++) array[i] = Next();
        return array;
    }
    public int[] NextIntArray(int size)
    {
        var array = new int[size];
        for (int i = 0; i < size; i++) array[i] = NextInt();
        return array;
    }

    public long[] NextLongArray(int size)
    {
        var array = new long[size];
        for (int i = 0; i < size; i++) array[i] = NextLong();
        return array;
    }

    public String Next()
    {
        if (TokenQueue.Count == 0)
        {
            if (!StockTokens()) throw new InvalidOperationException();
        }
        return TokenQueue.Dequeue();
    }

    public bool HasNext()
    {
        if (TokenQueue.Count > 0)
            return true;
        return StockTokens();
    }

    private bool StockTokens()
    {
        while (true)
        {
            var line = Reader.ReadLine();
            if (line == null) return false;
            var tokens = line.Trim().Split(" ".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
            if (tokens.Length == 0) continue;
            foreach (var token in tokens)
                TokenQueue.Enqueue(token);
            return true;
        }
    }
}


Measured memory_bytes: 11220
h, w = map(int, input().split())
a = []
b = []
for _ in range(h):
    a.append(list(map(int, input().split())))
for _ in range(h):
    b.append(list(map(int, input().split())))

grid = [[0 for _ in range(w)] for _ in range(h)]
for i in range(h):
    for j in range(w):
        grid[i][j] = abs(a[i][j] - b[i][j])

dp = [[0 for _ in range(80*(h+w) + 1)] for _ in range(h+w)]
dp[0][0] = 1
for ij in range(h+w-1):
    for i in range(h):
        j = ij - i
        if j < 0 or j >= w:
            continue
        c = grid[i][j]
        for k in range(80*(h+w-1) + 1):
            if dp[ij][k] == 1:
                dp[ij+1][k+c] = 1
                dp[ij+1][abs(k-c)] = 1

for i in range(100):
    if dp[-1][i] == 1:
        print(i)
        exit()


Measured memory_bytes: 62428
#include <bits/stdc++.h>
#define inf 0x3f3f3f3f
#define pb push_back
#define fi first
#define se second

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

int n;
vector <int> v;

void read() {
  cin >> n;
  for(int i = 0; i < n; ++i) {
    int x;
    cin >> x;
    v.pb(x);
  }
}

void solve() {
  int sol = 0;
  for(int i = 1; i < n - 1; ++i) {
    if ((v[i] > v[i - 1] && v[i] < v[i + 1]) || (v[i] < v[i - 1] && v[i] > v[i + 1])) {
      ++sol;
      //cout << v[i] << " ";
    }
  }
  cout << sol;
}

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

	return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        float n = sc.nextFloat();
        float x = sc.nextFloat();
        int t = sc.nextInt();
        int ans = (int)(Math.ceil(n/x))*t;
        System.out.println(ans);
    }
}

Measured memory_bytes: 37240
#include<iostream>
#include<vector>
using namespace std;
class DisjointSet{
public:
  vector<int> rank,p;
  
  DisjointSet(){}
  DisjointSet(int size){
    rank.resize(size,0);
    p.resize(size,0);
    for(int i =0;i < size;i++){
      make_set(i);
    }
  }
  void make_set(int x){
    p[x]=x;
    rank[x]=0;
  }
  void merge(int x,int y){
    link(find_set(x),find_set(y));
  }
  void link(int x,int y){
    if (rank[x]>rank[y]){
      p[y]=x;
    }else {
      p[x]=y;
      if ( rank[x] ==rank[y])rank[y]+=1;
    }
  }
  int find_set(int x){
    if (x != p[x])p[x]=find_set(p[x]);
    return p[x];
  }
};


int main(){
  int n, m;
  cin >> n >> m;
  DisjointSet dj(n);
  vector<int> in(n);
  for(int i = 0;i < n;i++){
    cin >> in[i];
    in[i]--;
  }
  for(int j = 0;j < m;j++){
    int a,b;
    cin >> a >>b;
    a--;
    b--;
    dj.merge(a,b);
  }
  int ans = 0;
  for(int i = 0;i < n;i++){
    if (dj.find_set(i) == dj.find_set(in[i])){
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1408
#include<stdio.h>

int hantei(char x[], char y[]) {
int xn = 0, yn = 0, flag = 0, i, j, max = 0;
int c[1001][1001];

while (flag == 0)
{

if (x[xn] != '\0')
{
xn++;
} else {
flag = 1;
}

}

flag = 0;

while (flag == 0) {

if (y[yn] != '\0')
{
yn++;
} else {
flag = 1;
}

}

for (i = 1; i < xn + 1; i++) c[i][0] = 0;
for (j = 1; j < yn + 1; j++) c[0][j] = 0;

for (i = 1; i < xn + 1; i++)
{

for (j = 1; j < yn + 1; j++)
{

if (x[i - 1] == y[j - 1]) {
c[i][j] = c[i - 1][j - 1] + 1;
} else if (c[i - 1][j] >= c[i][j - 1]) {
c[i][j] = c[i - 1][j];
} else {
c[i][j] = c[i][j - 1];
}

if (max < c[i][j]) max = c[i][j];

}

}

return max;
}

int main(void) {
char x[1000], y[1000];
int q, i;

scanf("%d", &q);

for (i = 0; i < q; i++)
{
scanf("%s", x);
scanf("%s", y);
printf("%d\n", hantei(x, y));
}

return 0;
}

Measured memory_bytes: 5708
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAXN=int(1e3+5);
int H,W,A,B;
int Ans[MAXN][MAXN];
int main()
{
    //freopen("stone.in","r",stdin);
    //freopen("stone.out","w",stdout);
    scanf("%d%d%d%d",&H,&W,&A,&B);
    for(int i=1;i<=H;i++) {
        for(int j=1;j<=W;j++) {
            if((i<=B)==(j<=A))
                printf("1");
            else
                printf("0");
        }
        puts("");
    }
}


Measured memory_bytes: 1152
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

const int N = 3600*24;

int main() {
    int n;
    while (cin >> n && n){
        VI d(N);
        REP(i,n) {
            int h, m, s;
            scanf("%d:%d:%d", &h, &m, &s);
            s += 60*m + 3600*h;
            d[s]++;
            scanf("%d:%d:%d", &h, &m, &s);
            s += 60*m + 3600*h;
            d[s]--;
        }
        FOR(i,1,N-1) d[i] += d[i-1];
        int ans = 0;
        REP(i,N) ans = max(ans, d[i]);
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 3400
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <math.h>
using namespace std;

int main() {

	int A;
	int B;

	cin >> A;
	cin >> B;

	if (A + B == 3) {
		cout << 3 << endl;
	}
	else if (A + B == 4) {
		cout << 2 << endl;
	}
	else if (A + B == 5) {
		cout << 1 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1e9+7 , inv2 = (mod+1)/2;
ll n,p=1,q,ans,a[3005],dp[3005][3005];
int main(){
    ios_base:: sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    cin>>n>>q;
    for(ll i=1;i<=n;i++)cin>>a[i];
    for(ll i=1;i<=n;i++)for(ll j=1;j<=n;j++)dp[i][j]=a[i]>a[j];
    for(;q>0;q--){
        ll x,y;cin>>x>>y;
        for(ll i=1;i<=n;i++){
            if(i==x || i==y)continue;
            ll p = dp[x][i] + dp[y][i];
            ll q = dp[i][x] + dp[i][y];
            dp[x][i]=dp[y][i]=p*inv2%mod;
            dp[i][x]=dp[i][y]=q*inv2%mod;
        }
        ll r = dp[x][y] + dp[y][x];
        dp[x][y]=dp[y][x]=r*inv2%mod;
        p=(p*2)%mod;
    }
    for(ll i=1;i<=n;i++)for(ll j=i+1;j<=n;j++)ans=(ans + dp[i][j])%mod;
    ans = (ans * p)%mod;
    cout<<ans;
}

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

using namespace std;
using ll = long long;

template <typename K,typename V>
using umap = unordered_map<K,V>;
template <typename V>
using uset = unordered_set<V>;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define REP(i,n) for(int i=0;i<n;i++)
#define REPD(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define ALL(v) v.begin(),v.end()

#define INF 1'000'000'000'000 //10^12
#define MOD 1'000'000'007


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

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);

    int n;
    cin >> n;
    double p[n];
    REP(i,n){
        cin >> p[i];
    }

    vector<vector<double>> dp(n+1,vector<double>(n+1,0.0));

    dp[0][0] = 1.0;

    REP(i,n){
        REP(j,n){
            dp[i+1][j+1] += dp[i][j] * p[i];
            dp[i+1][j] += dp[i][j] * (1-p[i]);
        }
    }
    double res = 0.0;

    REP(i,n+1){
        if(i > n - i){
            res += dp[n][i];
        }
    }

    cout << res << endl;

    return 0;
}


Measured memory_bytes: 73708
import sys

def print_arr(arr):
	for i in range(len(arr)):
		sys.stdout.write(str(arr[i]))
		if i != len(arr) - 1:
			sys.stdout.write(' ')
	print()

def selection_sort(arr):
	cnt = 0
	n = len(arr)
	for i in range(n):
		mini = i
		for j in range(i + 1, n):
			if arr[j] < arr[mini]:
				mini = j
		if mini != i:
			temp = arr[i]
			arr[i] = arr[mini]
			arr[mini] = temp
			cnt += 1
	return cnt

n = int(input())
arr = list(map(int, input().split()))

cnt = selection_sort(arr)
print_arr(arr)
print(cnt)


Measured memory_bytes: 5612
A,B,C,D,E,F = map(int,input().split())
W=set()
for a in range(0,F+1,100*A):
    for b in range(0,F+1-a,100*B):
        W.add(a+b)
S=set()
for c in range(0,F+1,C):
    for d in range(0,F+1-c,D):
        S.add(c+d)
rate = -1
for w in W:
    for s in S:
        if 0 < w+s <= F and s <= w*E//100:
            if s/(w+s) > rate:
                rate = s/(w+s)
                ans = w+s, s
print(ans[0],ans[1])

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

bool check(string t) {
	return t == string(t.size(), t[0]);
}

string transform(string t, char c) {
	string res = "";
	for (int i = 0; i < (int)t.size() - 1; i++)
		if (t[i] == c || t[i + 1] == c)
			res += c;
		else
			res += t[i];
	return res;
}

int main() {
	string s;
	cin >> s;
	
	int sol = 1000;
	for (int i = 0; i < 26; i++) {
		int k = 0;
		for (string tmp = s; !check(tmp); k++)
			tmp = transform(tmp, 'a' + i);
		sol = min(sol, k);
	}
	
	cout << sol << endl;
	
	return 0;
}

Measured memory_bytes: 256
package main

import(
	"fmt"
)

func main() {
	var s string
	fmt.Scan(&s)

	max := 0
	num := 0
	for i:=0; i<len(s); i++{
		if string(s[i]) == "A" || string(s[i]) == "T" || string(s[i]) == "C" || string(s[i]) == "G" {
			num++
		} else {
				num = 0
		}

		if num > max {
			max = num
		}
	}


	fmt.Println(max)
}

Measured memory_bytes: 512
#include<algorithm>
#include<cstdio>
#include<iostream>
#include<cmath>
using namespace std;
int main(void){
	int h1,h2,hsum=0,k1,k2,ksum=0;
	int iwana,yamame,iwana10,yamame20;
	cin>>h1>>h2>>k1>>k2>>iwana>>yamame>>iwana10>>yamame20;
	hsum+=h1*iwana;
	hsum+=((int)(h1/10))*iwana10;
	hsum+=h2*yamame;
	hsum+=((int)(h2/20))*yamame20;
	ksum+=k1*iwana;
	ksum+=((int)(k1/10))*iwana10;
	ksum+=k2*yamame;
	ksum+=((int)(k2/20))*yamame20;
	if(ksum==hsum){
		cout<<"even"<<endl;
	}
	else if(ksum>hsum){
		cout<<"kenjiro"<<endl;
	}
	else{
		cout<<"hiroshi"<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 3120
#include<stdio.h>
#define ll long long int
int main()
{
    ll a,b;
    scanf("%lld %lld",&a,&b);
    ll c;
    c=a+b;
    if(c%2==0)
    {
        ll d;
        d=c/2;
        printf("%lld\n",d);
    }
    else
        printf("IMPOSSIBLE\n");
    return 0;
}


Measured memory_bytes: 128
//Rishabh Sethi @lostground97

#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
#define ll long long
#define in insert
#define mod 1000000007
#define vpair vector< pair <ll,ll> >
#define F first
#define S second

ll modexp(ll x, ll y)
{
	ll ans = 1;
	x = x%mod;
	while(y>0)
	{
		if(y%2==1)
			ans = (ans%mod*x%mod)%mod;
		y = y/2;
		x = (x%mod*x%mod)%mod;
	}
	return ans;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll a, b, k;
	cin>>a>>b>>k;
	int x = 1;
	while(k--)
	{
	    if(x==1)
	    {
	    if(a%2==1)
	        a--;
	    b = b + a/2;
	    a = a/2;
	    }
	    else
	    {
	        if(b%2==1)
	        b--;
	    a = a + b/2;
	    b = b/2;
	    }
	    x = 1 - x;
	}
	cout<<a<<" "<<b<<endl;
}

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

dic = {}
for x in range(1,100):
    for y in range(1, 100):
        for z in range(1,100):
            a = x**2+y**2+z**2+x*y+y*z+x*z

            if not a in dic:
                dic[a] = 1
            
            else:
                dic[a] += 1

for i in range(1,n+1):
    if not i in dic:
        print(0)
    
    else:
        print(dic[i])

Measured memory_bytes: 72184
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int MOD = 1000000007;
const int INF = 1001001001;

int main(){
    
    int a,b; cin>>a>>b;
    if(a*b%2)cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3640
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;
import java.util.StringTokenizer;
import java.io.BufferedReader;
import java.util.Comparator;
import java.io.InputStream;

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

    static class BPolygon {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            List<Integer> list = new ArrayList<>();
            for (int i = 0; i < n; i++) {
                list.add(in.nextInt());
            }
            list.sort(Comparator.reverseOrder());
            int max = list.get(0);
            list.remove(0);
            int sum = 0;
            for (int i : list) {
                sum += i;
            }
            out.println(sum > max ? "Yes" : "No");
        }

    }

    static class InputReader implements AutoCloseable {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 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 int nextInt() {
            return Integer.parseInt(next());
        }

        public void close() {
        }

    }
}



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

#define int long long
#define loop(i,n) for(int i=1;i<=n;i++)
int p[100002];
int s[100002];

signed main() {
  int n,m,a,b,c;
  cin>>n>>m;
  loop(j,m){
    cin>>p[j];
    if(j==1)continue;
    s[min(p[j-1],p[j])]++;
    s[max(p[j-1],p[j])]--;
  }
  int sum=0;
  int t=0;
  loop(i,n-1){
    cin>>a>>b>>c;
    t+=s[i];
    sum+=min(t*a,t*b+c);
  }
  cout<<sum<<endl;
  return 0;
}

Measured memory_bytes: 4648
import static java.lang.System.*;
import java.util.*;
 
public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		int n = sc.nextInt();
		int day = sc.nextInt();
		int x = sc.nextInt();
		
		int total = 0;
		for (int i=0; i<n; i++) {
			int a = sc.nextInt();
			if (day%a==0) {
				total += day/a;
			}
			else {
				total += day/a + 1;
			}
		}
		
		out.println(total+x);
	}
}

Measured memory_bytes: 21716
#include "bits/stdc++.h"
using namespace std;

int main() {

	vector<int> vec(3);
	cin >> vec.at(0) >> vec.at(1) >> vec.at(2);

	sort(vec.begin(), vec.end());

	string res = "No";

	if (vec.at(0) + vec.at(1) == vec.at(2)) res = "Yes";
	if (vec.at(0) == vec.at(1) + vec.at(2)) res = "Yes";

	cout << res << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] input = new int[N];
		for(int i = 0;i<N;i++) {
			input[i]=sc.nextInt();
		}
		int res=Integer.MAX_VALUE;
		for(int i = 0;i<N;i++) {
			int count=0;
			while(input[i]%2==0) {
				input[i]/=2;
				count++;
			}
			if(count<res) {
				res=count;
			}
		}
		System.out.println(res);


	}
}

Measured memory_bytes: 36160
n = int(input())

def num2alpha(num):
    if num <= 26:
        return chr(96 + num)
    elif num % 26 == 0:
        return num2alpha(num // 26 - 1) + chr(122)
    else:
        return num2alpha(num // 26) + chr(96 + num % 26)

print(num2alpha(n))

Measured memory_bytes: 9176
<?php
// C
fscanf(STDIN, '%d', $n);
if ($n < 6) exit(strval($n));
$n6 = 6;
$n9 = 9;
while (true) {
    if ($n6 > $n && $n9 > $n) break;
    if ($n6 <= $n) {
        $a6[] = $n6;
        $n6 *= 6;
    }
    if ($n9 <= $n) {
        $a9[] = $n9;
        $n9 *= 9;
    }
}
rsort($a6);
rsort($a9);
$ans = PHP_INT_MAX;
for ($i = 0; $i <= $n; $i++) {
    $cnt = 0;
    $t = $i;
    foreach ($a6 as $v) {
        $cnt += intdiv($t, $v);
        $t %= $v;
    }
    $cnt += $t;
    $t = $n - $i;
    foreach ($a9 as $v) {
        $cnt += intdiv($t, $v);
        $t %= $v;
    }
    $cnt += $t;
    $ans = min($ans, $cnt);
}
echo $ans;

Measured memory_bytes: 4728
#include <bits/stdc++.h>
using namespace std;
struct ios_accelerate { ios_accelerate() { ios::sync_with_stdio(false); cin.tie(nullptr); } } CALL;

#define REP(i, n) for(auto (i) = (n)*0; (i) < (n); (i)++)
#define RNG(i, a, b) for(auto (i) = (a); (i) < (b); (i)++)
#define RBF(i, v) for(auto& (i) : (v))
#define ALL(x) (x).begin(), (x).end()

using LL = long long;
using UL = unsigned long;
using ULL = unsigned long long;
template<typename T> using V = vector<T>;
template<typename T> using VV = vector<vector<T>>;
template<typename T> using P = pair<T, T>;

const double PI = 3.141592653589793;
const int MOD = 1000000007;
const LL INF64 = static_cast<LL>(1e18) + 2;
const int INF = static_cast<int>(1e9) + 2;

template<typename T> inline void upsort(vector<T>& x) { sort(x.begin(), x.end()); }
template<typename T> inline void downsort(vector<T>& x) { sort(x.begin(), x.end(), greater<T>()); }
template<typename T> inline void col(T x) { cout << x << '\n'; }
template<> inline void col(double x) { cout << fixed << setprecision(12) << x << '\n'; }

signed main() {
	int n, m;
	cin >> n >> m;

	if (n == m) {
		col("Yes");
	}
	else {
		col("No");
	}

	return 0;
}


Measured memory_bytes: 3648
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, 1000000007)
	sc.Split(bufio.ScanWords)
	n := intScanner()
	fmt.Println(2. * math.Pi * float64(n))
}


Measured memory_bytes: 1756
#include <iostream>
#include <string>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <iomanip>


using namespace std;



int main() {

	string A, B;

	cin >> A >> B;

	if (A.size() > B.size()) {
		cout << "GREATER";
	}
	else if (A.size() < B.size()) {
		cout << "LESS";
	}
	else {
		for (int i = 0; i < A.size(); i++) {
			if (A[i] > B[i]) {
				cout << "GREATER";
				goto End;
			}
			else if (A[i] < B[i]) {
				cout << "LESS";
				goto End;
			}
		}
		cout << "EQUAL";

	}
	
	End:
	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

using value = long double;
const value id = 0.;
value marge(value a, value b) { return a + b; }

int main() {
	int n; scanf("%d", &n);
	std::vector<int> a(n - 1), b(n - 1);
	std::vector<std::vector<int>> g(n);
	for(int i = 0; i < n - 1; i++) {
		scanf("%d%d", &a[i], &b[i]);
		a[i]--; b[i]--;

		g[a[i]].push_back(i);
		g[b[i]].push_back(i);
	}

	std::vector<std::map<int, value>> dp(n);
	auto solve = [&](auto&& solve, int v, int par, bool flag) -> value {
		if(dp[v].count(par)) return dp[v][par];
		
		value res = id;
		const int deg = g[v].size() - (par != -1);
		if(par == -1 or flag) {
			std::vector<value> ret;
			for(int i = 0; i < g[v].size(); i++) {
				int id = g[v][i];
				int to = a[id] ^ b[id] ^ v;
				if(to == par) continue;
				
				ret.push_back(solve(solve, to, v, flag) + 1.);
			}
			
			std::vector<value> R(ret.size() + 1, id);
			for(int i = (int)R.size() - 1; i > 0; i--) R[i - 1] = marge(R[i], ret[i - 1]);
			if(par == -1) {
				value L = id;
				for(int i = 0; i < g[v].size(); i++) {
					int id = g[v][i];
					int to = a[id] ^ b[id] ^ v;
					
					long double tmp = marge(L, R[i + 1]);
					if(deg - 1) tmp = tmp / (deg - 1);
					dp[v][to] = tmp;
					L = marge(L, ret[i]);
				}
			}

			if(deg) res = R[0] / deg;
		} else {
			solve(solve, v, -1, flag);

			res = solve(solve, v, par, flag);
		}

		return dp[v][par] = res;
	};
	solve(solve, 0, -1, true);

	for(int i = 0; i < n; i++) printf("%.12Lf\n", solve(solve, i, -1, false));
	return 0;
}


Measured memory_bytes: 68096
def d_remainder_reminder(N, K):
    if K==0:
        return N*N
    import bisect
    ans = 0
    for b in range(K + 1, N + 1):
        tmp1 = (N+1)//b #[0,1,2,...,b-1]のパターン何個
        tmp2 = (N+1)%b #[0,1,...,途中]のパターン
        # print(tmp1,tmp2)

        t=0 if tmp2<=K else tmp2-K
        ans += (b-K)*tmp1 + t
        # print(ans)
    return ans 

N,K = [int(i) for i in input().split()]
print(d_remainder_reminder(N, K))

Measured memory_bytes: 3060