akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

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

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y){
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}

// index が条件を満たすかどうか

int main() {
	long long int n;
	cin >> n;
	long long int k;
	cin >> k;
	long long int r, s, p;
	cin >> r >> s >> p;
	string t;
	cin >> t;
	string ans;
	for (int i = 0; i < t.size(); i++) {
		if (t[i] == 'r') {
			ans = ans + 'p';
		}
		if (t[i] == 's') {
			ans = ans + 'r';
		}
		if (t[i] == 'p') {
			ans = ans + 's';
		}
	}
	long long int sum = 0;
	for (int i = 0; i < k; i++) {
		char buck = 'k';
		int  f = 0;
		for (int j = i; j < t.size(); j = j + k) {
			if (buck != ans[j]) {
				if (ans[j] == 'r') {
					sum = sum + r;
				}
				if (ans[j] == 's') {
					sum = sum + s;
				}
				if (ans[j] == 'p') {
					sum = sum + p;
				}
				f = 0;
			}
			else if(f == 1) {
				if (ans[j] == 'r') {
					sum = sum + r;
				}
				if (ans[j] == 's') {
					sum = sum + s;
				}
				if (ans[j] == 'p') {
					sum = sum + p;
				}
				f = 0;
			}
			else {
				f = 1;
			}
			buck = ans[j];
		}
	}
	cout << sum;

}

Measured memory_bytes: 696
n = int(input())
arr = list(map(int, input().split()))

dp = [0] * n
dp[1] = abs(arr[1] - arr[0])

for i in range(1, n - 1):
    dp[i + 1] = min(dp[i - 1] + abs(arr[i + 1] - arr[i - 1]), dp[i] + abs(arr[i + 1] - arr[i]))

print(dp[-1])

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


const int N = pow(10,5)+5;
int x[N]={},y[N] = {};

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

    for(int i = 0; i < n/2; ++i){
        int a,b;

        cin >> a >> b;

        x[a]++;
        y[b]++;
    }

    //cout << "a" << endl;

    int xmax = 0,ypos,ymax = 0,xpos,xxmax = 0,yymax = 0,xxpos,yypos;

    for(int i = 0; i < N; ++i){
        if(x[i] > xmax){
            xxmax = xmax;
            xxpos = xpos;
            xmax = x[i];
            xpos = i;
        }else if(x[i] > xxmax){
            xxmax = x[i];
            xxpos = i;
        }

        if(y[i] > ymax){
            yymax = ymax;
            yypos = ypos;
            ymax = y[i];
            ypos = i;
        }else if(y[i] > yymax){
            yymax = y[i];
            yypos = i;
        }
    }

    //cout << xmax << " " << ymax << " " << xxmax << " " << yymax << endl;
    //cout << xpos << " " << ypos << " " << xxpos << " " << yypos << endl;

    if(xpos != ypos){
        cout << n - xmax - ymax << endl;
    }else{
        if(xxmax > yymax){
            cout << n - xxmax - ymax << endl;//cout << "a";
        }else{
            cout << n - xmax - yymax << endl;
        }
    }


}


Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<math.h>
#include<algorithm>
#include<vector>


typedef long long ll;
using namespace std;

int main() {

	ll N;
	ll all=0;
	cin >> N;
	vector<ll> d(N, 0);

	for (int i = 0; i < N; i++) {
		cin >> d[i];
	}


	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j<N; j++) {
			all += d[i] * d[j];
		}
	}

	cout << all;

	return 0;

}

Measured memory_bytes: 256
from collections import Counter

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

even = v[::2]
odd = v[1::2]

c_even = Counter(even)
c_odd = Counter(odd)

e_max1 = [0, 0]
e_max2 = [0, 0]
o_max1 = [0, 0]
o_max2 = [0, 0]

for x, y in c_even.items():
    if y > e_max1[1]:
        e_max2 = e_max1
        e_max1 = [x, y]
    elif y > e_max2[1]:
        e_max2 = [x, y]

for x, y in c_odd.items():
    if y > o_max1[1]:
        o_max2 = o_max1
        o_max1 = [x, y]
    elif y > o_max2[1]:
        o_max2 = [x, y]


if e_max1[0] == o_max1[0]:
    print(min(n - e_max1[1] - o_max2[1], n - e_max2[1] - o_max1[1]))
else:
    print(n - e_max1[1] - o_max1[1])


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

ans = 0
for i in range(N):
    tp = min(B[i],A[i])
    ans += tp
    B[i] -= tp
    tp = min(B[i], A[i+1])
    ans += tp
    A[i+1] -= tp
print(ans)


Measured memory_bytes: 19116
import collections
from math import factorial

from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under



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

for i in range(N):
    S[i] = ''.join(sorted(S[i]))

c = collections.Counter(S)
values, counts = zip(*c.most_common())
counts = [i for i in counts if i > 1]

ans = 0
for c in counts:
    ans += cmb(c, 2)
print(int(ans))

