akhauriyash/Code-Regression huggingface dataset:
def slove():
    import sys
    input = sys.stdin.readline
    n, m, c = list(map(int, input().rstrip('\n').split()))
    b = list(map(int, input().rstrip('\n').split()))
    cnt = 0
    for _ in range(n):
        a = list(map(int, input().rstrip('\n').split()))
        t = c
        for i in range(m):
            t += (a[i] * b[i])
        if t > 0:
            cnt += 1
    print(cnt)


if __name__ == '__main__':
    slove()


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

int main () {
  	long long int n, total;
   	cin >> n;
  	total = 0;
	for (int i = 1;i<=n;i++) {
    	if (i % 3 != 0 && i % 5 != 0) {
          total += i;
        }
    }
  	cout << total << endl;
}


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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

LL N,M;
string S,T;

LL gcd(LL a, LL b){
	return b ? gcd(b,a%b) : a;
}

int main(){
	cin >> N >> M;
	cin >> S >> T;
	LL ans = N * M / gcd(N,M);
	int i = 0, j = 0;
	while(i < N || j < M){
		if(ans / N * i == ans / M * j){
			if(S[i] != T[j]) return cout << -1 << endl, 0;
			++i; ++j;
		} else if(ans / N * i < ans / M * j){
			++i;
		} else {
			++j;
		}
	}
	cout << ans << endl;
	return 0;
}


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

int main() {
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if (1<=a,b,c,d<=10){
    if(a+b>c+d){
      cout<<"Left"<<endl;
      }
    else if(a+b<c+d){
      cout<<"Right"<<endl;
      }
    else {
      cout<<"Balanced"<<endl;
      }
    }
  }

Measured memory_bytes: 256
use strict;

my $n = <>;
my @input = split(/\s+/, <>);

my %cnt;
foreach my $key (@input){
    if ($cnt{$key}) {
        $cnt{$key}=$cnt{$key}+1;
    } else {
        $cnt{$key}=1;
    }
}

my $answer = 0;
foreach my $key (sort(keys(%cnt))){
    my $tmp = $cnt{$key} + $cnt{$key-1} + $cnt{$key+1};
    if ($answer < $tmp) {
        $answer = $tmp;
    }
}
print $answer;

Measured memory_bytes: 22780
n=int(input())
l=list(map(int,input().split()))
# print(l)
ans=1
if 0 in l:
    print(0)
    exit()
for i in l:
    ans*=i
    if ans> 10**18:
        # print(ans)
        print(-1)
        exit()
print(ans)

Measured memory_bytes: 21572
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;

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

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

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main()
{
	int n,m;
	cin>>n>>m;
	vector<int> cnt(n);
	rep(i,m){
		int a,b;
		cin>>a>>b;
		a--;b--;
		cnt[a]++;
		cnt[b]++;
	}
	bool flag = true;
	rep(i,n)if(cnt[i]%2!=0)flag=false;
	cout<<(flag?"YES":"NO")<<endl;
	return 0;
}

Measured memory_bytes: 640
#???????????°???????????????
Integer1,Integer2,Integer3 = gets.split(" ").map(&:to_i)
sortInteger = [Integer1,Integer2,Integer3]
for countA in 0..1     #??????????????????
	for count in 0..1
		if sortInteger[count] > sortInteger[count+1] then
			temp = sortInteger[count]
			sortInteger[count] = sortInteger[count+1]
			sortInteger[count+1] = temp
		end
	end
end

puts "#{sortInteger[0]} #{sortInteger[1]} #{sortInteger[2]}"

Measured memory_bytes: 8684
#include<iostream>
#include<string.h>

using namespace std;

