akhauriyash/Code-Regression huggingface dataset:
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())

N,M = MI()


class WarshallFloyd():
    def __init__(self,N):  # Nは頂点の個数
        self.N = N
        self.d = [[float('inf')]*N for i in range(N)]  # d[i][j] = iからjへの最短距離,0-indexed
    def add(self,u,v,c,directed = False):
        if directed is False:  # 無向グラフの場合
            self.d[u][v] = c
            self.d[v][u] = c
        else:  # 有向グラフの場合
            self.d[u][v] = c
    def WarshallFloyd_search(self):
        for k in range(self.N):
            for i in range(self.N):
                for j in range(self.N):
                    self.d[i][j] = min(self.d[i][j],self.d[i][k] + self.d[k][j])
        return self.d


W = WarshallFloyd(N)
edges = [0]*M
for i in range(M):
    a,b,c = MI()
    W.add(a-1,b-1,c,directed=False)
    edges[i] = (a-1,b-1,c)
for i in range(N):
    W.add(i,i,0)

W.WarshallFloyd_search()

ans = 0
for i in range(M):
    a = 0
    for j in range(N):
        if W.d[j][edges[i][1]] == W.d[j][edges[i][0]] + edges[i][2]:
            a = 1
    if a == 0:
        ans += 1

print(ans)


Measured memory_bytes: 74376
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

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

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

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

int main()
{
    string S;
    cin >> S;
    ll ans;
    ll cnt = 0;
    for (int i = 0; i < S.size(); i++)
    {
        if (i % 2 == 0)
        {
            if (S[i] != '0')
                cnt++;
        }
        else
        {
            if (S[i] != '1')
                cnt++;
        }
    }
    ans = cnt;
    cnt = 0;
    for (int i = 0; i < S.size(); i++)
    {
        if (i % 2 == 0)
        {
            if (S[i] != '1')
                cnt++;
        }
        else
        {
            if (S[i] != '0')
                cnt++;
        }
    }
    ans = min(ans, cnt);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		try (BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {
			char[] s = br.readLine().toCharArray();
			int ans = s[0] + s[1] + s[2] - 3 * '0';
			System.out.println(ans);
		}
	}
}


Measured memory_bytes: 21332
from itertools import combinations

N = int(input())
S = [input() for _ in range(N)]

M = len(list(filter(lambda x: x[0] == 'M', S)))
A = len(list(filter(lambda x: x[0] == 'A', S)))
R = len(list(filter(lambda x: x[0] == 'R', S)))
C = len(list(filter(lambda x: x[0] == 'C', S)))
H = len(list(filter(lambda x: x[0] == 'H', S)))

march = ['M', 'A', 'R', 'C', 'H']
ans = 0
for a, b, c in combinations(march, 3):
    ans += eval(a) * eval(b) * eval(c)

print(ans)


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

#ifdef RUBICK
#include "dbg.h"
#endif

using namespace std;
using namespace __gnu_pbds;

template<class T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;

