akhauriyash/Code-Regression huggingface dataset:
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.string;

void main() {
    auto s = readln.split.map!(to!int);
    auto sx = s[0];
    auto sy = s[1];
    auto gx = s[2];
    auto gy = s[3];

    auto n = readln.chomp.to!int;
    auto a = n.iota.map!(_ => readln.split.map!(to!int).array).array;

    s = readln.split.map!(to!int);
    auto lx = s[0];
    auto ly = s[1];

    auto ng = new bool[][](lx*2+10, ly*2+10);
    foreach (i; 0..a.length) ng[a[i][0]+lx][a[i][1]+ly] = true;

    auto dist = new int[][][](lx*2+10, ly*2+10, 6);
    foreach (i; 0..lx*2+10) foreach (j; 0..ly*2+10) dist[i][j][] = 1 << 29;

    const int[] dx = [0, 1, 1, 0, -1, -1];
    const int[][] dy = [[1, 0, -1, -1, -1, 0], [1, 1, 0, -1, 0, 1]];

    auto pq = new BinaryHeap!(Array!(Tuple!(int, int, int, int)), "a[3] > b[3]");
    pq.insert(tuple(sx+lx, sy+ly, 0, 0));

    while (!pq.empty) {
        auto x = pq.front[0];
        auto y = pq.front[1];
        auto t = pq.front[2];
        auto d = pq.front[3];
        pq.removeFront;
        if (dist[x][y][t%6] <= d) continue;
        dist[x][y][t%6] = d;
        foreach (i; 0..6) {
            int nx = x + dx[i];
            int ny = y + dy[((x-lx)%2+2)%2][i];
            int nt = (t + 1) % 6;
            int nd = abs((x - lx) * (y - ly) * t) % 6 == i ? d : d + 1;
            if (nx < 0 || nx > 2 * lx || ny < 0 || ny > 2 * ly) continue;
            if (ng[nx][ny]) continue;
            if (dist[nx][ny][nt%6] <= nd) continue;
            pq.insert(tuple(nx, ny, nt, nd));
        }
        if (dist[x][y][(t+1)%6] > d + 1) {
            pq.insert(tuple(x, y, (t+1)%6, d+1));
        }
    }

    int ans = dist[gx+lx][gy+ly].reduce!min;
    writeln(ans == 1 << 29 ? -1 : ans);
}



Measured memory_bytes: 5364
k = int(input())
if k == 0:
    print("2\n1 1")
    exit(0)
if k == 1:
    print("2\n2 0")
    exit(0)
n = min(50,k)
a = [i for i in range(n)]
c = k // n

for i in range(n):
    a[i] += c

for i in range(k % n):
    a[i] += n
    for j in range(n):
        if i != j:
            a[j] -= 1
print(n)
for i in a:
    if i in range(10**16 + 1001):
        print(i, end=' ')
    else:
        exit(1)
print()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)

using namespace std;

void solve(int N, int M, int X, vector<int> A) {
  sort(A.begin(), A.end());
  int cost_to_0 = 0;
  int cost_to_N = 0;
  rep(i, M)
    if (A[i] < X)
      cost_to_0++;
    else
      cost_to_N++;
  cout << min(cost_to_0, cost_to_N) << endl;
}

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

  int N, M, X;
  cin >> N >> M >> X;
  vector<int> A(M);
  for(int i = 0 ; i < M ; i++){
    cin >> A[i];
  }
  solve(N, M, X, move(A));
  return 0;
}


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

struct pt
{
    ll x,y; 
};

bool cmp1( pt a, pt b )
{
    return -a.x-a.y>-b.x-b.y;
}

bool cmp2( pt a, pt b )
{
    return a.x+a.y>b.x+b.y;
}

bool cmp3( pt a, pt b )
{
    return -a.x+a.y>-b.x+b.y;
}

bool cmp4( pt a, pt b )
{
    return a.x-a.y>b.x-b.y;
}

ll dist( pt a, pt b )
{
    return abs(a.x-b.x)+abs(a.y-b.y);
}

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

    pt arr[n+5];

    for( int i=0;i<n;i++ )
        cin>>arr[i].x>>arr[i].y;

    std::vector<pt> v;
    sort( arr, arr+n, cmp1 );
    v.push_back(arr[0]);
    sort( arr, arr+n, cmp2 );
    v.push_back(arr[0]);
    sort( arr, arr+n, cmp3 );
    v.push_back(arr[0]);
    sort( arr, arr+n, cmp4 );
    v.push_back(arr[0]);
    
    ll ans= 0;

    for( auto x: v )
        for( auto y: v )
            ans= max( ans, dist(x,y) );

    cout<< ans <<"\n";
}


Measured memory_bytes: 6728
#include<bits/stdc++.h>
using namespace std;
 
using ll = long long;
using pll = pair<ll, ll>;
#define all(x) (x).begin(), (x).end()
#define call(x) (x).cbegin(), (x).cend()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back
#define sz(x) ((x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
const double PI = acos(-1);
const int mod = 1e9+7;
const long long INF = (1LL << 60);
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}
ll ceil(ll a, ll b){return ((a)+(b)-1)/b;}
template<class T> inline bool chmax(T &a, const T &b){ if(a < b){ a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(a > b){ a=b; return 1; } return 0; }

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

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

  vector<ll> sum;
  rep(i, 0, n){
    sum.pb(a[i] - (i+1));
  }
  sort(all(sum));

  ll sum1 = 0;
  rep(i, 0, n){
    sum1 += abs(sum[i] - sum[n/2]);
  }
  cout << sum1 << endl;
  return 0;
}

Measured memory_bytes: 3956
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <random>
#include <cstdio>
#include <cstring>
#include <cmath>

// for i in f..<t {... : as Swift
#define forin(i, f, t) for(auto i = f; i < t; i++)

using namespace std;
using ll = long long;