int main(){
	int h,w;
	cin >> h >> w;
	char a[200][200];
	
	bool ux[200],uy[200];
	memset(a,0,sizeof(a));
	memset(ux,0,sizeof(ux));
	memset(uy,0,sizeof(uy));
	for(int i = 0;i < h;i++){
		for(int j = 0;j < w;j++){
			cin >> a[i][j];
			if(a[i][j] == '#'){
				ux[j] = 1;
				uy[i] = 1;
			}
		}
	}
	
	for(int i = 0;i < h;i++){
		if(uy[i]){
			for(int j = 0;j < w;j++){
				if(ux[j]){
					cout << a[i][j];
				}
			}
			cout << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2000)

N, M = map(int, input().split())
x = [0] * M
y = [0] * M
G = [[] for _ in range(N + 1)]
for i in range(M):
    X, Y = map(int, input().split())
    x[i] = X
    y[i] = Y
    G[X] += [Y]

dp = [-1] * (N + 1)


def f(n):
    if dp[n] != -1:
        return dp[n]
    res = 0
    for m in G[n]:
        res = max(res, f(m) + 1)
    dp[n] = res
    return res


for i in range(1, N + 1):
    f(i)
print(max(dp))

Measured memory_bytes: 119220
s = gets.chomp
s1, s2 = [s[0..1], s[2..3]].map(&:to_i)
if 1 <= s1 && s1 <= 12 then
  if 1 <= s2 && s2 <= 12 then
    puts "AMBIGUOUS"
  else
    puts "MMYY"
  end
else
  if 1 <= s2 && s2 <= 12 then
    puts "YYMM"
  else
    puts "NA"
  end
end

Measured memory_bytes: 1788
n = int(input())
s = [input()for i in range(n)]
a = "abcdefghijklmnopqrstuvwxyz"
cnt = []
for i in a:
    mi = 50
    for j in s:
        mi = min(mi,j.count(i))
    cnt.append(mi)
ans =""
for i in  range(26):
    ans +=a[i]*cnt[i]
print(ans)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<iomanip>
#include<list>
#include<deque>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define DEB2(X) cout<<X<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define DEB2(X) {}
#define END {}
#endif
typedef long long ll;
#define int ll
#define uset unordered_set
#define umap unordered_map
//typedef std::pair<int,int> P;
struct edge{int to,cost;};
const int INF=100000000000000000;
const int INF2=9223372036854775807;
const int MOD=1000000007;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define min(X,Y) (((int)(X)<(int)(Y))?(X):(Y))
#define max(X,Y) (((int)(X)>(int)(Y))?(X):(Y))
#define NP(X,Y) next_permutation(X,Y)
#define setdouble(X,Y) cout<<fixed<<setprecision(X)<<Y
int ceil2(int a,int b){if(a%b==0){return a/b;}else{return a/b+1;}}
int pow2(int a,int b){int r=1;for(int i=1;i<=b;i++){r*=a;}return r;}
int Log2(int a){int t=0;while(1){if(a==0||a==1){break;}a/=2;t++;}return t;}

int A,B,C;

signed main(){
	cin>>A>>B>>C;
	if(A%2==0||B%2==0||C%2==0){
		cout<<0<<endl;
	}
	else{
		cout<<min(A*B,min(B*C,C*A))<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;

namespace dp
{
    class Program
    {
        static int[] ReadNumList()
        {
            var line = Console.ReadLine().Split(' ');
            var numList = new int[line.Length];
            for (var i = 0; i < line.Length; ++i)
            {
                numList[i] = int.Parse(line[i]);
            }
            return numList;
        }
        static void Main(string[] args)
        {
            var n = int.Parse(Console.ReadLine());
            var hTable = new int[n][];
            var rTable = new int[n][];
            for (var i = 0; i < n; ++i)
            {
                hTable[i] = ReadNumList();
                rTable[i] = new int[3];
            }

            rTable[n - 1] = hTable[n - 1];

            for (var i = n - 2; i >= 0; --i)
            {
                rTable[i][0] = hTable[i][0] + Math.Max(rTable[i + 1][1], rTable[i + 1][2]);
                rTable[i][1] = hTable[i][1] + Math.Max(rTable[i + 1][0], rTable[i + 1][2]);
                rTable[i][2] = hTable[i][2] + Math.Max(rTable[i + 1][0], rTable[i + 1][1]);
            }
            Console.WriteLine(Math.Max(Math.Max(rTable[0][0], rTable[0][1]), rTable[0][2]));
        }
    }
}


Measured memory_bytes: 48620
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin >> a >> b;
  if(a==1){
    a = 14;
  }
  if(b==1){
    b = 14;
  }
  if(a == b){
    cout << "Draw" << endl;
  }else if(a>b){
    cout << "Alice" << endl;
  }else{
    cout <<"Bob" << endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC target("avx2")
#pragma GCC optimize("03")
#pragma GCC optimize("unroll-loops")
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define dunk(a) cout << (a) << "\n"
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n, p;
	cin >> n >> p;
	vector<pair<ll, ll>> div;
	for (ll i = 1; i * i <= p; ++i) {
		if (i == 1) {
			div.emplace_back(p / i, 1);
			continue;
		}
		if (p % i == 0) {
			ll a = p;
			ll cnt = 0;
			while (a % i == 0) {
				cnt++;
				a /= i;
			}
			div.emplace_back(pair<ll, ll>(i, cnt));
			if (i * i != p) {
				a = p;
				cnt = 0;
				ll k = p / i;
				while (a % k == 0) {
					cnt++;
					a /= k;
				}
				div.emplace_back(pair<ll, ll>(k, cnt));
			}
		}
	}
	sort(all(div));
	ll ans = 0;
	for (auto& c : div) {
		if (c.second >= n) {
			ans = max(ans, (ll)pow(c.first, ll(c.second / n)));
		}
	}
	ans = max(ans, 1ll);
	dunk(ans);
	return 0;
}


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

const int INF = 1001001001;
int A[12][12];

int main(){
  //input numbers
  int n,m,x;
  cin >> n >> m >> x ;
  vector<int> C(n,0);
  rep(i,n){
    cin >> C[i];
    rep(j,m){
      cin >> A[i][j];
    }
  }

  //check all cases
  int ans =INF;
  //1//n⇒2^n
  rep(s,1<<n){
    int cost=0;
    //vector d for adding a[i][j]
    vector<int> d(m);
    rep(i,n){
      //add cost and d when s's digit is 1
      if(s>>i&1){
        cost +=C[i];
        rep(j,m) d[j]+=A[i][j];
      }
    }
    // if d isn't enough, fail
    bool ok = true;
    rep(j,m) if(d[j]<x) ok = false;
    // if ok,calculate cost by using min function
    if (ok)ans=min(ans,cost);
  }

  //if ans wasn't changed, output "-1"
  if(ans==INF) cout << -1 << endl;
  // else output ans which is the minimunm cost
  else cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3604
from collections import deque

N,M=map(int,input().split())
G=[[]for i in range(N)]
for i in range(M):
    a,b=map(int,input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)
dist=[-1]*N
d=deque()
dist[0]=0
d.append(0)
while(len(d)!=0):
    v=d[0]
    d.popleft()
    for nv in G[v]:
        if(dist[nv]!=-1):
            continue
        dist[nv]=dist[v]+1
        d.append(nv)
if(dist[N-1]==2):
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Measured memory_bytes: 40472
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define F first
#define S second
#define _sz(x) (int)x.size()

using namespace std ;
using ll = long long ;
using ld = long double ;
using pii = pair <int , int> ;

int const N = 1e5 + 20 ;
int n , a[N] , ans ;

inline void compress (int a[N] , int n) {
	vector <int> vec ;
	for (int i = 0 ; i < n ; i ++) vec.push_back(a[i]) ;
	sort(vec.begin() , vec.end()) ;
	for (int i = 0 ; i < n ; i ++) a[i] = lower_bound(vec.begin() , vec.end() , a[i]) - vec.begin() ;
}

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

	cin >> n ;

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

	compress(a , n) ;

	for (int i = 0 ; i < n ; i ++) if ((a[i] & 1) && !(i & 1)) ans ++ ;


	cout << ans << '\n' ;
}


Measured memory_bytes: 1276
x,k,d = map(int,input().split())
if x == 0:
    if k % 2 == 0:
        print(0)
    else:
        print(d)
elif x > 0:
    if d * k <= x:
        print(x-d*k)
    else:
        w = x // d
        if (k - w)%2 == 0:
            print(x%d)
        else:
            print(abs(x%d-d))
else:
    if d * k <= abs(x):
        print(abs(x+d*k))
    else:
        w = abs(x) // d
        if(k - w)%2 == 0:
            print(abs(x)%d)
        else:
            print(abs(abs(x)%d-d))
        

Measured memory_bytes: 9152
/*
ACplease
　　 ●
　　/⌒ヽ
　 ｜ 　|/⌒ヽ(ヽ
　 (｀　∥ー⌒) |
　|￣||￣￣￣￣￣|
　|―||―――――|
　|　Ｕ　　　　　|
　|￣￣￣￣￣￣￣|
　|＿＿＿＿＿＿＿|
　　|―――――|
　　|―――――|
ｗｗＷｗｗＷｗＷＷｗ
*/
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>
#include <cassert>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repe(i, n) for (int i = 0; i <= (int)(n); i++)
#define YES cout<<"YES"<<endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl
#define ANS cout << ans << endl
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define REVERSE(a) reverse(all(a))
#define KOZYUN(a) sort(all(a),greater<int>())
#define int ll
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORe(i, m, n) for(int i = m;i <= n;i++)
#define VIin(a) for(int i=0; i<a.size(); i++) cin >> a[i]
#define OUT(a) cout << a << endl
#define IN(a) cin >> a
#define INT(a) int a; cin >> a
typedef vector<int> VI;
typedef vector<VI> VVI;
const int MOD=1e9+7;
const long long INF = 1LL << 60;
/*最大公約数*/int gcd(int x, int y) { return y ? gcd(y,x%y) : x;}
/*最小公倍数*/int lcm(int a, int b) { int g = gcd(a, b); return a / g * b; }
/*素数判定*/int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*約数列挙*/vector<int> getDivisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}

//----------------------------------------------
signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(15);
    srand((unsigned)time(NULL));
    
    int n; cin >> n;
    map<int,int> a;
    rep(i,n){
        int x; cin >> x;
        if(a[x] == 1){
            NO;
            return 0;
        }else a[x]++;
    }
    YES;

    return 0;
}

Measured memory_bytes: 12800
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int i = (int)(n); i >= 0; i--)
#define all(v) v.begin(),v.end()
typedef long long ll;

int main(){
    int N,M;
    cin >> N >> M;
    vector<int> left(0);
    vector<int> right(0);
    rep(i,M){
        int L;
        cin >> L;
        left.push_back(L);
        int R;
        cin >> R;
        right.push_back(R);
    }
    sort(all(left));
    sort(all(right));
    int max_left = left[M - 1];
    int min_right = right[0];
    if (max_left > min_right){
        cout << 0 << endl;
    }
    else{
        cout << min_right - max_left + 1 << endl;
    }
}


Measured memory_bytes: 1276
#!usr/bin/env python3
from collections import defaultdict, deque
from heapq import heappush, heappop
from itertools import permutations, accumulate
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.buffer.readline().split()]
def I(): return int(sys.stdin.buffer.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    n = I()
    a = LI()
    if not n&1:
        dp = a[:2]
        for i in range(2,n)[::2]:
            nd = [-float("inf")]*2
            nd[0] = dp[0]+a[i]
            nd[1] = max(dp)+a[i+1]
            dp = [j for j in nd]
        print(max(dp))
        return
    dp = a[:3]
    dp[0] = a[0]
    dp[1] = a[1]
    dp[2] = a[2]
    for i in range(2,n-1)[::2]:
        nd = [-float("inf")]*3
        nd[0] = dp[0]+a[i]
        nd[1] = max(dp[0],dp[1])+a[i+1]
        nd[2] = max(dp)+a[i+2]
        dp = [j for j in nd]
    print(max(dp))
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 91504
#include <cstdio>

const int N(3010);
struct edge { int next, to; } e[N << 1];
int n, A[N], head[N], e_num, ans[N];
inline void add_edge(int from, int to)
{
	e[++e_num] = (edge) {head[from], to};
	head[from] = e_num;
}

void dfs(int x, int f)
{
	ans[x] = 0;
	for (int i = head[x]; i; i = e[i].next) if (e[i].to != f && A[e[i].to] < A[x])
		{ dfs(e[i].to, x); if (!ans[e[i].to]) { ans[x] = 1; break; } }
}

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d", A + i);
	for (int i = 1, a, b; i <= n; i++)
		scanf("%d%d", &a, &b), add_edge(a, b), add_edge(b, a);
	for (int i = 1; i <= n; i++) { dfs(i, 0); if (ans[i]) printf("%d ", i); }
	return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var N = 5

	at := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&at[i])
	}

	var K int
	fmt.Scan(&K)

	var can = true
	for i := N - 1; i > 0; i-- {
		for j := 0; j < N; j++ {
			if at[i]-at[j] > K {
				can = false
				break
			}
		}
	}
	if can {
		fmt.Println("Yay!")
	} else {
		fmt.Println(":(")
	}
}