int main() {
    int arr[3];
    scanf("%d %d %d", arr, arr+1, arr+2);

    sort(arr, arr+3);

    if (arr[0] == 5 && arr[1] == 5 && arr[2] == 7)
        puts("YES");
    else
        puts("NO");

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <set>
#include <cmath>
#include <algorithm>
#include <string>
#include <utility>
#include <map> 
#include <queue>
#include <stack>
#include <iomanip>
#include <sstream>
#define MP make_pair
#define PB push_back
#define S size()
#define B begin()
#define E end()
#define ll long long
#define REP(i,a,n) for(ll i=a; i<n; ++i)
#define RED(i,n,a) for(ll i=n; i>=a; --i)
#define m9 1000000007
#define endl "\n"
#define F first
#define SE second
#define ld long double



using namespace std;

ll gcd(ll a, ll b){
    if(a%b==0){
        return b;
    }
    else{
        return gcd(b, a%b);
    }
}
ld area(ld x1, ld y1, ld x2, ld y2, ld x3, ld y3){
    return abs(x1*(y2-y3)+x2*(y3-y1)+x3*(y1-y2))/2;
}
ld dp[2*2999+1][2999+1];

int main(){
    //freopen("input.txt", "r", stdin); 
    //freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);
   ll n;
   cin>>n;
   
   REP(i,0,2*n+1){
       REP(j,0,n+1){
           dp[i][j]=0;
       }
   }
   dp[n][0]=1;
   REP(i,1,n+1){
       ld p;
       cin>>p;
       REP(j,0,2*n+1){
           if(ceil(dp[j][i-1])!=0){
               if(j+1<2*n+1){dp[j+1][i]+=(p*dp[j][i-1]);}
               if(j-1>=0){dp[j-1][i]+=((1-p)*dp[j][i-1]);}
           }
       }
       
   } 
   ld ans=0;
   REP(i,n+1, 2*n+1){
       ans+=dp[i][n];
   }
   cout<<fixed<<setprecision(20)<<ans;

}


Measured memory_bytes: 281472
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
	
	static class Dice {

		private int[] sides;

		private static int[][] eastTable = {
				{6, 2, 4, 1, 3, 6},
				{3, 6, 0, 5, 6, 2},
				{1, 5, 6, 6, 0, 4},
				{4, 0, 6, 6, 5, 1},
				{2, 6, 5, 0, 6, 3},
				{6, 3, 1, 4, 2, 6}
		};

		private static Dice getDice(String line) {
			Dice dice = new Dice();
			String[] sides = line.split(" ");
			dice.sides = new int[sides.length];
			for (int i = 0; i < sides.length; i++) {
				dice.sides[i] = Integer.parseInt(sides[i]);
			}
			return dice;
		}

		public static int getEast(Dice dice, String line) {
			String[] nums = line.split(" ");
			int tnum = Integer.parseInt(nums[0]);
			int snum = Integer.parseInt(nums[1]);
			boolean tflag = false;
			boolean sflag = false;
			int top = 0;
			int south = 0;
			int[] sides = dice.sides;
			for (int i = 0; i < sides.length; i++) {
				if (tnum == sides[i]) {
					top = i;
					tflag = true;
					if (sflag) {
						break;
					}
				} else if (snum == sides[i]) {
					south = i;
					sflag = true;
					if (tflag) {
						break;
					}
				}
			}
			
			return sides[eastTable[top][south]];
		}
	}

	public static void main(String[] args) {
		try {
			StringBuilder output = new StringBuilder();
			String lb = System.getProperty("line.separator");
			
			BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
			Dice dice = Dice.getDice(input.readLine());
			int q = Integer.parseInt(input.readLine());
			
			for (int i = 0; i < q; i++) {
				String line = input.readLine();
				output.append(String.valueOf(Dice.getEast(dice, line))).append(lb);
			}
			System.out.print(output);
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}

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

lint gcd(lint x, lint y) {
  if(x == 0) { return y; }
  else { return gcd(y%x,x); }
}

lint lcm(lint x, lint y) { return x/gcd(x,y)*y; }


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

  lint ans;
  if((b-a)%2 == 1) {
    ans = min(a-1,n-b) + 1 + (b-a-1)/2;
  } else if((b-a)%2 == 0) {
    ans = (b-a)/2;
  }

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

Measured memory_bytes: 256
n = gets.to_i
a = []
n.times{ a << gets.to_i }
dp =  Array.new
dp << -1
n.times do |i|
  if dp.last < a[i]
    dp << a[i]
  else
    left = 0
    right = dp.size - 1
    mid = 0
    while left <= right
      mid = (left + right)/2
      if a[i] >= dp[mid]
        left = mid + 1
      else
        right = mid - 1
      end
    end
    if dp[right] < a[i] && dp[right+1] > a[i]
      dp[right+1] = a[i]
    end
  end
end
p dp.size - 1

Measured memory_bytes: 10496
#include <bits/stdc++.h>
#define Rep(i,j,n) for(int i=j; i<n; i++)
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100//000000000
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define P pair<int, int>
#define PP pair<P,P>
#define T tuple<int,int,int> 
using namespace std;

int main(){
    int n; cin >> n;
    int ans=INF;
    queue<P> q;
    q.emplace(n,0);
    while(!q.empty()){
        int f=q.front().first;
        int c=q.front().second;
        q.pop();
        if(f<=5){
            ans=min(ans,c+f);
            continue;
        }
        int now=1;
        int now2=1;
        while(now*9<=f) now*=9;
        while(now2*6<=f) now2*=6;
        q.emplace(f-now,c+1);
        q.emplace(f-now2,c+1);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 7596
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int a,b,c=0;
	cin>>a>>b;
	if(a+b==15)
	{
		cout<<"+"<<endl;
		c++;
	}
	if(a*b==15)
	{
		cout<<"*"<<endl;
		c++;
	}
	if(c==0) cout<<"x"<<endl;
	return 0;
}

Measured memory_bytes: 256
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::iter;
#[allow(unused_imports)]
use std::mem::*;
#[allow(unused_imports)]
use std::str::*;
#[allow(unused_imports)]
use std::usize;

#[allow(unused_macros)]
macro_rules! read_cols {
    ($($t:ty),+) => {{
        let mut line = String::new();
        stdin().read_line(&mut line).unwrap();

        let mut it = line.trim()
            .split_whitespace();

        ($(
            it.next().unwrap().parse::<$t>().ok().unwrap()
        ),+)
    }}
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let mut line = String::new();
    stdin().read_line(&mut line).unwrap();
    line.trim().to_string().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vecl<T: FromStr>(n: usize) -> Vec<T> {
    let mut v = vec![];
    for _ in 0..n {
        v.push(read::<T>());
    }

    v
}

#[allow(dead_code)]
fn read_vec<T: FromStr>() -> Vec<T> {
    let mut line = String::new();
    stdin().read_line(&mut line).unwrap();

    line.trim()
        .split_whitespace()
        .map(|s| s.parse().ok().unwrap())
        .collect()
}

fn main() {
    let s = read::<String>();

    let chars = s.chars().fold(HashSet::new(), |mut chars, c| {
        chars.insert(c);
        chars
    });

    let a = (b'a'..(b'z'+1)).map(|c| c as char).skip_while(|&c| chars.contains(&c)).next().map_or(String::from("None"), |c| c.to_string());
    println!("{}", a);
}


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

int main() {
    string S;
    int count=0;
    cin >> S;
    for (int i = 0; i < S.size(); i++) {
        if (S[i]=='o') ++count;
    }
    cout << (700 + (count*100)) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#define MAP 12
using namespace std;

int map[MAP][MAP];

bool valid(int y, int x) {
  if ((0 <= y && y < MAP) && (0 <= x && x < MAP)) {
    if (map[y][x] == 1)
      return true;
  }
  return false;
}

void remove_island(int y, int x) {
  int nx, ny;
  int dx[4] = {1, 0, -1, 0};
  int dy[4] = {0, 1, 0, -1};

  map[y][x] = 0;
  for (int i = 0; i < 4; i++) {
    ny = y + dy[i];
    nx = x + dx[i];
    if ((valid(ny, nx)))
      remove_island(ny, nx);
  }
}

int main() {
  char c[MAP + 1];
  int ans;
  while (1) {
    for (int i = 0; i < MAP; i++) {
      if (!(cin >> c))
        return 0;
      for (int j = 0; j < MAP; j++) {
        map[i][j] = (int)(c[j] - '0');
      }
    }
    ans = 0;
    for (int i = 0; i < MAP; i++) {
      for (int j = 0; j < MAP; j++) {
        if (valid(i, j)) {
          remove_island(i, j);
          ans++;
        }
      }
    }
    cout << ans << endl;
  }
  return 0;
}

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


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

int n;
cin >> n;
long long t;
long double  ans = 1;
for (int i = 0; i < n; i++)
{
    cin >> t;
    if (ans != -1)
       ans *= t;
    if (ans > 1000000000000000000 || ans < 0)
       ans = -1;
    if (t == 0)
       ans = 0;
}
cout << (long long)ans;
return 0;
}

Measured memory_bytes: 3580
N = gets.chomp.to_i
A = gets.chomp.split().map(&:to_i)
s = []
right =  A.inject(:+)
left = 0
 
N.times do |n|
  right -= A[n]
  left += A[n]
  s.push( (right - left).abs )
end
puts s.min

Measured memory_bytes: 1788
#include<iostream>
using namespace std;
int main(){
	int N,M;
		cin >> N;
	M = N;
	int S = 0;
	while(M != 0){
		S += M % 10;
		M /= 10;
	}
	if(N % S)
		cout << "No" << endl;
	else
		cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int n;
    cin >> n;
    vector<int> A(n);
    rep(i, n) cin >> A[i];
    sort(All(A));
    int a, b;
    a = A[n - 1];
    int half = a / 2 + !!(a % 2);
    int dif = INF;
    rep(i, n) {
        if(dif > abs(half - A[i])) {
            dif = abs(half - A[i]);
            b = A[i];
        }
    }
    cout << a << " " << b << endl;
    return 0;
}

Measured memory_bytes: 640
import itertools

def powpow(xl,yl):
    tmp = pow(xl[0]-yl[0], 2) + pow(xl[1]-yl[1], 2)
    dist = pow(tmp, 0.5)
    return dist


def main():
    n = int(input())
    num_list = [list(map(int, input().split())) for _ in range(n)]

    sum = 0

    ls = []
    for i in range(n):
        ls.append(i+1)

    p_list = list(itertools.permutations(ls, n))

    for i in range(len(p_list)):
        for j in range(n-1):
            xl = num_list[p_list[i][j] - 1]
            yl = num_list[p_list[i][j+1] - 1]
            sum += powpow(xl,yl)

    print(sum/len(p_list))

if __name__ == '__main__':
    main()

Measured memory_bytes: 45296
#include<stdio.h>

int main()
{
    int a, b, c, k, sum = 0, n, m;
    scanf("%d %d %d %d", &a, &b, &c, &k);
    if(a >= k){
        sum = k;
    }
    else{
        sum = a;
        n = k - a;
        if(b >= n){
            sum = sum ;
        }
        else{
            m = n - b;
            sum = sum - m;
        }
    }
    printf("%d", sum);

    return 0;
}

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

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
 
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
 
#define VV(T) vector<vector< T > >
 
template <class T>
void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
    v.assign(a, vector<T>(b, t));
}

#define reep(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  reep(i,0,n)
#define clr(a) memset((a), 0 ,sizeof(a))
#define ALL(a) a.begin(),a.end()
#define PB push_back

const int INF = (1e9);
const ll MOD = 1e9+7;
const double EPS = 1e-5;
const double PI=atan2(0,-1);

int main(void){
    string a,b;
    cin >> a >> b;
    rep(i,b.size()){
        cout << a[i] << b[i];   
    }
    if(a.size()-b.size()){
        cout << a[a.size()-1];
    }
    cout << endl;
}

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

int64 dp[110][2][4];

int main() {
    string S; cin >> S;
    int K; cin >> K;
    int N = S.size();
    dp[0][0][0] = 1;
    rep(i, N) rep(j, 2) rep(k, 4) {
        int64 pre = dp[i][j][k];
        if(pre == 0) continue;
        int x = j ? 9 : S[i] - '0';
        if(k == K) {
            dp[i + 1][1][k] += pre;
        } else {
        rep(d, x + 1) {
            int nk = d ? k + 1 : k;
            dp[i + 1][j || d < x][nk] += pre;
        }
        }
    }
    int64 ans = dp[N][0][K] + dp[N][1][K];
    cout << ans << '\n';
    return 0;
}

// overflow
// corner cases


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


using namespace std;
using namespace __gnu_pbds;

#define int long long int
#define pb push_back
#define M 1000000007
#define ff first
#define ss second
#define deb(x) cout< #x< " "< x< endl;
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(int i=k;i<=n;i++)
#define FORR(a,b,c) for(int a= b;a>=c;a--)
#define fa(arrr) for(auto x:arrr)
#define sz size()
// #define mp make_pair
#define mxm3(a,b,c) max(a, max(b,c))
#define mi3(a,b,c) min(a, min(b,c))
#define MAX 100005
#define PII pair<int,int>
#define all(v) v.begin(), v.end()
#define endl "\n"
#define fast ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL);


typedef tree<pair<int, int>,
        null_type,
        less<pair<int, int>>,
        rb_tree_tag,
        tree_order_statistics_node_update> oset;

//126271
// 107897


int lcm(int a, int b) {
	int x = (a * b) % M;
	return x / __gcd(a, b);
}

int ceil(int a, int b) {
	if (a % b != 0) return a / b + 1;
	return a / b;
}

oset s;
int cnt = 0;

int freq(vector<int>arr, int l, int r, int x , map<int, vector<int>>mp) {
	int a = lower_bound(all(mp[x]), l) - mp[x].begin();
	int b = upper_bound(all(mp[x]), r) - mp[x].begin();

	return b - a;
}

string func(string x, string y, int n, int m){
	vector<vector<int>>dp(n+1, vector<int>(m+1,0));
	for(int i = 0;i<=n;i++){
		for(int j = 0;j<=m;j++){
			if(i==0 || j == 0) dp[i][j] = 0;
			else if(x[i-1] == y[j-1]) dp[i][j] = 1+ dp[i-1][j-1];
			else dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
		}
	}
	string ans = "";
	int i = n, j = m;
	while(i>0 && j>0){
		if(x[i-1]==y[j-1]){
			ans+=x[i-1];
			i--;
			j--;
			// k--;
		}
		else if(dp[i-1][j]>dp[i][j-1]) i--;
		else j--;
	}
	// for(auto x:ans) cout << x;
	reverse(all(ans));
	return ans;
}


int32_t main(){
	int t;
	// cin >> t;
	t = 1;
	while(t--){
		string x,y;
		cin >> x >> y;
		int n = (x).size();
		int m = (y).size();
		cout << func(x, y, n, m) << endl; 
	}
}



Measured memory_bytes: 70784
A, B, Q = map(long, raw_input().split())
S = [long(raw_input()) for _ in range(A)]
T = [long(raw_input()) for _ in range(B)]
X = [long(raw_input()) for _ in range(Q)]
INF = 10**11
S = [-INF]+S+[INF]
T = [-INF]+T+[INF]

def meguru_bs(array, x):
  left = 0 #array[0:left] < x
  right = len(array)-1 #array[right:] >= x
  while right - left>1:
    mid = (left+right) / 2
    if array[mid] >= x:
      right = mid
    else:
      left = mid
  return right

for x in X:
  s_right = meguru_bs(S, x)
  s_nearests = [s_right-1, s_right]
  t_right = meguru_bs(T, x)
  t_nearests = [t_right-1, t_right]
  ans = INF
  for s in s_nearests:
    for t in t_nearests:
      ans = min(ans, abs(S[s]-x)+abs(T[t]-S[s]),abs(T[t]-x)+abs(S[s]-T[t]))
  print ans


Measured memory_bytes: 21488
q = []
w = []
m, n = gets.split(" ").map(&:to_i)

m.times do
  q.push(gets.split(" ").map(&:to_i))
end

n.times do
  w.push(gets.to_i)
end

m.times do |i|
  c = 0
  n.times do |j|
    c += q[i][j] * w[j]
  end
  puts c
end



Measured memory_bytes: 6988
// practice with kaiboy
import java.io.*;
import java.util.*;

public class Main extends PrintWriter {
	Main() { super(System.out, true); }
	Scanner sc = new Scanner(System.in);
	public static void main(String[] $) {
		Main o = new Main(); o.main(); o.flush();
	}

	static final int MD = 1000000007;
	long solve(int[] aa, int n) {
		long ans = 0, sum = 0;
		for (int i = 0; i < n; i++) {
			ans = (ans + (long) aa[i] * i - sum) % MD;
			sum += aa[i];
		}
		return ans;
	}
	void main() {
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] xx = new int[n];
		int[] yy = new int[m];
		for (int i = 0; i < n; i++)
			xx[i] = sc.nextInt();
		for (int j = 0; j < m; j++)
			yy[j] = sc.nextInt();
		println(solve(xx, n) * solve(yy, m) % MD);
	}
}


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

using namespace std;

typedef unsigned int ui;
typedef long long ll;
typedef unsigned long long ull;

int main() {
	int N, A, B;
	cin >> N >> A >> B;
	int a = 0, b = 0, c = 0;
	for(int i = 0; i < N; i++) {
		int P;
		cin >> P;
		if(P <= A)
			a++;
		else if(P <= B)
			b++;
		else
			c++;
	}
	cout << min(min(a, b), c) << endl;
}


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

using namespace std;
#define ll long long
#define r(i, n) for(int i=0;i<n;i++)

int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    r(i, n) v[i] = i + 1;
    do {
        r(i, n) cout << v[i] << " \n"[i == n - 1];
    } while(next_permutation(v.begin(),v.end()));

    return 0;
}


Measured memory_bytes: 3108
# 長さNの文字列Sについて、i=2,3,...,N でのSのi文字目以降から成る文字列とSの最長共通接頭辞の長さ O(N) 
def z_algo(S):
    n = len(S)
    LCP = [0]*n
    i = 1
    j = 0
    c = 0 #最も末尾側までLCPを求めたインデックス
    for i in range(1, n):
        #i番目からのLCPが以前計算したcからのLCPに含まれている場合
        if i+LCP[i-c] < c+LCP[c]:
            LCP[i] = LCP[i-c]
        else:
            j = max(0, c+LCP[c]-i)
            while i+j < n and S[j] == S[i+j]: j+=1
            LCP[i] = j
            c = i
    LCP[0] = n
    return LCP
  
N = int(input())
S = input()

ans = 0
for i in range(N):
  SS = S[i:]
  lcp = z_algo(SS)
  for j in range(len(lcp)):
    l = min(lcp[j], j)
    ans = max(ans, l)

print(ans)

Measured memory_bytes: 52444
#include<cstdio>
#include<bits/stdc++.h>
typedef long long int ll;
#define REP(i, n) for(int i = 0; i < (n); i++)
#define FOR_IN(i, a, b) for(int i = (a); i < (b); i++)
#define BETWEEN(x, a, b) ((x) >= (a) && (x) <= (b))
#define BIT(b, i) (((b) >> (i)) & 1)
#define LOG_F 1
#define LOG(...) if(LOG_F) fprintf(stderr, __VA_ARGS__)

using namespace std;

ll pow(int x, int n){
  return n == 0 ? 1 : x * pow(x, n - 1);
}


/*

 */
int a[3];

int main(){
  REP(i,3){
    cin>>a[i];
  }

  sort(a,a+3);

  cout<<a[0]+a[1]<<endl;

  return 0;
}


Measured memory_bytes: 384
import math

def isPrime(n):
  if n == 2:
    return True
  if n % 2 == 0:
    return False

  # nの平方根まで計算する
  m = math.floor(math.sqrt(n)) + 1
  for p in range(3, m, 2):
      if n % p == 0:
        return False
  return True

if __name__ == '__main__':
    X = int(input())

    while(True):

        if isPrime(X):
            print(X)
            break
        else:
            X += 1


Measured memory_bytes: 38256
using System;

namespace C___Anti_Division
{
    class Program
    {
        static void Main (string[] args)
        {
            var input = Console.ReadLine ().Split (' ');
            var a = long.Parse (input[0]);
            var b = long.Parse (input[1]);
            var c = long.Parse (input[2]);
            var d = long.Parse (input[3]);
            var max = Math.Max (c, d);
            var min = Math.Min (c, d);
            while (true)
            {
                var r = max % min;
                if (r == 0)
                    break;

                max = min;
                min = r;
            }
            var l = c * d / min;
            var e = b - b / c - b / d + b / l;
            var f = a - 1 - (a - 1) / c - (a - 1) / d + (a - 1) / l;
            Console.WriteLine (e - f);
        }
    }
}

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

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

#define vt          vector
#define sz(x)       (int)(x).size()
#define all(x)      (x).begin(), (x).end()
#define rall(x)     (x).rbegin(), (x).rend()
#define fi          first
#define se          second

ll dp[100001];

void solve(int tc) {
    int n, W;
    cin >> n >> W;
    ll ans = 0;
    while (n--) {
        int w, v;
        cin >> w >> v;
        for (int i = W; i >= w; i--) {
            dp[i] = max(dp[i], dp[i - w] + v);
            ans = max(ans, dp[i]);
        }
    }

    cout << ans;
}

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

    int tcs = 1;
    for (int tc = 1; tc <= tcs; tc++) solve(tc);
}


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