int main() {
    int n;
    cin >> n;
    auto count = 0;
    for (auto i = 0; i < n; i++) {
        int a;
        cin >> a;
        
        while (a % 2 == 0) {
            count++;
            a /= 2;
        }
    }
    
    cout << count << endl;
    
}



Measured memory_bytes: 256
n,m = list(map(int, input().split()))
data = [tuple(map(int, input().split())) for _ in range(m)]

rank_map={}
rank=0
p=None

for t in sorted(data):
    if p!=t[0]:
        p=t[0]
        rank=1
    rank_map[t]='%06d%06d' % (t[0], rank)
    rank+=1

for t in data:
    print(rank_map[t])



Measured memory_bytes: 32148
N = int(input())
A = list(map(int, input().split()))

"""
1.特定の山に降った雨の量を計算する（とりあえず1つだけ）
S = sum(A)
X1 = S − 2(A2 + A4 + ... + AN−1)

2.以降の山も順次求めていく
Xi + Xi+1 = 2Ai 
Xi+1 = 2Ai − Xi
"""

## 1.特定の山に降った雨の量を計算する（とりあえず1つだけ）
X1 = sum(A) - 2 * sum([A[i] for i in range(1,N,2)])
ans = [X1]

## 2.以降の山も順次求めていく
for n in range(1,N,1):
  _ = 2 * A[n-1] - ans[n-1]
  ans.append(_)


print(*ans)

Measured memory_bytes: 14028
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <queue>

using namespace std;

int main(){
	
	int a[3], b[2];
	
	cin >> a[0] >> a[1] >> a[2] >> b[0] >> b[1];
	
	sort(a, a + 3);
	sort(b, b + 2);
	
	cout << a[0] + b[0] - 50 << endl;
	
	return 0;
}

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

int N, M;
bool graph[10][10]; // i から j への有向線があるかどうか

int main() {
    // 初期化
    for (int i = 0; i < 8; i++) {
        for(int j = 0; j < 8; j++) {
            graph[i][j] = false;
        }
    }

    cin >> N >> M;
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        graph[a][b] = graph[b][a] = true;
    }

    vector<int> v(N);
    iota(v.begin(), v.end(), 1); // v = {1,2, ..., N}
    int res = 0;

    // 1, {2, 3, ..., N} の順列
    do {
        int len = v.size();
        for ( int i = 0; i < len-1; i++ ) {
            if( not graph[ v.at(i) ][ v.at(i+1) ] )
                break;

            if(i == len-2) // 道があった
                res++;
        }
    } while( next_permutation( v.begin()+1, v.end()) );

    cout << res << endl;
}

Measured memory_bytes: 256
inp = input().split()
n = int(inp[0])
m = int(inp[1])
hyou = []
for i in range(n):
    tmp = []
    tmp_inp = input().split()
    k = int(tmp_inp[0])
    for i in range(k):
        tmp.append(int(tmp_inp[i+1]))
    hyou.append(set(tmp))


def intersect_set(list):
    result = list[0]
    for i in range(len(list)-1):
        result = result.intersection(list[i+1])
    return result

print(len(intersect_set(hyou)))


Measured memory_bytes: 3064
using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var read = "";
            while (!string.IsNullOrEmpty(read = Console.ReadLine()))
            {
                var data = read.Split().Select(s => int.Parse(s)).ToArray();

                if (data[0] == 0 && data[1] == 0) break;

                for (var i = 0; i < data[0]; i++)
                {
                    for (var j = 0; j < data[1]; j++)
                    {
                        Console.Write("#");
                    }
                    Console.WriteLine();
                }
                Console.WriteLine();
            }
        }
    }
}



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

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>
using lll = long long;
using ull = unsigned long long;
using namespace std;