Measured memory_bytes: 512
#include <iostream>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <set>
#include <deque>
#include <utility>

int main(){
  int K;
  scanf("%d", &K);
  std::vector<long long > A(K);
  for (int i=0; i<K; i++){
    scanf("%lld", &A[i]);
  }
  std::vector<long long > min(K+4), max(K+4);
  min[K]=2;
  max[K]=2;
  if (A[K-1]!=2) {
    printf("-1\n");
    return 0;
  }
  long long mincand, maxcand;
  for (int i=K-1; i>=0; i--){
    min[i]=A[i]*((min[i+1]+A[i]-1)/A[i]);
    max[i]=A[i]*(max[i+1]/A[i])+A[i]-1;
    //printf("i=%d, min,mnax=(%lld, %lld)\n", i, min[i], max[i]);
    if (min[i]>max[i]){
      printf("-1\n");
      return 0;
    }
  }
  std::cout<<min[0]<<" "<< max[0]<<std::endl;
  return 0;
}


Measured memory_bytes: 2560
#include <stdio.h>

int from, battery, to;
double prob[16][16]; //残量iで, 地点jからbatteryへいける確率

double getProb(int lim, int start)
{
    int k;
    double ans;
    
    if (prob[lim][start] >= 0){
        return (prob[lim][start]);
    }
    
    if (start == battery && lim == 0){
        return (1);
    }
    if (lim == 0){
        return (0);
    }
    
    ans = 0.0;
    k = 4;
    
    if ((start + 1) % 3 && start + 1 != to){
        ans += 0.25 * getProb(lim - 1, start + 1);
        k--;
    }
    
    if (start % 3 && start - 1 != to){
        ans += 0.25 * getProb(lim - 1, start - 1);
        k--;
    }
    
    if (start + 3 < 9 && start + 3 != to){
        ans += 0.25 * getProb(lim - 1, start + 3);
        k--;
    }
    
    if (start - 3 >= 0 && start - 3 != to){
        ans += 0.25 * getProb(lim - 1, start - 3);
        k--;
    }
    
    ans += 0.25 * k * getProb(lim - 1, start);
    
    return (prob[lim][start] = ans);
}