int main(){
    int x, h, m, s;
    cin >> x;
    h = x / 3600;
    x = x - 3600 * h;
    m = x / 60;
    x = x - 60 * m;
    s = x;
    cout << h << ":" << m << ":" << s << endl;
    return 0;
}



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

int main(){
    double x1, y1, x2, y2;
    cin >> x1 >> y1 >> x2 >> y2;
    cout << fixed <<setprecision(5)<< sqrt(pow(x2 - x1, 2.0) + pow(y2 - y1, 2.0)) << endl;
    return 0;
}


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

const int N = (int)2e5 + 50;
typedef long long ll;
const ll INF = (ll)1e18;
typedef long double ld;

struct node{
    ll l, r;
    int sz;
};

int n, a[N];
stack<node> S;
ll res[2][N];

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

    cin >> n;
    for(int i = 1; i <= n; i++) cin >> a[i];

    ll cur_res = 0;
    for(int swapped = 0; swapped < 2; swapped++) {
        cur_res = 0;
        while(!S.empty()) S.pop();
        if(swapped) {
            reverse(a + 1, a + n + 1);
        }
        for(int i = n; i >= 1; i--) {
            node nd = {a[i], a[i], 1};
            while(!S.empty() && S.top().l < nd.r) {
                auto st = S.top(); S.pop();
                while(st.l < nd.r) {
                    st.l *= 4;
                    st.r *= 4;
                    cur_res += 2 * st.sz;
                }
                nd.r = st.r;
                nd.sz += st.sz;
            }
            S.push(nd);
            res[swapped][i] = cur_res;
        }
    }
    reverse(res[1] + 1, res[1] + n + 1);