Measured memory_bytes: 31908
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using i64 = int64_t;
using ll = long long;
int main() {
  ll a,b,v,w,t;
  cin >> a >> v >> b >> w >> t;
  ll distance = abs(a-b);
  ll speed = v - w;
  if(speed*t < distance){
    cout << "NO" << endl;
    return 0;
  }
  cout << "YES" << endl;
  return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <set>
#include <vector>
#include <algorithm>
#include <bitset>
#define ll long long
using namespace std;

ll p2(ll n,ll N){
    ll b = N;
    for(int i=1;;i++){
        if(n<b){
            return i-1;
        }
        b = b*2;
    }
}



int main(){
    
    ll A,B;
    cin>>A>>B;
   

    cout<<abs(p2(B,A))<<endl;

    return 0;
}

 



Measured memory_bytes: 256
from bisect import bisect_left, bisect_right
import sys
input = sys.stdin.readline

INF = float('inf')

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

def getLenLNDS(As):
    dp = [-INF]
    for A in As:
        if dp[-1] <= A:
            dp.append(A)
        else:
            i = bisect_right(dp, A)
            dp[i] = A
    return len(dp)-1

ans = getLenLNDS(As)

print(ans)


Measured memory_bytes: 7832
MOD = 10 ** 9 + 7
S = input()
N = len(S)

# dp[i][j] := i桁目までで13で割ったあまりがjになるものの個数

dp = [[0] * 13 for _ in range(N + 1)]
if S[-1] == '?':
    for j in range(10):
        dp[1][j] = 1
else:
    dp[1][int(S[-1])] = 1

m = 1
for i in range(2, N + 1):
    m = m * 10 % 13
    for j in range(13):
        num = '?' if S[-i] == '?' else int(S[-i])
        for k in range(10):
            if num == '?' or k == num:
                d = k * m % 13
                dp[i][j] = (dp[i][j] + dp[i - 1][(13 + j - d) % 13]) % MOD

print(dp[N][5])


Measured memory_bytes: 61916
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define all(v) v.begin(), v.end()
using in = int64_t;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const double PI=3.14159265358979323846;
const int64_t waru = 1000000007;
const in INF=1<<30;
using vec = vector<vector<vector<vector<int>>>>;


int main(){
int n;
  cin>>n;
  vector<int> a(n);
  rep(i,n) cin>>a.at(i);
  
  int min =a.at(0);
  int cnt =0;
  rep(i,n){
  if(a.at(i)>min) continue;
    min = a.at(i);
    cnt ++;
  }
  cout<<cnt;
}


Measured memory_bytes: 1152
# string
# a, b, c = input().split()
# str_list = list(input().split())

# number
# a, b, c = map(int, input().split())
# num_list = list(map(int, input().split()))

# lows
# str_list = [input() for _ in range(n)]

# many inputs
# num_list = []
# for i in range(n): num_list.append(list(map(int, input().split())))

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

l.sort(reverse = True)

ctr = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        if l[i] == l[j]:
            continue
        for k in range(j+1, n):
            if l[j] == l[k]:
                continue
            if l[i] < l[j] + l[k]:
                ctr += 1

print(ctr)

Measured memory_bytes: 9176
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>

typedef std::uint64_t u64;
typedef std::int64_t  i64;
typedef std::uint32_t u32;
typedef std::int32_t  i32;

using namespace std;

#define swap(a, b)    do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while(0)
#define repd(i, a, b) for(typeof(b) i = (a); (i) < (b); (++(i)))
#define rep(i, n)     repd(i, (0), (n))
#define dump(x)       cerr << #x << " = " << (x) << endl
#define debug(x)      cerr << "L" << __LINE__ << ": " << #x << " = " << (x) << endl

int main(int argc, const char* argv[]) {
  u64 n;
  cin >> n;
  
  vector<u64> l(n);
  u64 sum = 0;
  rep(i, n) {
    cin >> l.at(i);
    sum += l.at(i);
  }
  sort(l.begin(), l.end());
  sum -= l.back();
  
  if(sum > l.back()) { 
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  
  return 0;
}


Measured memory_bytes: 256
N = int(input())
L = sorted(list(map(int, input().split())))
ans = 0
for i in range(N):
    for j in range(i + 1, N):
        for k in range(j + 1, N):
            if L[i] + L[j] > L[k] and L[i] != L[j] and L[j] != L[k]:
                ans += 1
print(ans)


Measured memory_bytes: 9168
#line 1 "C.cpp"
#include <cstdio>
#include <algorithm>
#include <tuple>
#include <vector>

#line 1 "~/git/library/utility/make/fix_point.cpp"
/**
 * @brief ラムダ式の再帰
 * @author えびちゃん
 */

#ifndef H_make_fix_point
#define H_make_fix_point

#include <utility>

template <typename Fn>
class fix_point: Fn {
public:
  explicit constexpr fix_point(Fn&& f) noexcept: Fn(std::forward<Fn>(f)) {}

  template <typename... Args>
  constexpr decltype(auto) operator ()(Args&&... args) const {
    return Fn::operator ()(*this, std::forward<Args>(args)...);
  }
};

template <typename Fn>
static inline constexpr decltype(auto) make_fix_point(Fn&& f) noexcept {
  return fix_point<Fn>{std::forward<Fn>(f)};
}

#endif  /* !defined(H_make_fix_point) */
#line 7 "C.cpp"

int main() {
  size_t n, q;
  int m;
  scanf("%zu %d %zu", &n, &m, &q);

  std::vector<std::tuple<size_t, size_t, int, int>> abcd(q);
  for (auto& [a, b, c, d]: abcd)
    scanf("%zu %zu %d %d", &a, &b, &c, &d), --a, --b;

  std::vector<int> s(n, 0);
  int res = 0;
  make_fix_point([&](auto& dfs, size_t i) -> void {
    if (i == n) {
      int cur = 0;
      for (auto [a, b, c, d]: abcd) {
        if (s[b] - s[a] == c) cur += d;
      }
      res = std::max(res, cur);
      return;
    }

    int lb = ((i == 0)? 1: s[i-1]);
    for (int j = lb; j <= m; ++j) {
      s[i] = j;
      dfs(i+1);
    }
  })(0);

  printf("%d\n", res);
}


Measured memory_bytes: 3228
#include<bits/stdc++.h>
using namespace std;
int main(){
  cin.tie(NULL);
  ios::sync_with_stdio(false);
  int n,now=1;
  cin>>n;
  int bot[n+1];
  bool push[n+1]={false};
  for(int i=1;i<=n;i++){
    cin>>bot[i];
  }
  int sum=1;
  while(true){
    if(bot[now]==2){
      cout<<sum;
      break;
    }
    else if(push[now]==true){
      cout<<-1;
      break;
    }
    push[now]=true;
    now=bot[now];
    sum++;
  }
  cout<<'\n';
  return 0;
}


Measured memory_bytes: 768
import std.stdio;
import std.string;
import std.conv;
import std.typecons;
import std.algorithm;
import std.functional;
import std.bigint;
import std.numeric;
import std.array;
import std.math;
import std.range;
import std.container;
import std.ascii;

void main(){
  auto ip = readln.chomp;
  writeln(ip.count("o")*100+700);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  ll N;
  cin >> N;

  ll X = (100*N) / 108;

  for(ll x = max(0LL, X-1000); x<X+1000; x++){
    ll Y = x * 108 / 100;
    if(Y == N){
      cout << x << endl;
      return 0;
    }
  }

  cout << ":(" << endl;
  
  return 0;
}


Measured memory_bytes: 256
def solve():
    n = int(input())
    e = [i for i in range(1, n + 1) if i % 2 == 0]
    o = [i for i in range(1, n + 1) if i % 2 == 1]
    return len(e) * len(o)


if __name__ == "__main__":
    print(solve())


Measured memory_bytes: 38384
from collections import Counter

N, P = map(int, input().split())
S = input()

ans = 0

if P == 2 or P == 5:
    for i in range(N):
        if int(S[-1 - i]) % P == 0:
            ans += N - i
else:
    M = []
    cum = [0]

    for i in range(N):
        M.append(pow(10, i, P) * int(S[-1 - i]) % P)

    for i in range(N):
        cum.append((cum[-1] + M[i]) % P)

    C = Counter(cum)

    for v in C.values():
        ans += v * (v - 1) // 2

print(ans)

Measured memory_bytes: 19236
#include <bits/stdc++.h>
#define rep(i,a,b) for(ll i=ll(a);i<ll(b);i++)
#define irep(i,a,b) for(ll i=ll(a);i>=ll(b);i--)
#define pb push_back
#define mp make_pair
#define pll pair<ll,ll>
#define endl "\n"
using ll=long long;
using ld=long double;
using namespace std;
const ll mod= 998244353;
const ll INF = 1LL<<40;
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }

ll a[220000];
int main(){
  ll n,k,ans=0;
  cin>>k>>n;
  rep(i,0,n)cin>>a[i];
  a[n]=k+a[0];
  rep(i,0,n)ans=max(ans,abs(a[i]-a[i+1]));
  cout<<k-ans;
}



Measured memory_bytes: 1792
#[allow(unused_macros)]
macro_rules! input {
    ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } };
    ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } };
}
#[allow(unused_macros)]
macro_rules! input_inner {
    ( $ next : expr ) => { };
    ( $ next : expr , ) => { };
    ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } };
}
#[allow(unused_macros)]
macro_rules! read_value {
    ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) };
    ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) };
    ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) };
    ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 };
    ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) };
}