int main(){
  int ii,jj,kk;

  long a,b;

  cin >> a >> b;

  long aa[3];
  aa[0] = a+b;
  aa[1] = a-b;
  aa[2] = a*b;
  long max= -1000;

  for(ii=0;ii<=2;ii++){
    if(aa[ii] > max){
      max = aa[ii];
    }
  }

  cout << max << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstring>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <queue>
#include <bitset>
#include <stack>
#include <deque>
using namespace std;
typedef pair<int, int> pii;
typedef long long LL;

int main() {
    int N, A, B;
    scanf("%d %d %d", &N, &A, &B);
    int c1 = 0, c2 = 0, c3 = 0;
    for (int i = 0; i < N; i++) {
        int tmp;
        scanf("%d", &tmp);
        if (tmp <= A) c1++;
        else if (tmp > A && tmp <= B) c2++;
        else c3++;
    }
    printf("%d\n", min({c1, c2, c3}));
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main
{
  public static void main(String args[])
  {
    Scanner in=new Scanner(System.in);
    int A=in.nextInt();
    int B=in.nextInt();
    int C=in.nextInt();
    A=A^B;
    B=A^B;
    A=A^B;
    A=A^C;
    C=A^C;
    A=A^C;
    System.out.print(A+" "+B+" "+C);
  }
}

Measured memory_bytes: 22484
package main
import (
    "bufio"
    "fmt"
    "math/big"
    "os"
    "strconv"
    "strings"
)

var sc = bufio.NewReaderSize(os.Stdin, 1024*1024*10)

func main() {
    N := getStdinInt()
    A := getStdinIntArr64()
    Abig := make([]*big.Int, N)
    for i := 0; i < N; i++ {
        Abig[i] = big.NewInt(A[i])
    }

    for i := range A {
        if A[i] == 0 {
            fmt.Println(0)
            return
        }
        if A[i] > 1000000000000000000 {
            fmt.Println(-1)
            return
        }
    }

    ans := big.NewInt(1)
    cmp := big.NewInt(1000000000000000000)

    for i := range Abig {
        ans = ans.Mul(ans, Abig[i])
        if ans.Cmp(cmp) == 1 {
            fmt.Println(-1)
            return
        }
    }

    fmt.Println(ans)
}


func getStdin() string {
    return readLine()
}
func getStdinInt() int {
    str := getStdin()
    res, _ := strconv.Atoi(str)
    return res
}
func getStdinintArr() []int {
    str := getStdin()
    list := strings.Split(str, " ")
    res := make([]int, len(list))
    for idx, v := range list {
        res[idx], _ = strconv.Atoi(v)
    }
    return res
}
func getStdinIntArr64() []int64 {
    str := getStdin()
    list := strings.Split(str, " ")
    res := make([]int64, len(list))
    for idx, v := range list {
        res[idx], _ = strconv.ParseInt(v, 10, 64)
    }
    return res
}
func readLine() string {
    buf := make([]byte, 0, 0)
    for {
        l, p, e := sc.ReadLine()
        if e != nil {
            panic(e)
        }
        buf = append(buf, l...)
        if !p {
            break
        }
    }
    return string(buf)
}

Measured memory_bytes: 15476
from itertools import accumulate
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
N,M,K=MI()
A=[0]+LI()
A=list(accumulate(A))
B=[0]+LI()
B=list(accumulate(B))
j=M
ans=0
for i in range(N+1):
  if A[i]>K:
    break
  while A[i]+B[j]>K:
    j-=1
  ans=max(ans,i+j)
print(ans)

Measured memory_bytes: 42728
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
int a[100005];
LL sum[100005];
int main(){
    int n;
    LL m;
    scanf("%d%lld", &n, &m);
    for(int i=1;i<=n;i++) scanf("%d", &a[i]);
    sort(a+1, a+1+n);
    for(int i=1;i<=n;i++) sum[i] = sum[i-1] + a[i];
    int lo = 2, hi = 2e5;
    LL d = 0, base = 2e5+1, ans = 0;
    while(lo <= hi){
        int mid = (lo+hi)/2;
        LL ways = 0, res = 0;
        for(int i=1;i<=n;i++){
            int j = lower_bound(a+1, a+1+n, mid-a[i]) - a;
            ways += n-j+1;
            res += (n-j+1)*1ll*a[i] + (sum[n] - sum[j-1]);
        }
        if(ways <= m){
            d = ways;
            ans = res;
            base = mid;
            hi = mid-1;
        }
        else{
            lo = mid+1;
        }
    }
    m -= d;

    lo = 2, hi = base-1;
    base = 0;
    while(lo <= hi){
        int mid = (lo+hi)/2;
        LL ways = 0;
        for(int i=1;i<=n;i++){
            int j = lower_bound(a+1, a+1+n, mid-a[i]) - a;
            ways += n-j+1;
        }
        if(ways-d > 0) base = mid, lo = mid+1;
        else hi = mid-1;
    }
    ans += m*1ll*base;
    printf("%lld\n", ans);
}

Measured memory_bytes: 1408
#include <stdio.h>
#include <string>
#include <algorithm>
#include <iostream>
#include <cmath>
using namespace std;

static const int MAX = 1e5;
static const long MOD = 1e9 + 7;
int n;
long A[MAX][4][4][4], ans;

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

    for ( int i = 0; i < 4; i++ ) {
        for ( int j = 0; j < 4; j++ ) {
            for ( int k = 0; k < 4; k++ ) {
                A[0][i][j][k] = 0;
                A[1][i][j][k] = 0;
                A[2][i][j][k] = 1;
            }      
        }
    }
    
    A[2][0][1][2] = 0;
    A[2][0][2][1] = 0;
    A[2][2][0][1] = 0;

    for ( int l = 3; l < n; l++ ) {
        for ( int i = 0; i < 4; i++ ) {
            for ( int j = 0; j < 4; j++ ) {
                for ( int k = 0; k < 4; k++ ) {
                    if ( (i == 0) and (j == 1) and (k == 2) ) {
                        A[l][i][j][k] = 0;
                    } else if ( (i == 0) and (j == 2) and (k == 1) ) {
                        A[l][i][j][k] = 0;
                    } else if ( (i == 2) and (j == 0) and (k == 1) ) {
                        A[l][i][j][k] = 0;
                    } else if ( (j == 2) and (k == 1) ) {
                        A[l][i][j][k] = (A[l-1][1][i][j] + A[l-1][2][i][j] + A[l-1][3][i][j]) % MOD;
                    } else if ( (i == 2) and (k == 1) ) {
                        A[l][i][j][k] = (A[l-1][1][i][j] + A[l-1][2][i][j] + A[l-1][3][i][j]) % MOD;
                    } else {
                        A[l][i][j][k] = (A[l-1][0][i][j] + A[l-1][1][i][j] + A[l-1][2][i][j] + A[l-1][3][i][j]) % MOD;
                    }
                }      
            }
        }
    }

    ans = 0;

    for ( int i = 0; i < 4; i++ ) {
        for ( int j = 0; j < 4; j++ ) {
            for ( int k = 0; k < 4; k++ ) {
                ans = (ans + A[n-1][i][j][k]) % MOD;
            }      
        }
    }
    
    printf("%ld\n", ans);
    return 0;
}


Measured memory_bytes: 256
// atcoder/abc127/C/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

typedef long long int lli;
typedef unsigned long long ull;
typedef complex<double> point;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; each (i, v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { each (i, v) is >> i; return is; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n, m;
  while (cin >> n >> m) {
    int mn = n;
    int mx = 0;
    for (int i = 0; i < m; ++i) {
      int a, b;
      cin >> a >> b;
      setmax(mx, a);
      setmin(mn, b);
    }
    cout << max(0, mn - mx + 1) << endl;
  }

  return 0;
}


Measured memory_bytes: 256
# 1-index
def segfunc(x, y):
    return max(x, y)

ide_ele = 0

class segtree:

    def __init__(self, init_val, segfunc, ide_ele):
        n = len(init_val)
        self.segfunc = segfunc
        self.ide_ele = ide_ele
        self.num = 1 << (n - 1).bit_length()
        self.tree = [ide_ele] * 2 * self.num

        for i in range(n):
            self.tree[self.num + i] = init_val[i]

        for i in range(self.num - 1, 0, -1):
            self.tree[i] = self.segfunc(self.tree[2 * i], self.tree[2 * i + 1])

    def update(self, k, x):
        k += self.num
        self.tree[k] = x
        while k > 1:
            self.tree[k >> 1] = self.segfunc(self.tree[k], self.tree[k ^ 1])
            k >>= 1

    def query(self, l, r):
        """
        [l, r)のsegfuncしたものを得る
        """
        res = self.ide_ele

        l += self.num
        r += self.num
        while l < r:
            if l & 1:
                res = self.segfunc(res, self.tree[l])
                l += 1
            if r & 1:
                res = self.segfunc(res, self.tree[r - 1])
            l >>= 1
            r >>= 1
        return res


N, K = map(int, input().split())
T = []
for i in range(N):
    a = int(input())
    T.append(a)

M = max(T)+1
A = [0]*M
s_tree = segtree(A, segfunc, ide_ele)
for i in range(N):
    a = T[i]
    p = s_tree.query(max(a - K, 0), min(a + K + 1, M))
    s_tree.update(a, p + 1)

print(s_tree.query(0, M))

Measured memory_bytes: 141628
import math

def worst_case(A, B):
    c = min(A, B)
    d = max(A, B)
    if c == d or c + 1 == d:
        return 2 * (c - 1)
    root = int(math.sqrt(A * B))
    if root ** 2 == A * B:
        root -= 1
    return 2 * (root - 1) + 1 if root * (root + 1) < A * B else 2 * (root - 1)

Q = int(input())
A = []
B = []
for i in range(Q):
    line = input().split()
    A.append(int(line[0]))
    B.append(int(line[1]))

for i in range(Q):
    print(worst_case(A[i], B[i]))

Measured memory_bytes: 3064
N,A,B=map(int,input().split())
List=[]
Correct=[]
Counter=0
n=1
M=0
while n<=N:
    M=n
    while Counter<=5:
      List.append(M%10)
      M=int(M/10)
      Counter+=1
    if A<=sum(List)<=B:
      Correct.append(n)
    List.clear()
    n+=1
    Counter=0
print(sum(Correct))

Measured memory_bytes: 3300
N = int(input())
A = list(input().split())

def BubbleSort(C, N):
    for i in range(N):
        for j in range(N-1, i, -1):
            if int(C[j][1]) < int(C[j-1][1]):
                C[j], C[j-1] = C[j-1], C[j]

    return C

def SelectionSort(C, N):
    for i in range(N):
        minj = i
        for j in range(i, N):
            if int(C[j][1]) < int(C[minj][1]):
                minj = j
        C[i], C[minj] = C[minj], C[i]
    return C

C1 = BubbleSort(A[:], N)
C2 = SelectionSort(A[:], N)
print(' '.join(map(str,C1)))
print('Stable')
print(' '.join(map(str,C2)))
if C1 == C2:
    print('Stable')
else:
    print('Not stable')



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

using namespace std;

#define countof(a) (sizeof(a)/sizeof(*a))

#define vi vector<int>
#define vvi vector<vector<int> >
#define vpi vector<pi >
#define pi pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define all(n) n.begin(), n.end()

#define FROMTO(var, from, to) for (register int var = (from), var##down = ((int)(to)) < ((int)(from));var##down ? (var >= (int)(to)) : (var <= (int)(to));var##down ? var-- : var++)
#define UPTO(var, from, to)   for (register int var = (from); var <= ((int)to); var++)
#define DOWNTO(var, from, to) for (register int var = (from); var >= ((int)to); var--)
#define FOR(var, to)          UPTO(var, 0, (to)-1)
#define DOWN(var, from)       DOWNTO(var, (from)-1, 0) 

#define INIT(var, val) FOR(i,countof(var)) var[i] = val
#define INPUT(var) FOR(i,countof(var)) cin >> var[i]
#define INPUT1(var) FOR(i,countof(var)) cin >> var[i], var[i]--

#define SORT(v) qsort(v,countof(v),sizeof(*v),int_less)
#define SORTT(v) qsort(v,countof(v),sizeof(*v),int_greater)
#define QSORT(v,b) qsort(v,countof(v),sizeof(*v),b)

#define MOD 1000000007
#define INF ((1 << 30)-1)
#define LINF ((1LL << 62)-1)

typedef uint8_t u8;
typedef uint16_t u16;
typedef uint32_t u32;
typedef uint64_t u64;
typedef int8_t s8;
typedef int16_t s16;
typedef int32_t s32;
typedef int64_t s64;

struct Comb {
    vector<vector<s64> > data;
    Comb(int n) { // O(n^2)
        data = vector<vector<s64> >(n+1,vector<s64>(n+1,1));
        UPTO(i,1,n) {
            FOR(j,i+1) {
                if (!j || j == i) data[i][j] = 1;
                else data[i][j] = data[i-1][j-1] + data[i-1][j];
            }
        }
    }
    
    s64 ncr(int n, int r) {
        return data[n][r];
    }
};

int int_less(const void *a, const void *b) {
  return (*((const int*)a) - *((const int*)b));
}
int int_greater(const void *a, const void *b) {
  return (*((const int*)b) - *((const int*)a));
}

#define mygc(c) (c)=getchar()

int ri() {
	int c,s=0,r=0;
	for(;;){ mygc(c); if(c=='-'){s=1;break;} if(c<='9'&&c>='0'){r=c-'0';break;}}
	for(;;){ mygc(c); if(c>'9'||c<'0')break; r= r* 10 + c-'0';}
	if(s)r=-r;
	return r;
}

int main() {
    int n = ri();
	int m = ri();
	int nn = 0;
	int mm = 0;
	int last = ri();
	FOR(i,n-1) {
		int a = ri();
		nn += ((s64)a-last)*(n-i-1)%1000000007*(i+1)%1000000007; nn %= 1000000007;
		last = a;
	}
	last = ri();
	FOR(i,m-1) {
		int a = ri();
		mm += ((s64)a-last)*(m-i-1)%1000000007*(i+1)%1000000007; mm %= 1000000007;
		last = a;
	}
	
	cout << (((s64)nn)*mm%1000000007) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
//constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;
constexpr int MOD = 1'000'000'007;
//inline void modAdd(LL &l, LL &r) {l = (l + r) % MOD;}

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    int n;
    cin >> n;
    VI v(n), c(n);
    REP(i,0,n) cin >> v[i];
    REP(i,0,n) cin >> c[i];
    int ans = 0;
    REP(i,0,n) ans += max(0, v[i] - c[i]);
    cout << ans << endl;
    
}

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

Measured memory_bytes: 256
s = input()
b = 'No'
for i in range(len(s)):
  if ((i%2)==0)and((s[i]=='R')or(s[i]=='U')or(s[i]=='D')):
      b = 'Yes'
  elif ((i%2)==1)and((s[i]=='L')or(s[i]=='U')or(s[i]=='D')):
      b = 'Yes'
  else:
      b = 'No'
      break

print(b)

Measured memory_bytes: 3060
#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <vector>
#include <set>
#include <map>
#include <list>
#include <cassert>
#include <unordered_map>

#define _(x) { cout << #x << " = " << x << " "; }

const double E = 1e-8;
const double PI = acos(-1);

using namespace std;
typedef long long ll;

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

    ll x, ans = 100;
    cin >> x;

    int y = 0;
    while (ans < x) {
        ans = ans + ans/100;
        ++y;
    }
    cout << y << '\n';
    return 0;
}



Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    string s;
    cin >> s;
    vector<ll> cnt(2, 0);
    rep(i, len(s)) cnt[s[i] - '0']++;
    cout << (min(cnt[0], cnt[1]) * 2) << endl;
    return 0;
}