//    for(int i = 1; i <= n; i++) cout << res[0][i] << " ";
//    cout << endl;
//    for(int i = 1; i <= n; i++) cout << res[1][i] << " ";
//    cout << endl;
    ll fres = INF;
    for(int i = 0; i <= n; i++) {
        fres = min(res[0][i+1] + res[1][i] + i, fres);
    }
    cout << fres << endl;

}

Measured memory_bytes: 8960
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
#import numpy as np
#from decimal import *

N, M = MAP()
X = LIST()
X.sort()
#print(X)
Y = [X[i]-X[i-1] for i in range(1, M)]
Y.sort()
#print(Y)
print(sum(Y[:M-N]) if M > N else 0)


Measured memory_bytes: 15380
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<P> Graph;

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

  string s,t,r;
  cin >> s >> t >> r;
  
  if(s[s.size()-1] == t[0] && t[t.size()-1] == r[0])
    cout << "YES" << endl;
  else
    cout << "NO" << endl;

  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
using namespace std;
#define N 220
int a[N];
int main()
{
	int n,ans=0,i;
	scanf("%d",&n);
	for(i=1;i<=2*n;i++)
		scanf("%d",&a[i]);
	sort(a+1,a+2*n+1);
	for(i=1;i<=2*n;i+=2)
		ans+=a[i];
	printf("%d\n",ans);
}

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