#[allow(unused_macros)]
macro_rules! vec_md {
    ( $ init : expr ; $ ( $ dim : expr ) ;* ) => { vec_md ! ( $ ( $ dim ) ;* => $ init ) };
    ( $ head : expr ; $ ( $ tail : expr ) ;* => $ init : expr ) => { vec ! [ vec_md ! ( $ ( $ tail ) ;* => $ init ) ; $ head ] };
    ( $ head : expr => $ init : expr ) => { vec ! [ $ init ; $ head ] };
}

fn main() {
    input! {
        n: usize, a: usize,
        x: [usize; n]
    }

    let mut dp = vec_md![0u64;n+1;n+1;2501];
    dp[0][0][0] = 1;
    for i in 0..n {
        for j in 0..n {
            for k in 0..dp[0][0].len() {
                dp[i+1][j][k] += dp[i][j][k];
                if k+x[i] < dp[0][0].len() {
                    dp[i+1][j+1][k+x[i]] += dp[i][j][k];
                }
            }
        }
    }
    let mut ret = 0;
    for j in 1..dp[0].len() {
        for k in 0..dp[0][0].len() {
            if a * j == k {
                ret += dp[n][j][k];
            }
        }
    }
    println!("{}", ret);
}


Measured memory_bytes: 67964
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**10
mod = 998244353

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    rr = []

    while True:
        M,T,P,R = LI()
        if M == 0 and T == 0 and P == 0 and R == 0:
            break
        a = [LI() for _ in range(R)]
        d = collections.defaultdict(int)
        tt = [[0,0,i] for i in range(1,T+1)]
        for m,t,p,j in a:
            if j != 0:
                d[(t,p)] += 1
                continue
            tt[t-1][0] += 1
            tt[t-1][1] += m + d[(t,p)] * 20
        tt.sort(key=lambda x: [-x[0],x[1],-x[2]])
        r = str(tt[0][2])
        c = (tt[0][0],tt[0][1])
        for p,m,t in tt[1:]:
            if c == (p,m):
                r += '='
            else:
                r += ','
            r += str(t)
            c = (p,m)
        rr.append(r)

    return '\n'.join(map(str, rr))


print(main())