Measured memory_bytes: 512
import java.util.*;
import java.io.*;

// Template for atcoder
public class Main {

    BufferedReader br;
    PrintWriter out;
    StringTokenizer st;
    boolean eof;
    final long MOD = 1000L * 1000L * 1000L + 7;
    private static final int[] dx = {0, -1, 0, 1};
    private static final int[] dy = {1, 0, -1, 0};

    int[] arr;
    long[][] dp;
    void solve() throws IOException {
        int N = nextInt();
        arr = nextIntArr(N);
        dp = new long[N][N];
        for (int i = 0; i < N; i++) {
            Arrays.fill(dp[i], Long.MIN_VALUE);
        }
        long res = rec(0, N - 1);
        outln(res);
    }

    long rec(int start, int end) {
        if (start > end) {
            return 0;
        }
        if (start == end) {
            return arr[start];
        }
        if (dp[start][end] != Long.MIN_VALUE) {
            return dp[start][end];
        }

        long res = arr[start] - rec(start + 1, end);
        res = Math.max(res, arr[end] - rec(start, end - 1));
        dp[start][end] = res;
        return res;
    }

    void shuffle(int[] a) {
        int n = a.length;
        for(int i = 0; i < n; i++) {
            int r = i + (int) (Math.random() * (n - i));
            int tmp = a[i];
            a[i] = a[r];
            a[r] = tmp;
        }
    }
    private void outln(Object o) {
        out.println(o);
    }
    private void out(Object o) {
        out.print(o);
    }
    public Main() throws IOException {
        br = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }
    public static void main(String[] args) throws IOException {
        new Main();
    }