typedef long long ll;
const ll MOD = 1e9 + 7;
const ll inf = 1LL<<60;
const double eps = 1e-9;

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

int main()
{
    ll n;
    cin >> n;
    vector <ll> a(n), ans(n+2, inf);
    for (int i = 0; i < n; i++) cin >> a[i];

    ans[0] = 0;

    for (int i = 0; i < n; i++) {
        for (int j = 1; j <= 2; j++) {
            chmin(ans[i+j], ans[i] + abs(a[i] - a[i+j]));
        }
    }
    cout << ans[n-1] << endl;
    return 0;
}



Measured memory_bytes: 1792
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;

int n,y;

int main(){
	scanf("%d%d",&n,&y);
	for(int i=0;i<=n&&10000*i<=y;i++)
	    for(int j=0;i+j<=n&&10000*i+5000*j<=y;j++)
	        if((y-10000*i-5000*j)%1000==0&&(y-10000*i-5000*j)/1000==n-i-j){
	        	printf("%d %d %d\n",i,j,(y-10000*i-5000*j)/1000);
	        	return 0;
			}
	printf("-1 -1 -1\n");
	return 0;
}


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

using namespace std;

using ll = long long int;

#define REP(i, N) for (int i = 0; i < (N); ++i)
#define scanInt(x) int x; scanf("%d", &(x)); getchar();
#define scanLLInt(x) ll x; scanf("%lld", &(x)); getchar();
#define scanVecInt(A, N) vector<int> A(N); REP(i, N){scanf("%d", &(A[i])); getchar();}
#define scanVecLLInt(A, N) vector<ll> A(N); REP(i, N){scanf("%lld", &(A[i])); getchar();}

int main()
{
    scanVecInt(V, 9);
    int a = V[1] - V[0];
    int b = V[2] - V[0];
    int c = V[3] - V[0];
    int d = V[6] - V[0];
    bool flag = true;
    if (V[4] - V[3] != a) flag = false;
    if (V[7] - V[6] != a) flag = false;
    if (V[5] - V[3] != b) flag = false;
    if (V[8] - V[6] != b) flag = false;
    if (V[4] - V[1] != c) flag = false;
    if (V[5] - V[2] != c) flag = false;
    if (V[7] - V[1] != d) flag = false;
    if (V[8] - V[2] != d) flag = false;
    if (flag){
        puts("Yes");
    }else{
        puts("No");
    }
}


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