int main(void)
{
    int left;
    int i, j;
    char in[16];
    
    while (1){
        scanf(" %d", &left);
        if (left == 0){
            break;
        }
        scanf(" %c %c %c", in, in + 2, in + 4);
        from = in[0] - 'A';
        battery = in[2] - 'A';
        to = in[4] - 'A';
        
        for (i = 0; i < 16; i++){
            for (j = 0; j < 16; j++){
                prob[i][j] = -1;
            }
        }
        
        printf("%.8lf\n", getProb(left, from));
    }
    
    return (0);
}

Measured memory_bytes: 0
//include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
// chmax chmin
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(void){
    int N;
    cin >> N;
    int a[N];
    REP(i,N) cin >> a[i];

    double mean = 0;
    REP(i,N) mean += (double)a[i]/N;

    int ans;
    if(mean-floor(mean) < ceil(mean)-mean) ans = floor(mean);
    else ans = ceil(mean);

    int A = 0;
    REP(i,N) A += (ans-a[i])*(ans-a[i]);

    cout << A << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c,d,A,B,C,D,E,F,i,j,k,l,fz=0,fm=0,x=1,y=1;
	scanf("%d%d%d%d%d%d",&A,&B,&C,&D,&E,&F);
	for(i=0;i<=F/(100*A);i++){
		a=i*100*A;
		if(a>F) break;
		for(j=0;j<=F/(100*B);j++){
			b=j*100*B;
			if(a+b>F) break;
			for(k=0;k<F/C;k++){
				c=k*C;
				if(a+b+c>F) break;
				for(l=0;l<F/D;l++){
					d=l*D;
					if((a+b+c+d)>F||(c+d)>(a+b)/100*E) break;
					fz=(c+d);
					fm=(a+b);
					if(x*(fm+fz)<=fz*(y+x)) {x=fz;y=fm;}
					
				}
			}
		}
	}
	printf("%d %d",x+y,x);
	return 0;
}

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

#define ll long long

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    char c = 'B';
    string s;
    cin >> s;
    if(s[1]=='B') c = 'R';
    s[1] = c;
    cout << s << '\n';
    return 0;
}

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

using namespace std;
#define int long long
const double pi=3.14159265358979;
int32_t main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cout<<fixed<<setprecision(15)<<"";
    int a,b,h,m;
    cin>>a>>b>>h>>m;
    double ang1=(60*h+m+0.0)/(720.0)*2*pi;
    double ang2=2.0*pi*(m+0.0)/60.0;
    //cout<<(ang1/pi)<<" "<<ang2/pi<<endl;
    double delta=(ang2-ang1);
    cout<<sqrt(a*a+b*b-2*a*b*cos(delta));
    return 0;
}


Measured memory_bytes: 4164
import Foundation

extension String {
    
    func toStrList() -> [String] {
        return self.map{String($0)}
    }
    
    func toIntList() -> [Int] {
        return self.map{Int(String($0))!}
    }
    
    func toSepDoubleList() -> [Double]{
        return self.split(separator: " ").map{Double($0)!}
    }

    func toSepIntList() -> [Int] {
        return self.split(separator: " ").map{Int($0)!}
    }

    func toSepStrList() -> [String] {
        return self.split(separator: " ").map{String($0)}
    }
    
    func zFill(n:Int) -> String {
        return String(format: "%0\(n)d", Int(self)!)
    }
    
    func count(c:Character) -> Int{
        var result = 0

        for e in self{
            if e == c{
                result += 1
            }
        }
        return result
    }

    func counter() -> Dictionary<Character, Int>{
        var result:[Character:Int] = [:]
        
        for c in self{
            guard let _ = result.index(forKey: c) else {
                result[c] = 1
                continue
            }
            result[c]! += 1
        }
        return result
    }
}

extension Int {
    func toBin() -> String {
        return String(self, radix: 2)
    }
    
    func toNBin(_ radix:Int) -> String{
        return String(self, radix: radix)
    }
    
    func toD() -> Double {
        return Double(self)
    }
}

extension Double {
    func toI() -> Int {
        return Int(self)
    }
}