    public long[] nextLongArr(int n) throws IOException{
        long[] res = new long[n];
        for(int i = 0; i < n; i++)
            res[i] = nextLong();
        return res;
    }
    public int[] nextIntArr(int n) throws IOException {
        int[] res = new int[n];
        for(int i = 0; i < n; i++)
            res[i] = nextInt();
        return res;
    }
    public String nextToken() {
        while (st == null || !st.hasMoreTokens()) {
            try {
                st = new StringTokenizer(br.readLine());
            } catch (Exception e) {
                eof = true;
                return null;
            }
        }
        return st.nextToken();
    }
    public String nextString() {
        try {
            return br.readLine();
        } catch (IOException e) {
            eof = true;
            return null;
        }
    }
    public int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }
    public long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }
    public double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }
}


Measured memory_bytes: 105688
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

struct BipartiteMatching {
	int n;
	vector<vector<int>> g;
	vector<int> match;
	vector<int> used;
	BipartiteMatching(int n) : n(n), g(n), match(n), used(n) {}
	void addEdge(int u, int v) {
		g[u].emplace_back(v);
		g[v].emplace_back(u);
	}
	int maximumMatching() {
		int cnt = 0;
		rep(i, 0, n)match[i] = -1;
		fill(match.begin(), match.end(), -1);
		for (int v = 0; v < n; v++) {
			if (match[v] == -1) {
				fill(used.begin(), used.end(), false);
				if (augment(v))cnt++;
			}
		}
		return cnt;
	}
	bool augment(int v) {
		used[v] = true;
		for (int i = 0; i < g[v].size(); i++) {
			int u = g[v][i];
			int w = match[u];
			if (w == -1 || (!used[w] && augment(w))) {
				match[v] = u;
				match[u] = v;
				return true;
			}
		}
		return false;
	}
};

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	for (int N, M, L; cin >> N >> M >> L&&N;) {
		vector<vector<int>> g(N, vector<int>(N, INF));
		rep(i, 0, M) {
			int u, v, d; cin >> u >> v >> d;
			g[u][v] = g[v][u] = d;
		}
		rep(i, 0, N)
			g[i][i] = 0;
		rep(k, 0, N)rep(i, 0, N)rep(j, 0, N) {
			if (g[i][k] != INF&&g[k][j] != INF)
				g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
		}

		vector<int> p(L), t(L); rep(i, 0, L) {
			cin >> p[i] >> t[i];
		}
		BipartiteMatching bm(L + L);
		int source = L + L, sink = source + 1;
		rep(i, 0, L) {
			rep(j, 0, L) {
				if (i == j)continue;
				if (g[p[i]][p[j]] <= t[j] - t[i]) {
					bm.addEdge(i, L + j);
				}
			}
		}
		auto ans = L - bm.maximumMatching();
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 8452
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll s;
    cin >> s;
    ll p, n;
    p = s / 100;
    n = s % 100;
    if (p >= 1 && p <= 12 && n >= 1 && n <= 12)
    {
        cout << "AMBIGUOUS" << endl;
    }
    else if (p >= 1 && p <= 12 && (n < 1 || n > 12))
    {
        cout << "MMYY" << endl;
    }
    else if (n >= 1 && n <= 12 && (p < 1 || p > 12))
    {
        cout << "YYMM" << endl;
    }
    else
    {
        cout << "NA" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
    using namespace std;
    int main(){
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        int a;
        cin>>a;
        long long val=0;
        for(int i=1;i<=a;i++){
            for(int j=1;j<=a;j++){
                for(int k=1;k<=a;k++){
                    int z=__gcd(i,j);
                    z=__gcd(z,k);
                    val+=z;
                }
            }
        }
        cout<<val;
        return 0;
    }

Measured memory_bytes: 3648
#include <iostream>
#include <iomanip>
#include <string>
#include <string.h>
#include <math.h>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <utility>
#include <deque>
#include <queue>
#include <functional>

#define rep(i, n) for(int i = 0; i < n; ++i)
#define REP(i, m, n) for(int i = m; i < n; ++i)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define RREP(i, m, n) for(int i = n; i >= m; --i)
#define llrep(i, n) for(ll i = 0; i < n; ++i)
#define llREP(i, m, n) for(ll i = m; i < n; ++i)
#define llrrep(i,n) for(ll i = n; i >= 0; --i)
#define llRREP(i, m, n) for(ll i = n; i >= m; --i)

using ll = long long;
using ull = unsigned long long;
using pii = std::pair<int, int>;
using pll = std::pair<long long, long long>;

using namespace std;

const long long _MOD = 1000000007;
const long long MOD = 998244353;

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

	ll n;
	cin >> n;

	ll ans = 0;
	llrep(i, n+1) {
		if (i % 3 != 0 && i % 5 != 0) {
			ans += i;
		}
	}

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 3660
N = int(input())
lst_1 = []
ans = 0

for n in range(N):
    lst_1.append(input().split())

for n in range(N):
    money = 0
    money = float(lst_1[n][0])
    if lst_1[n][1] == "BTC":
        money = money * 380000
    ans += money

print(ans)

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

int main(){
	int n, ma, mi, tmp, ans;
	while(cin >> n){
		if(n == 0) break;
		ma = 0;
		mi = 1001;
		ans = 0;
		for(int i = 0;i<n;i++){
			cin >> tmp;
			ans += tmp;
			mi = fmin(tmp,mi);
			ma = fmax(tmp,ma);
		}
		cout << int(ans - mi - ma)/(n-2) << endl;
	}
	return 0;
}


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

int main(){
	string s,ans;
	cin>>s;
	vector<int> a(s.size());
	for(int i=0;i<s.size();++i)a.at(i)=s.at(i)-'0';
	for(int i=0;i<(1<<s.size()-1);++i){
		int tmp=a.at(0);
		ans=s.at(0);
		for(int j=0;j<s.size()-1;++j){
			if(i&(1<<j)){
				tmp+=a.at(j+1);
				ans+='+',ans+=a.at(j+1)+'0';
			}
			else{
				tmp-=a.at(j+1);
				ans+='-',ans+=a.at(j+1)+'0';
			}
		}
		if(tmp==7){
			ans+="=7\n"s;
			break;
		}
	}
	cout<<ans;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<cassert>
#include<numeric>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
const int INF = 1001001001;
const long long LINF = 1001002003004005006ll;
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; }
typedef long long ll;
typedef pair<int,int> P;

int main(){
  ll x,k,d;
  cin >> x >> k >> d;
  if(x<0)x=-x;
  if(x/d>k)cout << x-(d*k) << endl;
  else{
    ll t = k-x/d;
    if(t%2==0)cout << x%d << endl;
    else cout << d-x%d << endl;
  }
  return 0;
}

Measured memory_bytes: 3612
N, M, Q = map(int, input().split())
dp1 = [[0] * N for _ in range(N)]
for _ in range(M):
    L, R = map(int, input().split())
    L -= 1; R -= 1
    dp1[L][R] += 1

for i in range(N):
    for j in range(N - 1):
        dp1[i][j + 1] += dp1[i][j]

for k in range(Q):
    p, q = map(int, input().split())
    ans = 0; p -= 1; q -= 1
    for i in range(p, q + 1):
        ans += dp1[i][q]
    print(ans)


Measured memory_bytes: 53744
#include <stdio.h>
int main(void)
{
 int x ,y;
  while(1){
  scanf("%d", &x);
  scanf("%d", &y);

  if(x == 0 && y == 0) break;
  
   if(x>y){
    printf("%d %d\n" ,y ,x);
    }
     else if(x<y){
      printf("%d %d\n" ,x ,y);
      }
    else{
            printf("%d %d\n" ,x ,y);
      }
}
return 0;
}


     

Measured memory_bytes: 600
#include <iostream>

using namespace std;

int
main()
{
  int N, X;
  cin >> N >> X;
  int count = 0;
  int d = 0;
  if (d <= X)
  {
    count++;
  }
  for (int i = 0; i < N; i++)
  {
    int L;
    cin >> L;
    d += L;
    if (d <= X)
    {
      count++;
    }
  }
  cout << count << endl;
  return 0;
}


Measured memory_bytes: 256
x, k, d = map(int, input().split())
cur = x
numTimes = x // d
if numTimes == 0:
    cur -= d
    k -= 1
else:
    numTimes = min(abs(numTimes), k)
    if x < 0:
        numTimes *= -1
    cur -= numTimes * d
    k -= numTimes
if k % 2 == 0:
    print(abs(cur))
else:
    result = min(abs(cur - d), abs(cur + d))
    print(result)

Measured memory_bytes: 61860
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <tuple>
#include <cstdio>
#include <cassert>
#include <functional>
#define _LIBCPP_DEBUG 0
using namespace std;

int main(void){

    vector<long long> lyu(87);
    lyu.at(0)=2;
    lyu.at(1)=1;
    for (int i = 2; i < 87; i++)
    {
        lyu.at(i)=lyu.at(i-1)+lyu.at(i-2);
    }
    
    long long n;
    cin >> n;
    cout << lyu.at(n) << endl;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reprev(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
typedef long long ll;

int main()
{
    int n, q, q1, q2, q3;
    string s;
    cin >> n >> s >> q;

    vector<set<int>> is(26);
    rep(i, n) { is[s[i] - 'a'].insert(i); }

    rep(i, q)
    {
        cin >> q1 >> q2;
        if (q1 == 1)
        {
            char c;
            cin >> c;
            int i = q2 - 1;
            is[s[i] - 'a'].erase(i);
            s[i] = c;
            is[s[i] - 'a'].insert(i);
            // s[q2 - 1] = c;
            //cout <<s << endl;
        }
        else
        {
            cin >> q3;
            int l = q2 - 1;
            int ans = 0;
            rep(i, 26)
            {
                auto it = is[i].lower_bound(l);
                if (it != is[i].end() && *it < q3)
                    ans++;
            }
            cout << ans << endl;

            // sub = s.substr(q2 - 1, q3 - q2 + 1);
            // set<char> se(sub.begin(), sub.end());
            //cout <<q1<<q2<<sub<< se.size() << endl;
            //cout << se.size() << endl;
        }
    }
}


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

auto chmin = [](auto&& l, auto r) { return r < l ? l = r, 1 : 0; };

template <class T> struct dijkstra {
  struct edge {
    int to;
    T w;
  };
  vector<vector<edge>> g;
  const T inf;
  dijkstra(int n, T _inf = numeric_limits<T>::max()) : g(n), inf(_inf) {}
  void add_edge(int from, int to, T w) { g[from].push_back({to, w}); }
  void add_undirected_edge(int u, int v, T w) {
    add_edge(u, v, w), add_edge(v, u, w);
  }
  vector<T> run(int s) const {
    vector<T> dist(g.size(), inf);
    priority_queue<pair<T, int>, vector<pair<T, int>>, greater<>> pq;
    pq.emplace(dist[s] = 0, s);
    while (not pq.empty()) {
      T d;
      int v;
      tie(d, v) = pq.top(), pq.pop();
      if (d > dist[v]) continue;
      for (auto e : g[v])
        if (chmin(dist[e.to], dist[v] + e.w)) pq.emplace(dist[e.to], e.to);
    }
    return dist;
  }
};

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, m;
  while (cin >> n >> m, n) {
    dijkstra<int> g(n);
    struct edge {
      int u, v, d, c;
    };
    vector<edge> es(m);
    while (m--) {
      int u, v, d, c;
      cin >> u >> v >> d >> c;
      --u, --v;
      g.add_undirected_edge(u, v, d);
      es[m] = {u, v, d, c};
    }
    auto dist = g.run(0);
    vector<int> mn(n, g.inf);
    mn[0] = 0;
    for (auto e : es) {
      for (int _ = 2; _--; ) {
        if (dist[e.u] + e.d == dist[e.v]) {
          chmin(mn[e.v], e.c);
        }
        swap(e.u, e.v);
      }
    }
    int res = accumulate(begin(mn), end(mn), 0);
    cout << res << '\n';
  }
}



Measured memory_bytes: 4260
n = int(input())
a =list(map(int,input().split()))
d = [0]*(n+1)
answer = 0
for i in range(n):
  d[a[i]]+=1
for j in range(n+1):
  answer+= (d[j]*(d[j]-1))//2
for k in range(n):
  print(answer+1-(d[a[k]]))

Measured memory_bytes: 32324
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define IOS ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define PI acos(-1)
#define EPS 1e-5
#define sz(v) ((int)(v).size())
#define all(v) v.begin(),v.end()
#define forn(i, n) for(ll i=0;i<(ll)n;i++)
#define fi first
#define se second



int main() {
	string s, t;
	cin >> s >> t;
	int n = sz(s);
	int m = sz(t);
	vector<vector<int>> dp(n+1, vector<int>(m+1, 0));
	vector<vector<pii>> prev(n+1, vector<pii>(m+1));
	for(int i = 1; i <= n; i++){
		for(int j = 1; j <= m; j++){
			if(s[i-1]==t[j-1]){
				dp[i][j] = dp[i-1][j-1]+1;
				prev[i][j] ={i-1,j-1};
			}else if(dp[i-1][j] >= dp[i][j-1]){
				dp[i][j] = dp[i-1][j];
				prev[i][j] = {i-1,j};
			}else{
				dp[i][j] = dp[i][j-1];
				prev[i][j] = {i,j-1};
			}
		}
	}
	string ans(dp[n][m],'0');
	int i = n, j = m, ind = dp[n][m]-1;
	while(i > 0 && j > 0){
		if(s[i-1] == t[j-1]){
			ans[ind] = s[i-1];
			i--,j--,ind--;
		}else if(dp[i-1][j] > dp[i][j-1])
			i--;
		else j--;
	}
	cout << ans << endl;
	return 0;

}



Measured memory_bytes: 105984
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

typedef long long ll;

int max(int a, int b){
  if(a > b) return a;
  else return b;
}
int min(int a, int b){
  if(a < b) return a;
  else return b;
}

int sort(const void *a ,const void *b){
  return *(int*)a - *(int*)b;
}

int main(){

  ll n;
  scanf("%lld",&n);

  char ans[12];
  int index = 0;
  while(n > 0){
    ans[index] =  'a' + (n + 25) % 26;
    if(n % 26 == 0) n -= 1;
    n /= 26;
    index++;
  }

  for(int i = index-1; i >= 0 ; --i){
    printf("%c",ans[i]);
  }


  return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <string>
#include <algorithm>
#define rep(i, n) for (int i=0; i<n; ++i)
using namespace std;

int main() {
    string s;
    int q;
    cin >> s >> q;

    bool is_r = false;
    string pre_s, post_s;
    rep(i, q) {
        int t;
        cin >> t;
        if (t == 1) {
            is_r = !is_r;
        } else if (t == 2) {
            int f;
            char c;
            cin >> f >> c;
            if (f == 1) {
                if (is_r) {
                    post_s += c;
                } else {
                    pre_s = c + pre_s;
                }
            } else if (f == 2) {
                if (is_r) {
                    pre_s = c + pre_s;
                } else {
                    post_s += c;
                }
            }
        }
    }

    if (is_r) {
        rep(i, post_s.size()) cout << post_s[post_s.size()-i-1];
        rep(i, s.size()) cout << s[s.size()-i-1];
        rep(i, pre_s.size()) cout << pre_s[pre_s.size()-i-1];
    } else {
        cout << pre_s;
        cout << s;
        cout << post_s;
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 1152
#include <stdio.h>
int main (){
  int k,n,m,v[100],re,i,j,max,rest;

  while(1){

    scanf("%d %d",&n,&m);

    if(n==0 && m==0)break;

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

    max=0;

    for(j=0;j<m;j++){
      if(max<v[j]){
	max=v[j];
      }
    }

    rest=m;
    
    for(k=max;k>=0;k--){
      for(j=0;j<m;j++){
	if(v[j]==k){
	  rest--;
	  if(rest==0) printf("%d",j+1);
	  else printf("%d ",j+1);
		 }
      }
    }
    printf("\n");
    
  }
  
  return 0;
  
}

Measured memory_bytes: 604
def main():
    div=[]
    a,b,c=map(int,input().split())
    for i in range(1,c+1):
        if c%i==0:
            div.append(i)
        
    count=0
    for i in div:
        if a<=i <=b:
            count+=1
    
    print(count)
    
 
if __name__ == '__main__':
    main()


Measured memory_bytes: 5600
#include <iostream>
using namespace std;
int main(){
  
  int i;
  string s;
  cin>>s;
  
  if(s=="SUN")
    cout<<"7";
  
  else if(s=="MON")
    cout<<"6";
  
  else if(s=="TUE")
    cout<<"5";
  
  else if(s=="WED")
    cout<<"4";
  
  else if(s=="THU")
    cout<<"3";
  
  else if(s=="FRI")
    cout<<"2";
  
  else cout<<"1";
  
  
  return 0;
}

Measured memory_bytes: 3132
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>
#include<bitset>
#include<cassert>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long int;

const int inf = 1001001000;
const long long int Inf = 1001001001001001000;



void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(vector<long long int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}

// int main(){
// 	ll a;
// 	double b;
// 	cin >> a >> b;
// 	ll b_ = b * 100;
// 	cout << a * b_ / 100 << endl;

// 	return 0;
// }

//素因数分解をする関数.
map<long long int, int> prime_factorization(long long int a)
{
	map<long long int, int>ans;
	for (long long i = 2; i*i <= a; ++i) {
		while (a%i == 0) {
			ans[i]++;
			a /= i;
		}
	}
	if (a != 1)ans[a]++;
	return ans;
}

int main(){
	ll n;
	cin >> n;
	map<ll, int> fact = prime_factorization(n);
	ll ans = 0;
	for (auto x:fact){
		int i = 1;
		while((i+1)*(i+2)/2 <= x.second){
			i++;
		}

		ans += i;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3580
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
typedef long long ll;

using namespace std;

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

  int K = 0;
  int i = min(a, b);
  for (; i > 0; i--){
    if (a % i == 0 && b % i == 0) K++;
    if (k == K) {
      cout << i << endl;
      break;
    }
  }

}


Measured memory_bytes: 256
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int co[2020][2020][2];//BW=BW
int dp[2020][2020];
int main(){
	int n;
	cin>>n;
	vp in(n*2);
	vvi to(n,vi(2));
	rep(i,n*2){
		char c;int a;
		cin>>c>>a;
		a--;
		in[i]={a,c=='W'};
		to[a][c=='W']=i;
	}
	rep(q,2)rep(i,n){
		int c=0;
		rep(j,i)if(to[j][q]<to[i][q])c++;
		if(!q)co[i][0][q]=to[i][q]-c;
		else co[0][i][q]=to[i][q]-c;
		rep(j,n){
			if(to[j][!q]<to[i][q])c++;
			if(!q)co[i][j+1][q]=to[i][q]-c;
			else co[j+1][i][q]=to[i][q]-c;
		}
	}
	rep(i,n+1)rep(j,n+1)dp[i][j]=inf;
	dp[0][0]=0;
	rep(i,n+1)rep(j,n+1){
		if(i+1<=n)cmin(dp[i+1][j],dp[i][j]+co[i][j][0]);
		if(j+1<=n)cmin(dp[i][j+1],dp[i][j]+co[i][j][1]);
	}
	cout<<dp[n][n]<<endl;
}










Measured memory_bytes: 47872