const int INF = 1 << 28;
int N, K, T, U, V, L;
int D[200], DL[10001];

int main() {
    cin >> N >> K >> T >> U >> V >> L;
    for (int i = 0; i < N; i++) {
        cin >> D[i];
        DL[D[i]]++;
    }
    double su = 1. / U;
    double sv = 1. / V;

    vector<bool> used(L+1, false);
    int count = 0;
    bool flag = false;
    int start;
    for (int i = 0; i < L; i++) {
        if (DL[i] > 0) count++;
        if (flag) {
            if (count > K) start = i, count = K;
            used[i] = true;
        } else {
            if (count > 0) {
                used[i] = true;
                flag = true;
                start = i;
                count--;
            }
        }

        if (flag && start + V * T == i + 1) {
            flag = false;
        }
    }

    double ans = 0;
    for (int i = 0; i < L; i++) {
        ans += used[i] ? sv : su;
    }
    printf("%.10f\n", ans);

    return 0;
}

Measured memory_bytes: 3272
"use strict"

const main = (input) => {
    const _input = input.split("\n");
    const a = _input[0];
    const s = _input[1];

    if(a >= 3200){
        console.log(s);
    } else {
        console.log("red");
    }

}

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

Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, n) for(int i = 1; i <= (int)(n); i++)
const long long INF = 1LL << 60;
const double PI=3.14159265358979323846;
int main() 
{
    int n;
    string s;
	cin >> n;
    cin >> s;
    char c;
    int a,b;
    rep(i,s.size()){
        b = s.at(i)+n;
      
        if(b>90){
          b=b-26;
        }
      	c = b;
        cout << c;
    }
    cout << endl;
}

Measured memory_bytes: 256
def main():
    N = int(input())
    dp = [1] * (N + 1)
    for i in range(2, N + 1):
        for j in range(i, N + 1, i):
            dp[j] += 1
    count = 0
    for i in range(1, N + 1):
        count += dp[i] * i
    print(count)


if __name__ == "__main__":
    main()


Measured memory_bytes: 151716
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<vector>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;

typedef long long LL;

inline int read()
{
	char c=getchar();int num=0,f=1;
	for(;!isdigit(c);c=getchar())
		f=c=='-'?-1:f;
	for(;isdigit(c);c=getchar())
		num=num*10+c-'0';
	return num*f;
}

const int N=2e3+5;
const int M=N*N;
const int mod=1e9+7;

inline void add(int &x,int y){(x+=y)>=mod?x-=mod:0;}

int ksm(int x,int k)
{
	int res=1;
	for(;k;k>>=1,x=1ll*x*x%mod)
		if(k&1) res=1ll*res*x%mod;
	return res;
}

int n,k;
int f[N][N],fac[M],ifac[M];

int C(int n,int m){return 1ll*fac[n]*ifac[m]%mod*ifac[n-m]%mod;}

int main()
{
	n=read(),k=read();
	if(k==1)
	{
		cout<<1;
		return 0;
	}
	fac[0]=1;
	for(int i=1;i<=n*k;++i) fac[i]=1ll*fac[i-1]*i%mod;
	ifac[n*k]=ksm(fac[n*k],mod-2);
	for(int i=n*k-1;~i;--i) ifac[i]=1ll*ifac[i+1]*(i+1)%mod;
	f[0][0]=1;
	for(int i=0;i<=n;++i)
	{
		for(int j=0;j<=i;++j)
		{
			if(i) add(f[i][j],f[i-1][j]);
			if(j) add(f[i][j],1ll*f[i][j-1]*C(n-i+(n-j+1)*(k-1)-1,k-2)%mod);
		}
	}
	cout<<1ll*f[n][n]*fac[n]%mod;
	return 0;
}

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

using namespace std;

long long int s=0,t,p,i,n,a;
vector <int> veca;

int main()
{
    cin >> n;
    for (i=0;i<n;i++)
    {
        cin >> a;
        veca.push_back(a);
    }
    sort(veca.begin(),veca.end());
    p=veca.size();
    for (i=0;i<p-1;i++)
    {
        s+=veca[i];
    }
    s+=veca[p-1]/2;
    cout << s << endl;
}


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

int main() {
  int N, L;
  cin >> N >> L;
  vector<string> words(N);
  
  for(int i = 0; i < N; i++) {
    cin >> words.at(i);
  }
  
  sort(words.begin(), words.end());
  
  for(int i = 0; i < N; i++) {
    cout << words.at(i);
  }
  cout << endl;
}

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

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

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


int main() {
  ll a,b;
  cin >> a >> b;
  printf("%lld\n", lcm(a,b));
  return 0;
}


Measured memory_bytes: 3772
lines = []
while line = gets
    lines << line.chomp.split(' ').map(&:to_i)
end

N = lines[0][0]

ans = 0
for i in 1..N do
  if lines[1][i-1] > lines[2][i-1] then
    ans += lines[1][i-1] - lines[2][i-1]
  end
end
  
puts ans

Measured memory_bytes: 14276
n, t, s = gets.split.map(&:to_i)
arr = n.times.map{ gets.split.map(&:to_i) }
dp = 2.times.map{ [0]*(t+1) }
ret = 0
n.times do |i|
  (t-arr[i][1]+1).times do |j|
    dp[1][j + arr[i][1]] = [dp[1][j + arr[i][1]], dp[0][j] + arr[i][0]].max if !(j + arr[i][1] > s && s > j)
  end
  ret = [ret, dp[1].max].max
  (t+1).times{ |i| dp[0][i] = dp[1][i] }
end
p ret

Measured memory_bytes: 8860
n = int(input())
a = list(map(int, input().split()))
min, max, sum = 1000000, -1000000, 0
for i in range(n):
    if a[i] >= max: max = a[i]
    if a[i] <= min: min = a[i]
    sum += a[i]
print(min, max, sum)