extension Array where Element: Equatable{
    func count(n:Self.Element) -> Int{
        var result = 0
        for e in self{
            if e == n{
                result += 1
            }
        }
        return result
    }
}

extension Array {
    func dump(){
        for x in 0..<self.count-1{
            print(self[x], terminator: " ")
        }
        print(self.last!)
    }
}

func pow(_ base:Int,_ exp:Int) -> Int{
    let d = pow(base.toD(), exp.toD())
    return Int(d)
}

func distance(p1:CGPoint, p2:CGPoint) -> Double {
    let diffp = CGPoint(x:p1.x - p2.x, y:p1.y - p2.y)
    return Double(sqrt(diffp.x*diffp.x + diffp.y * diffp.y))
}

func distance(p1:[Double], p2:[Double]) -> Double{
    let diff = [p1[0] - p2[0], p1[1] - p2[1]]
    return sqrt(diff[0] * diff[0] + diff[1] * diff[1])
    
}

func lotate(theta:Double, point:[Double]) -> [Double] {
    let matrix = [
        [cos(theta), -sin(theta)],
        [sin(theta), cos(theta)]
    ]
    let x = point[0]
    let y = point[1]
    
    let rx = matrix[0][0]*x + matrix[0][1]*y
    let ry = matrix[1][0]*x + matrix[1][1]*y
    
    return [rx, ry]
}


func d() -> Int{
    let N = Int(readLine()!)!
    var C = readLine()!.toStrList()
    var left = 0
    var right = N-1
    var ans = 0
    while left < right {
        if C[left] == "W" && C[right] == "R" {
            C[left] = "R"
            C[right] = "W"
            ans += 1
            
            left += 1
            right -= 1
            continue
        }
        if C[left] == "R"{
            left += 1
        }
        if C[right] == "W" {
            right -= 1
        }
    }
    return ans
    
}

print(d())




Measured memory_bytes: 15496
import java.util.*;

public class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String S = sc.next();
        char[] sca = S.toCharArray();
        BIT[] cnts = new BIT[26];
        for(int i=0;i<26;i++){
            cnts[i] = new BIT(N+10);
        }
        for(int i=0;i<N;i++){
            int ind = sca[i]-'a';
            cnts[ind].addTo(i + 1, 1);
        }
        int Q = sc.nextInt();
        for(int i=0;i<Q;i++){
            int qt = sc.nextInt();
            if(qt == 1){
                int iq=sc.nextInt()-1;
                String cq=sc.next();
                int toc=cq.charAt(0)-'a';
                int fromc = sca[iq]-'a';
                if(fromc != toc) {
                    cnts[fromc].addTo(iq + 1, -1);
                    sca[iq] = cq.charAt(0);
                    cnts[toc].addTo(iq + 1, 1);
                }
            }else{
                int lq=sc.nextInt();
                int rq=sc.nextInt();
                int sum=0;
                for(int k=0;k<26;k++){
                    BIT b = cnts[k];
                    if(b.sumTo(rq)-b.sumTo(lq-1)>0){
                        sum++;
                    }
                }
                System.out.println(sum);
            }
        }


    }
    private static class BIT{
        int[] vals;
        int len;
        BIT(int n){
            len = n;
            vals = new int[len+1];
            Arrays.fill(vals, 0);
        }
        public void addTo(int ind, int val){
            while(ind <= len){
                vals[ind] += val;
                ind += btmBit(ind);
            }
        }

        public int sumTo(int ind){
            int sum = 0;
            while(ind > 0){
                sum += vals[ind];
                ind -= btmBit(ind);
            }
            return sum;
        }

        private static int btmBit(int a){
            return a&(-a);
        }

        @Override
        public String toString(){
            StringBuilder bld = new StringBuilder();
            for(int i=0;i<len+1;i++){
                bld.append(sumTo(i));
            }
            return bld.toString();
        }
    }
}


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

using namespace std;

#define li long long int
#define ll pair<li,li>
#define vl vector<li>
#define vll vector<ll>
#define FOR(i,l,r) for( int i = l-(l>r); i != r-(l>r); i += 1-2*(l>r) )
#define xx first
#define yy second
#define pb push_back
#define all(X) (X).begin(),(X).end()

bool comp( ll & a, ll & b ) {
    return a.xx+a.yy < b.xx+b.yy;
}

void upd( li & a, li b ) {
    if( a == -1 ) a = b;
    else a = min(a,b);
}