Measured memory_bytes: 9348
#include<bits/stdc++.h>
#define mo 1000000007
#define maxn 1000000000000000000LL
#define pi 3.1415926535898
#define eps 1e-9 
using namespace std;
long long read(){
    long long xx=0,flagg=1;
    char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-')
        ch=getchar();
    if(ch=='-'){
        flagg=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        xx=xx*10+ch-'0';
        ch=getchar();
    }
    return xx*flagg;
}
void pus(long long xx,long long flagg){
    if(xx<0){
        putchar('-');
        xx=-xx;
    }
    if(xx>=10)
        pus(xx/10,0);
    putchar(xx%10+'0');
    if(flagg==1)
        putchar(' ');
    if(flagg==2)
        putchar('\n');
    return;
}
long long n,a,k,ans;
int main(){
	n=read();
	while(n--){
		a=read();
		k=read();
		while(a%k)
			a-=((a%k-1)/(a/k+1)+1)*(a/k+1);
		ans^=a/k;
	}
	if(ans)
		printf("Takahashi\n");
	else
		printf("Aoki\n");
	return 0;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
keys = []
for i in range(m):
    a, b = map(int, input().split())
    s = 0
    for c in map(int, input().split()):
        c -= 1
        s |= 1 << c
    keys.append((s, a))

INF = 1001001001
dp = [INF] * (1<<n)
dp[0] = 0
for s in range(1<<n):
    for k, v in keys:
        t = s | k
        cost = dp[s] + v
        dp[t] = min(dp[t], cost)

ans = dp[-1]
if ans == INF: ans = -1
print(ans)

Measured memory_bytes: 76932
#include <stdio.h>

int main()
{
    int n, i;
    int ans = 100000;

    scanf("%d", &n);

    for (i = 0; i < n; i++) {
        ans *= 1.05;
        ans = ((ans+999)/1000) * 1000;
    }

    printf("%d\n", ans);

    return 0;
}

Measured memory_bytes: 1824
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e10;
const int MOD = 1e9 + 7;
#define dump(x) cout << #x << " = " << (x) << endl;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a); i <= (b); ++i)
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define P pair<int, int>
#define V vector<int>
#define S set<int>
#define itn int
#define tin int
#define tni int
bool dbg = false;
int M, D;
void solve()
{
}

signed main()
{
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int ans = 0;
    cin >> M >> D;
    FORR(i, 1, M)
    {
        FORR(j, 1, D)
        {
            if ((j / 10) >= 2 && (j % 10) >= 2 && i == (j / 10) * (j % 10)) {
                ans++;
            }
        }
    }
    cout << ans << endl;
    solve();
    return 0;
}


Measured memory_bytes: 256
z='abcdefghijklmnopqrstuvwxyz'
e=lambda x,i,j:z[(z.index(x)*i+j)%26]
def f():
 for i in range(1,26,2):
  for j in range(26):
   if sum(''.join(e(c,i,j)for c in w)in s for w in['that','this']):return(i,j)
for _ in[0]*int(input()):
 s=input()
 k=f()
 print(s.translate(str.maketrans(''.join(e(c,*k)for c in z),z)))


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

int main() {
  int a,b,c; cin >> a >> b >> c;
  int sum = a+b+c;
  if (sum >= 22) cout << "bust" << endl;
  else cout << "win" << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <iomanip>


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define rep(i, a, b) for (int i=a; i<(b); i++)
#define rp(i, a) for (int i=0; i<(a); i++)
#define repd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define rpd(i,a) for (int i = (a)-1; i >= 0; i--)

#define dump(x)  cout << #x << " = " << (x) << endl;

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(0);
    cout << std::fixed;

    string s;
    cin >> s;
    if(s[0] != s[s.length()-1]){
        if(s.length()%2 == 1) cout << "First\n";
        else cout << "Second\n";
    } else {
        if(s.length()%2 == 0) cout << "First\n";
        else cout << "Second\n";
    }
    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


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

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

ll V[60];

int main()
{
    ll N, K;
    cin >> N >> K;
    REP(i, N)
    {
        cin >> V[i];
    }

    ll max = 0;
    for (int n = 0; n <= std::min(N, K); ++n)
    {
        //! n個取る
        for (int l = 0; l <= n; ++l)
        {
            ll sum = 0;
            vector<ll> v;
            //! 左からl個、右からr個
            int r = n - l;
            REP(i, l)
            {
                sum += V[i];
                v.push_back(V[i]);
            }
            REP(i, r)
            {
                int index = N - 1 - i;
                sum += V[index];
                v.push_back(V[index]);
            }
            sort(v.begin(), v.end());
            REP(i, std::min(K - n, (ll)v.size()))
            {
                if (v[i] >= 0)
                    break;
                sum += abs(v[i]);
            }
            max = std::max(sum, max);
        }
    }
    cout << max << endl;
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cmath>
#include <string>
#include <iostream>

using namespace std;

int main(void)
{
	int k, s, ans = 0;
	cin >> k >> s;

	for (int i = 0; i <= k; ++i) {
		for(int j = 0; j <= k; ++j) {
			if (s - i - j <= k && s - i - j >= 0) {
				++ans;
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    long small, large;
    scanf("%ld %ld", &small, &large);

    if (small > large) {
        long tmp = small;
        small = large;
        large = tmp;
    }

    long mod;
    while ((mod = large % small) != 0) {
        large = small;
        small = mod;
    }

    printf("%ld\n", small);

    return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
 
using namespace std;
 
const int N = 1000 * 1000 + 17;
const int MOD = 1000 * 1000 * 1000 + 7;

int n;
long long a[N], ldp[N], rdp[N];

bool read() {
    if (!(cin >> n))
        return false;

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

    return true;
}

void solve() {
    map<int, int> ids;

    for (int i = 1; i <= n; ++i) {
        ldp[i] = ldp[i - 1];

        for (auto x = a[i - 1]; i != 1 && x < a[i]; x *= 4)
            if (ids.empty()) {
                ldp[i] += 2 * (i - 1);
            } else {
                ldp[i] += 2 * (i - ids.rbegin()->first);

                if (--ids.rbegin()->second == 0)
                    ids.erase(--ids.end());
            }

        for (auto x = a[i]; i != 1 && 4 * x <= a[i - 1]; x *= 4)
            ++ids[i];
    }

    ids.clear();

    for (int i = n; i >= 1; --i) {
        rdp[i] = rdp[i + 1];

        for (auto x = a[i + 1]; i != n && x < a[i]; x *= 4)
            if (ids.empty()) {
                rdp[i] += 2 * (n - i);
            } else {
                rdp[i] += 2 * (ids.begin()->first - i);

                if (--ids.begin()->second == 0)
                    ids.erase(ids.begin());
            }

        for (auto x = a[i]; i != n && 4 * x <= a[i + 1]; x *= 4)
            ++ids[i];
    }

    auto ans = 1ll * MOD * MOD;

    for (int i = 0; i <= n; ++i)
        ans = min(ans, i + ldp[i] + rdp[i + 1]);

    cout << ans << endl;
}
 
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    while (read())
        solve();

    return 0;
}



Measured memory_bytes: 9984
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
typedef long long ll;

int n, q, cnt[200020] = {}, ans[200020] = {}, val = 0;
bool gt[200020] = {};
vector<int> G[200020];

void dfs(int k) {
    gt[k] = true;
    val += cnt[k];
    ans[k] = val;
    for (int i = 0; i < G[k].size(); i++) {
        if (!gt[G[k][i]]) {
            dfs(G[k][i]);
        }
    }
    val -= cnt[k];
}

int main() {
    cin >> n >> q;
    for (int i = 0; i < n - 1; i++) {
        int a, b;
        cin >> a >> b;
        a--;  b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    for (int i = 0; i < q; i++) {
        int p, x;
        cin >> p >> x;
        cnt[p - 1] += x;
    }

    dfs(0);

    for (int i = 0; i < n; i++) {
        if (i != 0) cout << " ";
        cout << ans[i];
    }

}

Measured memory_bytes: 24192
#include <bits/stdc++.h>
using namespace std;
int calc(vector<int> &a) {
  for (int i=0; i<10; i++) {
    cin >> a.at(i);
  }
  sort(a.begin(),a.end());
  return 0;
}
int main() {
  vector<int> w(10);
  vector<int> k(10);
  calc(w);
  calc(k);
  int x,y;
  x = w.at(7)+w.at(8)+w.at(9);
  y = k.at(7)+k.at(8)+k.at(9);
  cout << x << " " << y << endl;
}


Measured memory_bytes: 3164
/*                    */
#include <bits/stdc++.h>
using namespace std;
using lint = int64_t;
namespace my {
char itoc(int i) { return i + '0'; }
int ctoi(char c) { return c - '0'; }
lint gcd(lint a, lint b) {
  a = abs(a);
  b = abs(b);
  if (a < b) swap(a, b);
  while (b != 0) {
    a %= b;
    swap(a, b);
  }
  return a;
}
lint lcm(lint a, lint b) { return a * b / my::gcd(a, b); }
}  // namespace my
/*                    */

int main() {
  lint x;
  cin >> x;
  lint n = 0;
  // n = ceil((long double)log(x / 100.0) / log(1.01));
  // cout << n << endl;
  lint tmp = 100;
  while (tmp < x) {
    tmp *= 1.01;
    n++;
  }
  cout << n << endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>

int main()
{
    int n, k;
    std::cin >> n >> k;

    std::string str;
    char c;

    for(int i = 0; i < k; i++)
    {
        std::cin >> c;
        str += c;
    }

    while(std::string::npos != std::to_string(n).find_first_of(str))
    {
        n++;
    }

    std::cout << n << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mod 1000000000000000000
#define int long long 
#define garou ios_base::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
int pow(int p,int r){
	int ans=1;
	while(r>0){
     if(r&1){
		 ans=((ans%mod)*(p%mod))%mod;
	 }
	 r=r>>1;
     p=((p%mod)*(p%mod))%mod;
	}
	return ans;
}
signed main() {
garou;
int n,m;
cin>>n>>m;
int ans=0;
int a[n];
for(int i=0;i<n;i++){
	cin>>a[i];
	ans+=a[i];
}
int x=0;
for(int i=0;i<n;i++){
	double d=(double)(1/(4*(double)m));
	d*=ans;
	if(d>a[i])
	continue;
	x++;
}
if(x>=m)
cout<<"Yes";
else
cout<<"No";

}

Measured memory_bytes: 3584
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque, OrderedDict
from copy import deepcopy
from functools import lru_cache, reduce
from math import ceil, floor
from sys import setrecursionlimit

import heapq
import itertools
import operator


inf = float('inf')


# globals
N = ""


def set_inputs():
    global N
    N = get_str()
    return


def main():
    setrecursionlimit(100000)
    set_inputs()
    n = int(N)
    ans = 0
    candidates = []
    for i in range(3, len(N)+1):
        candidates.extend(itertools.product([3, 5, 7], repeat=i))
    for c in candidates:
        if 3 in c and 5 in c and 7 in c:
            v = sum(map(lambda x: x[1] * (10 ** x[0]), enumerate(reversed(c))))
            if v <= n:
                ans += 1
    print(ans)
    return


def get_int():
    return int(input())


def get_float():
    return float(input())


def get_str():
    return input().strip()


def get_li():
    return [int(i) for i in input().split()]


def get_lf():
    return [float(f) for f in input().split()]


def get_lc():
    return list(input().strip())


def get_data(n, types):
    if len(types) == 1:
        return [types[0](input()) for _ in range(n)]
    return zip(*(
        [t(x) for t, x in zip(types, input().split())]
        for _ in range(n)
    ))


if __name__ == '__main__':
    main()


Measured memory_bytes: 45292
main = do
  [n, a, b] <- map read . words <$> getLine
  putStrLn $ turnA n a b

turnA :: Int -> Int -> Int -> String
turnA n a b
  | a + 1 /= b = turnB n (a + 1) b
  | a /= 1 = turnB n (a - 1) b
  | otherwise = "Borys"

turnB :: Int -> Int -> Int -> String
turnB n a b
  | b - 1 /= a = turnA n a (b - 1)
  | b /= n = turnA n a (b + 1)
  | otherwise = "Alice"



Measured memory_bytes: 508
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
//using System.Text;
//using System.Text.RegularExpressions;
//using System.Globalization;
//using System.Diagnostics;
using static System.Console;
//using System.Numerics;
//using static System.Math;
//using pair = Pair<int, int>;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    readonly int[] dd = { 0, 1, 0, -1, 0 }; //→↓←↑
    readonly int mod = 1000000007;
    void chmax<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? b : a; }
    void chmin<T>(ref T a, T b) where T : IComparable<T> { a = a.CompareTo(b) < 0 ? a : b; }

    void solve()
    {
        int a = cin.nextint;
        int b = cin.nextint;
        int c = cin.nextint;
        int d = cin.nextint;

        if (true)
        {
            WriteLine($"{c - (d - b)} {d + (c - a)} {a - (d - b)} {b + (c - a)}");
        }
 
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

Measured memory_bytes: 13268
import sys

def solve(h, w, board):
    rows = []
    for i in range(h):
        row = []
        for k in range(w):
            row.append(0)
        rows.append(row)

    for i in range(h):
        for k in range(w):
            if board[i][k] == 1:
                rows[i][k] =  -1
                for dx in [-1, 0, 1]:
                    for dy in [-1,0,1]:
                        if  (not (dx == 0 and dy ==0)) and 0 <= i + dy and i + dy < h and 0 <= k + dx and k + dx < w:
                            if board[i + dy][k + dx] != 1:
                                rows[i + dy][k + dx] += 1


    return rows

def main():
    s1 = sys.stdin.readline()
    lst = s1.split(' ')
    h = int(lst[0])
    w = int(lst[1])

    rows = []
    for i in range(h):
        s = sys.stdin.readline()
        row = []
        for ch in s:
            if ch == '#':
                row.append(1)
            else:
                row.append(0)

        rows.append(row)

    ans = solve(h, w, rows)
    for ans_nums in ans:
        for num in ans_nums:
            if num == -1:
                sys.stdout.write('#')
            else:
                sys.stdout.write(str(num))
        print()
    return 0

if __name__ == '__main__':
    sys.exit(main())


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,A,B;
  cin >> N >> A >> B;
  
  int x = 0;
  x = N * A;
  
  if(N * A < B){
  	cout << N * A << endl;
  }
  else if(N * A == B){
  	cout << B << endl;
  }
  else{
  	cout << B << endl;
  }
}

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

int main(){
    int n, a, b;
    cin >> n >> a >> b;
    if(n*a < b){
        cout << n*a << endl;
    }else{
        cout << b << endl;
    }
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Text;
using System.Text.RegularExpressions;
using System.Linq;
using System.IO;

class Program
{ 
    static void Main(string[]args)
    {
        Magatro m = new Magatro();
        m.Scan();
        m.Solve();
    }
}

public class Scanner
{
    private StreamReader Sr;
    private string[] S;
    private int Index;

    private const char Separator=' ';

    public Scanner()
    {
        Index = 0;
        S = new string[0];
        Sr = new StreamReader(Console.OpenStandardInput());
    }

    private string[] Line()
    {
        return Sr.ReadLine().Split(Separator);
    }

    public string Next()
    {
        string result;
        if (Index >= S.Length)
        {
            S = Line();
            Index = 0;
        }
        result = S[Index];
        Index++;
        return result;
    }
    public int NextInt()
    {
        return int.Parse(Next());
    }
    public double NextDouble()
    {
        return double.Parse(Next());
    }
    public long NextLong()
    {
        return long.Parse(Next());
    }
    public string[] StringArray(int index = 0)
    {
        Next();
        Index = S.Length;
        return S.Skip(index).ToArray();
    }
    public int[] IntArray(int index = 0)
    {
        return StringArray(index).Select(int.Parse).ToArray();
    }
    public long[]LongArray(int index = 0)
    {
        return StringArray(index).Select(long.Parse).ToArray();
    }

    public bool ScanToEnd(ref string s)
    {
        if (Sr.EndOfStream)
        {
            return false;
        }
        else
        {
            s = Sr.ReadLine();
            return true;
        }
    }
}

public class Magatro
{
    private long N, X;
    public void Scan()
    {
        Scanner sc = new Scanner();
        N = sc.NextLong();
        X = sc.NextLong();
    }

    public void Solve()
    {
        Console.WriteLine(3 * (N-gcd(N, X)));
    }
    private long gcd(long n,long x)
    {
        long r = n % x;
        while (r > 0)
        {
            n = x;
            x = r;
            r = n % x;
        }
        return x;
    }
}





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

int main (){
	int n;scanf("%d",&n);
	string s1[100],s2[100];
	int a1[100],a2[100];
	for (int i=0;i<n;i++) {
		cin>>s1[i]>>a1[i];
		s2[i]=s1[i];
		a2[i]=a1[i];
	}
	for (int i=0;i<n;i++){
		for (int j=i+1;j<n;j++){
			if (s1[j][0]<s1[i][0]){
				swap(s1[j],s1[i]);
				swap(a1[j],a1[i]);
			}
			else if (s1[j][0]==s1[i][0]){
				if (s1[j][1]<s1[i][1]){
				    swap(s1[j],s1[i]);
				    swap(a1[j],a1[i]);
			    }
			    else if (s1[j][1]==s1[i][1]){
			    	if (s1[j][2]<s1[i][2]){
				        swap(s1[j],s1[i]);
				        swap(a1[j],a1[i]);
			        }
			        else if (s1[j][2]==s1[i][2]){
			        	if (s1[j][3]<s1[i][3]){
				            swap(s1[j],s1[i]);
				            swap(a1[j],a1[i]);
			            }
					}
				}
			}
			if (s1[j]==s1[i]){
				if (a1[j]>a1[i]){
					swap(s1[j],s1[i]);
				    swap(a1[j],a1[i]);
				}
			}
		}
	}
	for (int i=0;i<n;i++){
		for (int j=0;j<n;j++){
			if (a1[i]==a2[j]&&s1[i]==s2[j]){
				cout<<j+1<<endl;
				break;
			}
		}
	}
	return 0;
} 

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    
    int i,j,k,l;
    int a[4],b[4];
    int hit;
    int bro;
    
    while(1){
        hit=0;
        bro=0;
        
        if(scanf("%d %d %d %d",&a[0],&a[1],&a[2],&a[3])==EOF)break;
        for(i=0;i<4;i++){
            scanf("%d",&b[i]);
        }
        for(i=0;i<4;i++){
            if(a[i]==b[i]){
                hit++;
            }
        }
        
        for(i=0;i<4;i++){
            for(j=0;j<4;j++){
                if(i!=j){
                    if(a[i]==b[j]){
                        bro++;
                        break;
                    }
                }
            }
        }
        printf("%d %d\n",hit,bro);
    }
    return(0);
}

Measured memory_bytes: 596
#include <iostream>
#include <map>
#include <vector>
#include <cmath>
#include <string>
#include <cstring>
#include <algorithm>
#include <climits>
#include <stack>
#include <queue>
#include <set>
#include <cctype>
#include <bitset>
#include <type_traits>

#include <list>
using namespace std;

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define YES(j) cout << (j ? "YES" : "NO") << endl;
#define Yes(j) std::cout << (j ? "Yes" : "No") << endl;
#define yes(j) std::cout << (j ? "yes" : "no") << endl;

int main(void)
{
    int n;
    cin >> n;
    vector<int> x;
    REP(i, n)
    {

        int t;
        cin >> t;
        x.push_back(t);
    }
    int minv = 1001001001;
    sort(x.begin(), x.end());
    for (int i = x[0]; i <= x[x.size() - 1]; i++)
    {
        int sum = 0;
        for (auto j : x)
        {
            sum += (j - i) * (j - i);
        }
        if (sum < minv)
            minv = sum;
    }
    cout << minv << endl;
}

Measured memory_bytes: 256
while True:
    conv_map = {}
    s = ""
    n=input()
    if n==0:
        break

    for x in xrange(n):
        lst = raw_input().split()
        conv_map[lst[0]] = lst[1]

    m=input()
    tmp=""
    for x in xrange(m):
        tmp=raw_input()[0]
        s += conv_map.get(tmp, tmp)

    print s

Measured memory_bytes: 6332
#include<stdio.h>
int main()
{
    long long int N,M;
    long long int MAX_L=0,LOW_R=0;
    scanf("%lld %lld", &N, &M);
    long long int L[100000],R[100000];
    for(long long int i =0;i<M;i++)
    {
        scanf("%lld %lld", &L[i], &R[i]);
    }
    MAX_L=L[0];
    LOW_R=R[0];
    for(long long int i = 0;i<M-1;i++)
    {
        if(L[i+1]>MAX_L)MAX_L=L[i+1];
        if(R[i+1]<LOW_R)LOW_R=R[i+1];
    }
    if(LOW_R<MAX_L)
    {
        printf("0");
        return 0;
    }
    printf("%lld",LOW_R-MAX_L+1);
    return 0;
}

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

int main() {
  int N,M;
  cin >> N >> M;
  int sumN = 0;
  for ( N --;N > 0;N-- ) {
    sumN += N;
  }

  int sumM = 0;
  for ( M--;M > 0;M-- ) {
    sumM += M;
  }
 
  cout << sumM + sumN;
}

Measured memory_bytes: 256
#include <iostream>
#include <set>
#include <map>
using namespace std; // 575;

map<long long, long long> ms; // ms... Windowsっぽくね？
long long n;
long long a[200005];
long long ans;

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

    ms[0] = 1;
    for (int i = 1; i <= n; i++) {
        a[i] += a[i - 1];

        ans += ms[a[i]];
        ms[a[i]] += 1;
    }

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


Measured memory_bytes: 14336
N, M = map(int, input().split())
from collections import defaultdict
AB_dict = defaultdict(list)
dist_list = [-1] * N
dist_list[0] = 0
pre_list = []
for _ in range(M):
    a, b = [int(i)-1 for i in input().split()]
    AB_dict[a].append(b)
    AB_dict[b].append(a)
    if a == 0:
        pre_list.append(b)
        dist_list[b] = 0
    if b == 0:
        pre_list.append(a)
        dist_list[a] = 0
#print(AB_dict)

    
while True:
    tmp = []
    #print(pre_list)
    for p in pre_list:
        #print(p)
        for node in AB_dict[p]:
            #print("node", node)
            if dist_list[node] == -1:
                #print(node, "=", p)
                dist_list[node] = p
                tmp.append(node)
    if tmp == []:
        break
    pre_list = tmp
    
if -1 in dist_list:
    print('No')
    exit()
    
print('Yes')
for dist in dist_list[1:]:
    print(dist+1)

Measured memory_bytes: 39124
#include<bits/stdc++.h>
#define INF 2000000000
#define MOD 1000000007
#define EPS (1e-10)

using namespace std;


vector<int>  dx = {1,-1,0,0};
vector<int>  dy = {0,0,1,-1};


bool isMSprime(int num, vector<int>  MS_list) {
    for (int i = 0; i < MS_list.size(); i++) {
        if (num % MS_list[i] == 0 and num != MS_list[i]) {
            return false;
        }
    }
    return true;
}

int main() {
	vector<int> MS_list;
	
	for (int i = 2; i <= 299998; i++) {
		if (i % 7 == 6 or i % 7 == 1) {
			MS_list.push_back(i);	
		}
	}
	int l = MS_list.size();

	while(1) {
		int n; cin >> n;
		if (n == 1) break;

		vector<int> MS;

		for (int i = 0; i < l; i++) {
			if (n % MS_list[i] == 0 and isMSprime(MS_list[i],MS_list)) {
				MS.push_back(MS_list[i]);
			}
		}
		cout << n << ":";
		for (int i = 0; i < MS.size(); i++) {
			cout << " " << MS[i] ;
		}
		cout << endl;
	}

	return 0;
}



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

int main() {
	int n; cin >> n;
	vector<vector<ll> > p(n+1, vector<ll>(2));
	for (ll i = 0; i < n; ++i) {
		ll v, w; scanf("%lld%lld", &v, &w);
		p[i+1][0] = v; p[i+1][1] = w;
	}
	int k = 1;
	while (n > ((1<<k)-1)) k++;
	k = min(k, 10);
	int K = 1<<k;
	vector<vector<ll> > dp(K, vector<ll>(100001, 0));
	for (int i = p[1][1]; i < 100001; ++i) dp[1][i] = p[1][0];
	for (int i = 2; i < min(n+1, K); ++i) {
		for (int j = 0; j < 100001; ++j) {
			if (j >= p[i][1]) dp[i][j] = max(dp[i/2][j], dp[i/2][j-p[i][1]] + p[i][0]);
			else dp[i][j] = dp[i/2][j];
		}
		//for (ll j = 0; j < 10; ++j) cout << dp[i][j];
		//cout << "\n";
	}
	int Q; cin >> Q;
	for (int q = 0; q < Q; ++q) {
		int x, l; scanf("%d%d", &x, &l);
		if (x < K) {
			printf("%lld\n", dp[x][l]);
			continue;
		}
		int par = x; int cnt = 0;
		vector<int> pars(10);
		while (par >= K) {
			//cout << par << " ";
			pars[cnt] = par;
			par /= 2;
			cnt ++;
		}
		//cout << par << "\n";
		//cout << "\n";
		ll ans = dp[par][l];
		vector<vector<ll> > dp2(1<<cnt, vector<ll>(2, 0));
		for (int i = 1; i < (1<<cnt); ++i) {
			int lsb = i & (-i); int lsb_ind = 0;
			while ((1 << lsb_ind) < lsb) lsb_ind++;
			dp2[i][0] = dp2[i-lsb][0] + p[pars[lsb_ind]][0];
			dp2[i][1] = dp2[i-lsb][1] + p[pars[lsb_ind]][1];
			if (dp2[i][1] <= l) {
				//cout << i << " " << dp2[i][0] << " " << dp2[i][1] << "\n";
				ans = max(ans, dp2[i][0] + dp[par][l - dp2[i][1]]);
			}
		}
		printf("%lld\n", ans);
	}
	return 0;
}

Measured memory_bytes: 821164
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

const ll mod = 1000000009;

using vl = vector<ll>;
using mat = vector<vl>;

mat mul(const mat &A, const mat &B){
    int n = A.size();
    mat C(n,vl(n));
    rep(i,n)rep(j,n)rep(k,n) (C[i][j] += A[i][k]*B[k][j]) %= mod;
    return C;
}

mat mat_pow(const mat &A, ll x){
    int n = A.size();

    mat ret(n,vl(n));
    rep(i,n) ret[i][i] = 1;

    mat P(A);
    while(x){
        if(x&1) ret = mul(ret,P);
        P = mul(P,P);
        x>>=1;
    }
    return ret;
}

vl mul(const mat &A, const vl &b){
    int n = A.size();
    vl ret(n);
    rep(i,n)rep(j,n) (ret[i] += A[i][j]*b[j]) %= mod;
    return ret;
}

int main(){
    int T = 1;
    int w,n;
    ll h;
    while(cin >>w >>h >>n,w){
        map<ll,vector<int>> obj;
        rep(i,n){
            ll x,y;
            cin >>x >>y;
            --x;
            --y;

            if(y>0){
                obj[y].pb(x);
            }



        }

        mat O(w,vl(w));
        rep(i,w){
            for(int j=-1; j<=1; ++j){
                if(0<=i+j && i+j<w) O[i][i+j] = 1;
            }
        }

        mat A(w,vl(w));
        rep(i,w) A[i][i] = 1;

        ll ny = 0;
        for(const auto &p:obj){

            ll Y = p.fi;
            if(Y - ny > 1){
                A = mul(mat_pow(O, Y-ny-1), A);
            }

            mat B(O);
            for(int i:p.se){
                for(int j=-1; j<=1; ++j){
                    if(0<=i+j && i+j<w) B[i][i+j] = 0;
                }
            }

            A = mul(B,A);
            ny = Y;
        }

        if(ny != h-1) A = mul(mat_pow(O, h-1-ny), A);

        vector<ll> b(w);
        b[0]=1;

        vector<ll> res = mul(A,b);
        ll ans = res[w-1];
        printf("Case %d: %lld\n", T++, ans);
    }
    return 0;
}



Measured memory_bytes: 3220
#include <iostream>
#include <vector>
using namespace std;
#define INF 1e8
typedef long long ll;
int n;
vector<int> num;
ll memo[100][21];

ll solve(int index, int ans){
  if(ans < 0 || ans > 20) return 0;
  if(memo[index][ans] != -1) return memo[index][ans];
  if(index + 1 == n) return (ans == num[index + 1]);
  return (memo[index][ans] = solve(index + 1, ans - num[index + 1]) + solve(index + 1, ans + num[index + 1]));
}

int main(void){
  cin >> n;
  for(int i = 0; i < n; i++){
    int tmp;
    cin >> tmp;
    num.push_back(tmp);
  }
  for(int i = 0; i < 100; i++){
    for(int j = 0; j < 21; j++){
      memo[i][j] = -1;
    }
  }
  cout << solve(0, num[0]) << endl;
  return 0;
}

Measured memory_bytes: 1232
n,k = gets.split.map(&:to_i)
h = Hash.new(0)
n.times do
  a,b = gets.split.map(&:to_i)
  h[a] += b
end

h.sort.each do |n, v|
  if k <= v
    puts n
    exit 0
  else
    k -= v
  end
end

Measured memory_bytes: 9992