Measured memory_bytes: 6600
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <ratio>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <climits>
#define ll long long
#define ld long double
#define mp make_pair
#define pb push_back
#define in insert
#define vll vector<ll>
#define endl "\n"
#define pll pair<ll,ll>
#define f first
#define s second
#define FOR(i,a,b) for(int i=(a),_b=(b); i<=_b; i++)
#define int ll
#define sz(x) (ll)x.size()
#define all(x) (x.begin(),x.end())
using namespace std;

 
const ll INF = 1e12;
const ll N =(3000+5); // TODO : change value as per problem
const ll MOD = 1e9+7;

int a[N][N];
int dp[N][N][4];
void solve(){
    int n,m,K;
    cin >> n >> m >> K;
    for(int ii = 1;ii<=K;ii++){
        int i,j,v;
        cin >> i >> j >> v;
        a[i][j] = v;
    }
    for(int i = 1;i<=n;i++){
        
        dp[i][1][0] = max(dp[i-1][1][0],dp[i-1][1][1]);
        if(a[i][1] != 0)
            dp[i][1][1] = a[i][1] + max(dp[i-1][1][0],dp[i-1][1][1]);
    }
    for(int i = 2;i<=m;i++){
        for(int j = 1;j<=min(3ll,i);j++){
            if(a[1][i] != 0 && (j == 1 || dp[1][i-1][j-1] != 0))
                dp[1][i][j] = max(dp[1][i][j],dp[1][i-1][j-1] + a[1][i]);
            dp[1][i][j] = max(dp[1][i][j],dp[1][i-1][j]);
            
        } 
    }
    // cout << dp[1][2][2] << endl;
    for(int i= 2;i<=n;i++){
        for(int j = 2;j<=m;j++){
            for(int k = 1;k<=min(3ll,j);k++){
                if(a[i][j] != 0 && (k == 1 || dp[i][j-1][k-1] != 0))
                    dp[i][j][k] = max(dp[i][j][k],dp[i][j-1][k-1] + a[i][j]);
                int ma = 0;
                for(int kk = 0;kk<=3;kk++) ma = max(ma,dp[i-1][j][kk]);
                if(a[i][j] != 0 && k == 1)
                    dp[i][j][k] = max(dp[i][j][k], ma + a[i][j]);
                dp[i][j][k] = max(dp[i][j][k],dp[i][j-1][k]);
            }
            int ma = 0;
            for(int l = 0;l<=3;l++) ma =max(ma,dp[i-1][j][l]);
            dp[i][j][0] =max(dp[i][j][0],max(dp[i][j-1][0],ma));
        }
    }
    // cout << dp[2][1][1] << endl;
    // cout << dp[2][2][2] << endl;
    int ans = 0;
    for(int i = 0;i<=3;i++){
        ans = max(ans,dp[n][m][i]);
    }
    cout << ans << endl;
}
signed main(){
 
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
     // freopen(".in","r",stdin);freopen(".out","w",stdout);
    
     ll tt=1;   
     // cin >> tt;
    while(tt--){    
        solve();
    }    
}

Measured memory_bytes: 355776
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <sstream>
#include <random>
#include <utility>
#include <map>
#include <vector>
#include <queue>
#define REP(i,x) for(int i=0; i<(x); i++)
typedef long long ll;

using namespace std;

int main(int argc, const char * argv[]) {
    int k;
    cin >> k;
    int a[k];
    REP(i, k){
        cin >> a[i];
    }
    ll nmin=2,nmax=3;
    if (a[k-1] != 2) {
        cout << -1 << endl;
        return 0;
    }
    REP(i, k-1){
        ll bmin = ((nmin-1) / a[k-2-i]) +1;
        if (a[k-2-i]*bmin > nmax) {
            cout << -1 << endl;
            return 0;
        }
        ll bmax = (nmax) / a[k-2-i];
        if (a[k-2-i]*bmax < nmin) {
            cout << -1 << endl;
            return 0;
        }
        nmin = a[k-2-i]*bmin;
        nmax = (a[k-2-i]*(bmax+1)) -1;
    }
    cout << nmin << " " << nmax << endl;
    
    
    return 0;
}


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

typedef long long LL;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9+7;