int main() {
    int n; cin>>n;
    vll v;
    FOR(i,0,n) {
        li h,p;
        cin>>h>>p;
        v.pb({h,p});
    }
    sort(all(v),comp);
    vl dp(n+1,-1);
    dp[0] = 0;
    FOR(i,0,n) {
        vl temp(n+1,-1);
        temp = dp;
        FOR(j,0,n+1) {
            if( dp[j] != -1 ) {
                if( v[i].xx >= dp[j] ) {
                    upd(temp[j+1],dp[j]+v[i].yy);
                }
            }
        }
        dp = temp;
    }
    FOR(i,n+1,0) {
        if( dp[i] != -1 ) {
            cout<<i<<"\n";
            return 0;
        }
    }
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;

const long double PI = (acos(-1));
const long double EPS = 0.0000000001;

long double a, b, x;

void input() {
    cin >> a >> b >> x;
}

long double f(long double a, long double b, long double x) {
    long double ans;
    if(a * a * b / 2.0 <= x) {
        ans = atan(2 * (a * a * b - x) / (a * a * a));
    } else {
        ans = PI / 2 - atan(2 * x / (a * b * b));
    }
    return ans;
}

void solve() {
    input();
    cout << fixed << setprecision(10) << f(a, b, x) * 180.0 / PI << endl;
    return;
}

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


Measured memory_bytes: 3820
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <numeric>
#include <iomanip>
#include <set>
#include <string.h>

using namespace std;

typedef long long ll;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define REP3(i,st,en) for(ll (i)=(st);(i)<(en);(i)++)

using P = pair<ll, ll>;
const int MOD = 1e9+7;
const ll INF = 1e+14;
const double PI = 3.14159265349;



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

  ll N;
  cin >> N;
  vector<ll> T(N);
  REP(i,N){ cin >> T[i]; }

  ll sum = accumulate(T.begin(), T.end(), 0);

  ll M;
  cin >> M;
  REP(i,M){
    ll p, x;
    cin >> p >> x;
    cout << sum - T[p-1] + x << "\n";
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <queue>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define int long long
#define INF 1e9 + 7
#define cae cout << ans << endl;
#define cye cout << "Yes" << endl;
#define cne cout << "No" << endl;
#define r0 return 0;
using namespace std;
typedef pair<int,int>P;
typedef long long ll;
signed main() {
    int a, b;
    cin >> a >> b;
    cout<<(b-1+a-1-1)/(a-1)<<endl;
    r0
}


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

struct Sieve {
  int n;
  vector<int> f, primes;
  Sieve(int n=1):n(n), f(n+1) {
    f[0] = f[1] = -1;
    for (ll i = 2; i <= n; ++i) {
      if (f[i]) continue;
      primes.push_back(i);
      f[i] = i;
      for (ll j = i*i; j <= n; j += i) {
        if (!f[j]) f[j] = i;
      }
    }
  }
  bool isPrime(int x) { return f[x] == x;}
  vector<int> factorList(int x) {
    vector<int> res;
    while (x != 1) {
      res.push_back(f[x]);
      x /= f[x];
    }
    return res;
  }
  vector<P> factor(int x) {
    vector<int> fl = factorList(x);
    if (fl.size() == 0) return {};
    vector<P> res(1, P(fl[0], 0));
    for (int p : fl) {
      if (res.back().first == p) {
        res.back().second++;
      } else {
        res.emplace_back(p, 1);
      }
    }
    return res;
  }
};



void solve(long long N, std::vector<long long> A){
    vector<int> f(10000000);
    ll ans = 0;
    rep(i,N){
        ll d = A[i];
        if(f[d] != 0){
            f[d] = 2;
            continue;
        }
        for (ll j = d; j <= 10000000; j += d) {
            f[j] += 1;
        }
    }
    rep(i,N){
        ll d = A[i];
        if(f[d] == 1) ans++;
    }

    cout << ans << endl;
    
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 43852
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Optional;
import java.util.OptionalDouble;
import java.util.stream.DoubleStream;
import java.util.stream.Stream;

public class Main {

  public static void main(String[] args) throws IOException {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      String line;
      String[] lines;
      double[] s;
      while( !(line = br.readLine()).equals("0") ){

        int n = Integer.parseInt(line);
        lines = br.readLine().split(" ");

        s =
          Stream.of(lines)
            .mapToDouble(Double::parseDouble)
            .toArray();
        
        double dm =
          Arrays.stream(s)
            .average()
          .getAsDouble();

        double result =
        Arrays.stream(s)
          .map(d -> Math.pow((d-dm),2))
          .sum();
        result = Math.sqrt((result)/n);

        System.out.printf("%.8f\n" ,result);
      }
    }
  }
}


Measured memory_bytes: 32176
#include "bits/stdc++.h"
#define ll long long int
#define ld long double
#define fastIO ios_base::sync_with_stdio(false); cin.tie(nullptr)
#define F first
#define S second
#define INF 100000000

using namespace std;
typedef pair<int, int> pii;

int r, c;
vector<vector<char>> g;
bool isSafe(int row, int col) {
    return row < r && row >= 0 && col < c && col >= 0 && g[row][col] == '.';
}

int main() {
    fastIO;
    int startX, startY, endX, endY;
    cin >> r >> c >> startX >> startY >> endX >> endY;
    startX--, startY--, endX--, endY--;

    g = vector<vector<char>>(r, vector<char>(c));
    int dist[r][c];

    for (int i = 0; i < r; i++) {
        for (int j = 0; j < c; j++) {
            dist[i][j] = INF;
            cin >> g[i][j];
        }
    }

    deque<pii> q;
    q.push_back({endX, endY});

    int dx[] = {0, 0, -1, 1};
    int dy[] = {1, -1, 0, 0};

    dist[endX][endY] = 0;

    while (!q.empty()) {
        pii p = q.front();
        q.pop_front();
        int x = p.F, y = p.S;

        for (int i = 0; i < 4; i++) {
            int nx = x + dx[i], ny = y + dy[i];
            if (isSafe(nx, ny) && dist[x][y] < dist[nx][ny]) {
                dist[nx][ny] = dist[x][y];
                q.push_front({nx, ny});
            }
        }

        for (int i = x - 2; i <= x + 2; i++) {
            for (int j = y - 2; j <= y + 2; j++) {
                if (isSafe(i, j) && dist[x][y] + 1 < dist[i][j]) {
                    dist[i][j] = dist[x][y] + 1;
                    q.push_back({i, j});
                }
            }
        }
    }

    if (dist[startX][startY] >= 1000000) cout << -1;
    else cout << dist[startX][startY];

}


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

typedef long long LL;

const int N=300,mod=998244353;

int add(int a,int b,int p=mod){return a+b>=p?a+b-p:a+b;}
int sub(int a,int b,int p=mod){return a-b<0?a-b+p:a-b;}
int mul(int a,int b,int p=mod){return (LL)a*b%p;}
void sadd(int &a,int b,int p=mod){a=add(a,b,p);}
void ssub(int &a,int b,int p=mod){a=sub(a,b,p);}
void smul(int &a,int b,int p=mod){a=mul(a,b,p);}

int n,a[N+9],sum;

void into(){
  scanf("%d",&n);
  for (int i=1;i<=n;++i){
	scanf("%d",&a[i]);
	sum+=a[i];
  }
}

int dp[N*N+9],ans;

void Get_dp(){
  dp[0]=1;
  for (int i=1;i<=n;++i)
	for (int j=sum;j>=0;--j){
	  smul(dp[j],2);
	  if (j>=a[i]) sadd(dp[j],dp[j-a[i]]);
	}
  ans=1;
  for (int i=1;i<=n;++i) smul(ans,3);
  for (int i=sum+1>>1;i<=sum;++i) ssub(ans,mul(dp[i],3));
  if (sum&1) return;
  for (int i=0;i<=sum;++i) dp[i]=0;
  dp[0]=1;
  for (int i=1;i<=n;++i)
	for (int j=sum;j>=a[i];--j) sadd(dp[j],dp[j-a[i]]);
  sadd(ans,mul(dp[sum>>1],3));
}

void work(){
  Get_dp();
}

void outo(){
  printf("%d\n",ans);
}

int main(){
  into();
  work();
  outo();
  return 0;
}

Measured memory_bytes: 4144
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>

/*
#include<boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/rational.hpp>
namespace mp = boost::multiprecision;
using Real = mp::number<mp::cpp_dec_float<1024>>;
using Bint = mp::cpp_int;
*/

using namespace std;

#define int long long
#define REP(i,s,e) for((i)=(s);(i)<(e);(i)++)
#define RREP(i,s,e) for((i)=((s)-1);(i)>=(e);(i)--)
#define FOR(i,n) for((i)=(0);(i)<(n);(i)++)
#define RFOR(i,n) for((i)=((n)-1);(i)>=(0);(i)--)
#define MOD 1000000007

signed main(){
    int N,K;
    int P[5001];
    int C[5001];

    cin>>N>>K;
    for(int i=1;i<=N;i++){
        cin>>P[i];
    }
    for(int i=1;i<=N;i++){
        cin>>C[i];
    }

    int ans=LLONG_MIN;
    for(int i=1;i<=N;i++){
        int c=C[i];
        ans=max(ans,c);
        int n=P[i];
        int k=K-1;
        bool f=true;
        while(k>0){
            c+=C[n];
            ans=max(ans,c);
            n=P[n];
            k--;
            if(n==i&&f){
                f=false;
                if(c<=0){
                    break;
                }
                int a=K-k;
                int b=K/a;
                int d=K%a;
                if(b>0){
                    b--;
                    d+=a;
                }
                k=d;
                c*=b;
                ans=max(ans,c);
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3236
#include<bits/stdc++.h> 
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for(int i = 0; i < N; i++)

struct mint{
    using i64 = int_fast64_t;
    const i64 MOD = 1000000007;
    i64 x;

    mint(const i64 y = (i64)0) noexcept : x(y) { 
        if(x >= MOD) x %= MOD; 
        if(x < 0) x += MOD;
    }
    mint operator+() const noexcept {return x;}
    mint operator-() const noexcept {return x ? MOD - x : 0;}
    mint operator+(const mint y) const noexcept {return (mint)*this += y; }
    mint operator-(const mint y) const noexcept {return (mint)*this -= y; }
    mint operator*(const mint y) const noexcept {return (mint)*this *= y;}
    mint operator/(const mint y) const noexcept {return (mint)*this /= y;}

    mint operator=(const mint y) noexcept {
        x = y.x;
        if(x >= MOD) x -= MOD;
        if(x < 0) x += MOD;
        return *this;
    }
    mint operator=(const i64 y) noexcept {
        x = y;
        if(x >= MOD) x -= MOD;
        if(x < 0) x += MOD;
        return *this;
    }
    mint& operator+=(const mint y) noexcept {
        x += y.x; 
        if(x >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint y) noexcept {
        x -= y.x;
        if(x < 0) x += MOD;
        return *this;
    }
    mint& operator*=(const mint y) noexcept {
        x *= y.x;
        if(x >= MOD) x %= MOD;
        return *this;
    }
    mint& operator/=(mint y) noexcept {
        i64 exp = MOD - 2;
        while(exp){
            if(exp & 1) *this *= y;
            y *= y;
            exp /= 2;
        }
        return *this;
    }
    friend std::ostream& operator<< (std::ostream& os, const mint& m) noexcept {
        os << m.x;
        return os;
    }
    friend std::istream& operator>> (std::istream& in, mint& m) noexcept {
        const int mod = 1000000007;
        in >> m.x; 
        if(m.x < 0) m.x += mod;
        if(m.x >= mod) m.x %= mod;
        return in; 
    }
    friend mint mod_pow(mint n, i64 k) noexcept {
        mint res = 1;
        while(k){
            if(k&1) res *= n;
            n *= n;
            k >>= 1;
        }
        return res;
    }
};

int main(){
    string S;
    cin >> S;

    int L = S.size();
    vector<vector<mint>> dp(L+1, vector<mint>(13, 0));
    dp[0][0] = 1;

    for(i64 d = 0; d < L; d++){
        for(i64 i = 0; i < 10; i++){
            if(S[d] != '?' && (S[d] - '0') != i) continue;
            for(i64 s = 0; s < 13; s++){
                i64 x = (s*10 + i) % 13;
                dp[d+1][x] += dp[d][s];
            }
        }
    }
    cout << dp[L][5] << endl;
}


Measured memory_bytes: 27484
#include <stdio.h>
#include <stdlib.h>

#define N 100

int compare(const void *a, const void *b) {
	int ia = *(int *) a;
	int ib = *(int *) b;

	return ia - ib;
}

int main() {
	static int aa[N];
	int n, i, sum;

	scanf("%d", &n);
	sum = 0;
	for (i = 0; i < n; i++)
		scanf("%d", &aa[i]);
	qsort(aa, n, sizeof *aa, compare);
	for (i = 1; i < n; i++)
		sum += aa[i] - aa[i - 1];
	printf("%d\n", sum);
	return 0;
}


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

int main(){
	while(true){
		int n,c0=0,c1=0;
		cin>>n;
		if(n==0) break;
		int k[n];
		for(int i=0;i<n;i++){
			cin>>k[n];
			if(k[n]==0) c0++;
			if(k[n]==1) c1++;
		}
		if(n==c0+c1) cout<<"NA"<<endl;
		else cout<<n-c0+1<<endl;
	}
	return 0;
}

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

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	double d, t, s; cin >> d >> t >> s;
	double T=d/s;
	if(T<=t) cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 3732
#include "stdio.h"

int main(void)
{
    int a,b,c,d;
    int i;
    int flag=0;

    scanf("%d",&a);
    scanf("%d",&b);
    scanf("%d",&c);
    scanf("%d",&d);

    for(i=0;i<=100;i++)
    {
        c=c-b;
        if(c<=0)
        {
            flag=1;
            break;
        }
        a=a-d;
        if(a<=0)
        {
            flag=2;
            break;
        }
    }

    if(flag ==1)
    {
        printf("Yes");
    }
    else if (flag==2)
    {
        printf("No");
    }
    return 0;
}

Measured memory_bytes: 1728
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>

#define CK(N,A,B) (A<=N&&N<B)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define RREP(i,a,b) for(int i=(b-1);a<=i;i--)
#define F first
#define S second
#define ll long long

const int INF = 1e9;
const long long  LLINF = 1e18;

using namespace std;


/*==================================================*/

/*==================================================*/

int A, B, C, D, E, F;
int slt[6010];

double rate;
int ansslt;
int answtr;

void func(int na, int nb){
  for(int wa = na; wa*100 <= F; wa += A){
    for(int wb = nb; wb*100 <= F; wb += B){
      for(int sc = 0; sc <= F; sc += C){
        for(int sd = 0; sd <= F; sd += D){

          if(wa*100+wb*100+sc+sd > F) continue;
          if(sc+sd > (wa+wb)*E) continue;

          if( ansslt*(wa*100+wb*100) <= answtr*(sc+sd)){
            ansslt = sc+sd;
            answtr = wa*100+wb*100;
          }

          // if(rate < (double)(sc+sd)/(double)(sc+sd+wa*100+wb*100)){
          //   rate = (double)(sc+sd)/(double)(sc+sd+wa*100+wb*100);
          //   ansslt = sc+sd;
          //   answtr = wa*100+wb*100;
          // }
        }

      }
    }
  }
}

int main(){

  cin>>A>>B>>C>>D>>E>>F;

  // func(A,0);
  // func(0,B);
  func(0,0);
  cout<<ansslt+answtr<<" "<<ansslt<<endl;


  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int f(int n) {
	int r =0;
	while (n) {
		r += n % 10;
		n /= 10;
	}return r;
}
int main() {
	int a; cin >> a;
	int ans = 114514;
	for (int i = 1; i < a; i++) {
		ans = min(ans, f(i) + f(a - i));
	}
	cout << ans << endl;
}

Measured memory_bytes: 888
import itertools

n, m, q = map(int, input().split())
a = [0 for i in range(q)]
b = [0 for i in range(q)]
c = [0 for i in range(q)]
d = [0 for i in range(q)]

for i in range(q):
    a[i], b[i], c[i], d[i] = map(int, input().split())

score = 0
for SR in itertools.combinations_with_replacement(range(1, m+1), n):
    now = 0
    for i in range(q):
        now += d[i] if SR[b[i]-1] - SR[a[i]-1] == c[i] else 0
    score = max(score, now)

print(score)

Measured memory_bytes: 9172
import           Control.Monad

main :: IO ()
main = do
    n <- readLn
    abs <- replicateM n (map read . words <$> getLine)
    print $ solve abs

solve :: [[Int]] -> Int
solve = foldr f 0
    where 
        f [a, b] n = if (a + n) `mod` b == 0
            then n
            else n + b - ((a + n) `mod` b)


Measured memory_bytes: 150908
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

const vector<int> vx = {0,1,0,-1};
const vector<int> vy = {-1,0,1,0};

int main(){
  int h,w;
  cin >> h >> w;
  vector<string> s(h);
  for(int i=0;i<h;i++) cin >> s[i];

  vector<vector<int>> dist(h,vector<int>(w));
  queue<pair<int,int>> que;

  int ans = 0;

  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(s[i][j] == '#') continue;

      for(int i=0;i<h;i++) dist[i].assign(w,-1);

      //スタートの設定
      dist[i][j] = 0;
      que.push(make_pair(i,j));

      //bfs開始
      while(!que.empty()){
        //キューから先頭取り出し
        pair<int,int> v = que.front();
        que.pop();

        int vh = v.first;
        int vw = v.second;

        //ｖから辿れる頂点をすべて調べる
        for(int i=0;i<4;i++){
          int nh = vh + vy[i];
          int nw = vw + vx[i];

          if(nh < 0 || nh >= h || nw < 0 || nw >= w) continue;

          if(dist[nh][nw] != -1) continue;
          if(s[nh][nw] == '#') continue;

          dist[nh][nw] = dist[vh][vw] + 1;
          que.push(make_pair(nh,nw));
        }
      }

      //このパターンでの最大移動回数を求める
      int cnt = 0;
      for(int ih=0;ih<h;ih++){
        for(int iw=0;iw<w;iw++){
          cnt = max(cnt,dist[ih][iw]);
        }
      }

      //最終解と比較
      ans = max(ans,cnt);
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int, K: int):
    if N > K:
        print(min(N % K,abs(N % K-K)))
    else :
        N = K - N
        print(min(N % K,abs(N % K-K)))

    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    K = int(next(tokens))  # type: int
    solve(N, K)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060