int main() {
    string s;
    cin >> s;
    if(s == "AAA" || s == "BBB") {
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
    return 0;
}



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

//ATB151C
int32_t main()
{
    int n,m,i,j;
    int correctAns=0,penaltyAns=0;
    string tempInput;
    cin>>n>>m;
    int acIndex[n];
    for(i=0;i<n;i++)acIndex[i]=-1;
    int probNumInput[m];
    int probStatus[m];  //0 WA, 1 AC

    for(i=0;i<m;i++)
    {
        cin>>probNumInput[i]>>tempInput;
        probStatus[i]=(tempInput=="AC")?1:0;
    }
    //***************INPUT DONE*****************************

    map<int,vector<int>>mp;

    for(i=0;i<m;i++)
    {
        mp[probNumInput[i]].push_back(probStatus[i]);
    }
    //*********************MAP DONE**************************

    for(auto itr=mp.begin();itr!=mp.end();itr++)
    {
        vector<int> &temp=(itr->second);
        for(j=0;j<temp.size();j++)
        {
            if(temp[j]==1)
            {
                correctAns++;
                penaltyAns+=j;
                break;
            }
        }
    }
    cout<<correctAns<<" "<<penaltyAns<<"\n";
    return 0;
}

Measured memory_bytes: 13568
#include <bits/stdc++.h>
int n, m;
// std::vector<std::vector<int> > adj;

std::vector<int> v, parent, rank;

int find_set(int v) {
    if (v == parent[v])
        return v;
    return parent[v] = find_set(parent[v]);
}

void make_set(int v) {
    parent[v] = v;
    rank[v] = 0;
}

void union_sets(int a, int b) {
    a = find_set(a);
    b = find_set(b);
    if (a != b) {
        if (rank[a] < rank[b])
            std::swap(a, b);
        parent[b] = a;
        if (rank[a] == rank[b])
            rank[a]++;
    }
}


int main()
{    
    std::cin >> n >> m;
    v.assign(n, 0), parent.assign(n, 0), rank.assign(n, 0);

    for (int i = 0; i < n; ++i) {
        make_set(i);
    }

    for (int i = 0; i < m; ++i) {
        int u, v;
      	std::cin >> u >> v;
        --u, --v;
        union_sets(u, v);
    }
    std::unordered_map<int, int> map;

    for (int i = 0; i < n; ++i) {
        map[find_set(i)] += 1;
    }
    int max = std::max_element(
        map.begin(), map.end(), 
        [](const std::pair<int, int>& lhs, const std::pair<int, int>& rhs) {
            return lhs.second < rhs.second;
        }
    )->second;
    std::cout << max << '\n';

    return 0;
}


Measured memory_bytes: 13724
#include<stdio.h>
#include<string.h>
 
int main(){
  char a[200000];
  scanf("%s",a);
  int len=strlen(a);
  
  int sum=0;
  for(int i=0;i<len;i++){
    sum+=a[i]-'0';
  }
  if(sum%9!=0){
    printf("No\n");
  }else{
    printf("Yes\n");
  }
  return 0;
}

Measured memory_bytes: 1792
inputs = input().split()
n = int(inputs[0])
l = int(inputs[1])

tastes = []
minabs = abs(l)
for i in range(1, n+1):
  taste = l + i - 1
  tastes.append(taste)
  if abs(taste) < minabs:
    minabs = abs(taste)

sum = 0
for i in range(n):
  if abs(tastes[i]) != minabs:
    sum += tastes[i]

print(sum)

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



int main() {
  int n,k;
  cin >> n >> k;
  if (k==1) {
    printf("%d", 0); return 0;
  }
  printf("%d", n-k);
  return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
//#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
//#include <array>
#include <valarray>
#include <stdio.h>
//#include <random>
//#include <windows.h>
//#pragma comment(lib, "winmm.lib")
#include <algorithm>

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

long long  int nCm(long long int n, long long int m) {
	if (m == 1) {
		return n;
	}
	else {
		return n*nCm(n - 1, m - 1) / m;
	}
}

long long int npm(long long int n, long long int m) {
	if (m == 1) {
		return n;
	}
	else
		if (m == 0) {
			return 1;
		}
		else {
			return n*npm(n, m - 1);
		}
}



llint ketasu(llint a) {//桁数
	llint k = 1;
	while (true) {

		if ((a - a % 10) / 10 == 0) { break; }
		++k;
		a = (a - a % 10) / 10;
	}
	return k;
}


llint keta(llint a) {//最上位
	llint b = a;
	while (true) {

		if ((a - a % 10) / 10 == 0) { break; }
		a = (a - a % 10) / 10;
		b = a;
	}
	return b;
}

llint keta2(llint a, llint c) {//桁数目の桁
	llint b = a;
	for (llint i = 1; i<c; ++i) {

		if ((a - a % 10) / 10 == 0) { break; }
		a = (a - a % 10) / 10;
		b = a;
	}
	return b % 10;
}

llint pow10n(llint a) {//10^n
	llint s = 1;
	for (llint i = 0; i < a; ++i) {
		s *= 10;
	}
	return s;
}

llint hoge(llint a, llint b) {
	if (a%b == 0) {
		return a;
	}
	else {
		return a - a%b + b;
	}
}


int main()
{
	llint N;
	cin >> N;
	vector<llint> money(N);
	llint nedan = 2;
	for (llint i = 0; i < N; ++i) {
		cin >> money[i];
	}
	llint kosuu = money[0]-1;
	for (llint i = 1; i < N; ++i) {
		if (money[i] != nedan ) {
			kosuu += hoge(money[i], nedan) / nedan - 1;
		}
		else {
			nedan++;
		}
	}
	cout << kosuu << endl;
}

Measured memory_bytes: 1152
def dfs(s, ub, n):
    if len(s) == n:
        print(s)
    else:
        ch = "a"
        while ord(ch) < ord(ub):
            dfs(s + ch, ub, n)
            ch = chr(ord(ch) + 1)
        ub = chr(ord(ub) + 1)
        dfs(s + ch, ub, n)

def solve(n):
    dfs("", "a", n)

n = int(input())
solve(n)

Measured memory_bytes: 4340
#include <bits/stdc++.h>
using namespace std;
using ld = long double;
const ld INF = 1e20;

using edge = pair<int, ld>;
using tp = tuple<ld, int, int>;

int main()
{
	cout << fixed << setprecision(8);
	int n, m, p, a, b;
	while (cin >> n >> m >> p >> a >> b, n | m | p | a | b) {
		a--, b--;
		vector<int> t(n);
		for (int i = 0; i < n; i++) {
			cin >> t[i];
		}
		vector<vector<edge>> G(m);
		for (int i = 0; i < p; i++) {
			int x, y, z;
			cin >> x >> y >> z; x--, y--;
			G[x].emplace_back(y, z);
			G[y].emplace_back(x, z);
		}
		vector<vector<ld>> d(m, vector<ld>(1 << n, INF));
		priority_queue<tp, vector<tp>, greater<tp>> pq;
		pq.emplace(0.0, 0, a);
		while (!pq.empty()) {
			auto p = pq.top(); pq.pop();
			ld cos = get<0>(p);
			int v = get<2>(p), us = get<1>(p);
			if (d[v][us] != INF) continue;
			d[v][us] = cos;
			for (int i = 0; i < n; i++) {
				if (us & (1 << i)) continue;
				for (auto& e : G[v]) {
					if (d[e.first][us | (1 << i)] == INF) {
						pq.emplace(cos + e.second / t[i], us | (1 << i), e.first);
					}
				}
			}
		}
		ld res = INF;
		for (int i = 0; i < (1 << n); i++) {
			res = min(res, d[b][i]);
		}
		if (res == INF) puts("Impossible");
		else cout << res << endl;
	}
	return 0;
}

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

int main() {
  int H,W,h,w;
  cin >> H >> W >> h >> w;
  cout <<  H*W- h * W - (H-h) *w << endl;

}
  


Measured memory_bytes: 256