akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 1000000007
#define int long long
#define INF 1145141919810364364
#define all(vec) vec.begin(),vec.end()
#define P pair<int,int>
#define S second
#define F first

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
bool prime(int x) {
	for (int i = 2; i <= sqrt(x); i++) {
		if (x%i == 0)return false;
	}
	return true;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int n, m;

signed main() {
	cin >> n >> m;
	cout << comb(n, 2) + comb(m, 2) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
using namespace std;
const int mod = 1000000007;
#define ll long long

int main()
{
	int x, a, b;
	cin >> x >> a >> b;
	if (abs(x - a) < abs(x - b)) cout << 'A' << endl;
	else cout << 'B' << endl;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    ll n,m; cin>>n>>m;
    vector<ll> x(m,0);
    rep(i,m) cin>>x[i];
    if(n>=m) cout<<0<<endl;
    else{
        sort(al(x));
        vector<ll> d(m-1,0);
        rep(i,m-1) d[i]=x[i+1]-x[i];
        sort(al(d));
        ll ans=0;
        rep(i,m-n) ans+=d[i];
        cout<<ans<<endl; 
    }
}

Measured memory_bytes: 1920
#include<stdio.h>
#include<stdlib.h>
void judge(int n, int *A, int *B);

int main(){
  int n,i;
  int *A, *B;
  //init
  scanf("%d",&n);
  while(n != 0){
    A = (int*)malloc(sizeof(int) * n);
    B = (int*)malloc(sizeof(int) * n);

    for(i=0;i<n;i++){
      scanf("%d %d",&A[i], &B[i]); 
    }   
    //Judge and Output
    judge(n, A, B);

    free(A); free(B);
    scanf("%d",&n);
  }

  return 0;
}

/* 勝敗の判定と出力する関数 */
void judge(int n, int *A, int *B){
  int i;
  int Ap=0, Bp=0;

  for(i=0; i<n; i++){
    if(A[i] == B[i]){
      Ap += A[i];
      Bp += B[i];
    }
    else if(A[i] > B[i]){
      Ap += A[i] + B[i];
    }
    else{
      Bp += A[i] + B[i];
    }
  }

  printf("%d %d\n",Ap ,Bp);
}

Measured memory_bytes: 676
N = reversed("0" + input())
digit = next(N)
total = 0
carry = 0
for nextdigit in N:
    digit = int(digit) + carry
    if digit < 5:
        total += digit
        carry = 0
    elif digit == 5:
        if int(nextdigit) < 5:
            total += digit
            carry = 0
        else:
            total += 10 - digit
            carry = 1
    else:
        total += 10 - digit
        carry = 1
    digit = nextdigit

print(total + carry)


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

int main() {
  int N;
  cin >> N;
  vector<vector<int>> A(2,vector<int>(N));
  rep(i,2){
    rep(j,N){
      cin >> A[i][j];
    }
  }
  vector<vector<int>> dp(2,vector<int>(N));
  dp[0][0] = A[0][0];
  dp[1][0] = A[1][0] + A[0][0];
  rep(i,2){
    rep2(j,1,N){
      if(i == 0){
        dp[i][j] = A[i][j] + dp[i][j-1];
      }else{
        dp[i][j] = A[i][j] + max(dp[i][j-1], dp[i-1][j]);
      }
    }
  }
  cout << dp[1][N-1] << endl;
  return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>
#include <time.h>
#include <bitset>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

ll N, K;

int main() {

	cin >> N >> K;
	ll mi = 0, ma = 0;

	rep(i, K) {
		mi += i;
		ma += N - i;
	}

	ll ans = 1;
	for (ll i = K; mi < ma; ++i) {
		ans += ma - mi + 1;
		ans %= 1000000007;
		mi += i;
		ma += N - i;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#include <ext/pb_ds/detail/standard_policies.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag,
		tree_order_statistics_node_update> ordered_set;

#define el				'\n'
#define sz(v)			((int)((v).size()))
#define all(v)          ((v).begin()),((v).end())
#define clr(v, d)		memset(v, d, sizeof(v))

double const EPS = 1e-8, PI = acos(-1);
const int N = 405 + 9, M = 100 + 9, OO = (int) 1e9 + 1;
const long long MOD = 1e9 + 7, INF = 1e18 + 9;

typedef long long ll;

void OUTPUT() {
	cout << fixed << setprecision(12);
	ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
}

void INPUT() {
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif
}
int n, arr[N];
ll dp[N][N], cum[N];
int main() {
//	INPUT();
	OUTPUT();
	cin >> n;
	for (int i = 0; i < n; ++i) {
		cin >> arr[i];
		cum[i] = arr[i] + cum[i - 1] * (i != 0);
	}
	for (int L = n - 1; L >= 0; L--) {
		for (int R = L; R < n; R++) {
			if (L == R)
				dp[L][R] = 0;
			else {
				dp[L][R] = INF;
				ll s = cum[R];
				if (L != 0)
					s -= cum[L - 1];
				for (int i = L; i < R ; i++) {
					dp[L][R] = min(dp[L][R], dp[L][i] + dp[i + 1][R] + s);
				}
			}
		}
	}
	cout << dp[0][n - 1];

	return 0;

}


Measured memory_bytes: 1536
using static System.Math;using static System.Console;using System.Collections.Generic;using System.Linq;using System;using System.Collections;
using System.Runtime.Serialization;
using System.Collections.Specialized;
using System.Security.Cryptography;
using System.Globalization;

class Program
{
    #region Reader
    static string ReadStr => Console.ReadLine();
    static string[] ReadStrs => Console.ReadLine().Split(' ');
    static int ReadInt => Convert.ToInt32(Console.ReadLine());
    static int[] ReadInts => Console.ReadLine().Split(' ').Select(s => Convert.ToInt32(s)).ToArray();
    static long ReadLong => Convert.ToInt64(Console.ReadLine());
    static long[] ReadLongs => Console.ReadLine().Split(' ').Select(s => Convert.ToInt64(s)).ToArray();
    #endregion
    #region Method
    static int mod = (int)Pow(10, 9) + 7;
    public static int Mod(int a,int mod) { return a % mod >= 0 ? a % mod : a % mod + mod; }
    public static long Mod(long a, int mod) { return a % mod >= 0 ? a % mod : a % mod + mod; }
    #endregion


    #region Mod
    public static long GetInv(long a, long mod = 1000000007)
    {
        return PowerMod(a, mod - 2, mod);
    }
    public static long Combination(long a, long b, long mod = 1000000007)
    {
        if (b < 0 || b > a) return 0;
        if (b > a / 2) b = a - b;
        long numerator = Factorial(a, mod);
        long denominator = (Factorial(b, mod) * Factorial(a - b, mod)) % mod;

        return (numerator * GetInv(denominator, mod)) % mod;
    }
    public static long Factorial(long n, long mod = 1000000007)
    {
        if (n == 0) return 1;
        if (n == 1) return 1;
        long ans = n;
        for (int i = 2; i < n; i++)
        {
            ans = (ans * i) % mod;
        }

        return ans;
    }
    private static long PowerMod(long a, long n, long mod = 1000000007)
    {
        if (n == 0) return 1;
        if (n == 1) return a;

        long p = PowerMod(a, n / 2, mod);
        if (n % 2 == 1) return ((p * p) % mod * a) % mod;
        else return (p * p) % mod;
    }
    #endregion


    static void Main()
    {
        int[] NM = ReadInts;


        WriteLine(PowerMod(NM[0],NM[1]));

    }

}



Measured memory_bytes: 18552
# -*- coding: utf-8 -*-

"""
参考：https://qiita.com/drken/items/03c7db44ccd27820ea0d
・確率DP
"""

import sys, re
from collections import deque, defaultdict, Counter
from math import sqrt, hypot, factorial, pi, sin, cos, radians
if sys.version_info.minor >= 5: from math import gcd
else: from fractions import gcd 
from heapq import heappop, heappush, heapify, heappushpop
from bisect import bisect_left, bisect_right
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from functools import reduce, partial
from fractions import Fraction
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def ceil(a, b=1): return int(-(-a // b))
def round(x): return int((x*2+1) // 2)
def fermat(x, y, MOD): return x * pow(y, MOD-2, MOD) % MOD
def lcm(x, y): return (x * y) // gcd(x, y)
def lcm_list(nums): return reduce(lcm, nums, 1)
def gcd_list(nums): return reduce(gcd, nums, nums[0])
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N = INT()
pN = list(map(float, input().split()))

# dp[コインを投げた枚数][表が出た枚数] = そうなる確率
dp = [[0] * (N+1) for i in range(N+1)]
# 0枚投げて0になるのは100%
dp[0][0] = 1

for i in range(N):
    # 投げた枚数より表が多く出る訳ないのでi=jまで回せばOK
    for j in range(i+1):
        # 裏になる確率を下に送る
        dp[i+1][j] += dp[i][j] * (1-pN[i])
        # 表になる確率を右下に送る
        # 内ループは短く回るので添字オーバーは気にしなくていい
        dp[i+1][j+1] += dp[i][j] * (pN[i])

print('{:.10f}'.format(sum(dp[N][ceil(N, 2):])))


Measured memory_bytes: 256628
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = int64_t;
using vi = vector<int>;
using vl = vector<int64_t>;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define debug(x) cerr << #x << ": " << (x) << '\n'
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}
// constant
const int INF = (1<<30) - 1;
const int64_t INF64 = (1LL<<62) - 1;
const int MOD = 1000000007;
char in[1<<21];
char const*o;

inline void init_in() { 
  o = in;
  in[fread(in,1,sizeof(in)-4,stdin)] = 0;
}

int readInt(){ 
  unsigned u = 0, s = 0;
  while(*o && *o <= 32){
    ++o;
  }
  if (*o == '-'){
    s = ~s, ++o;
  } else if (*o == '+'){
    ++o;
  }
   
  while(*o>='0' && *o<='9'){
    u = (u<<3) + (u << 1) + (*o++ - '0');
  }

  return static_cast<int>((u^s) + !!s) ;
}
int main(){
  //ios_base::sync_with_stdio(false);
  //cin.tie(nullptr);

  init_in();
  int n = readInt();
  vector<int> a(n);
  rep(i, n) a[i] = readInt();

  for (int i = n - 1; i >= 1; --i) {
    if (a[i] < a[i - 1]) {
      --a[i - 1];
    }
  }

  for (int i = 0; i < n - 1; ++i) {
    if (a[i] > a[i + 1]) {
      print("No"); return 0;
    }
  }

  print("Yes");

  return 0;
}


Measured memory_bytes: 1664
# D
from collections import deque

# create graph
G = dict()
G_inv = dict()
N, M = map(int, input().split())
for n in range(1, N+1):
    G[n] = dict()
    G_inv[n] = dict()

for _ in range(M):
    a, b, c = map(int, input().split())
    G[a][b] = c
    G_inv[b][a] = c

# value
values = [-1000000000*2000]*(N+1)
values[1] = 0

reachable = [0]*(N+1)
reachable[N] = 1
# find reachble points
dr = deque([N])
while len(dr) > 0:
    b = dr.popleft()
    for a in G_inv[b].keys():
        if reachable[a] == 0:
            reachable[a] = 1
            dr.append(a)

# BFS
inc_cnt = 0
d = deque([1])
while len(d) > 0:
    a = d.popleft()
    for b in G[a].keys():
        if values[b] < values[a] + G[a][b] and reachable[b] == 1:
            values[b] = values[a] + G[a][b]
            inc_cnt += 1
            d.append(b)
    if inc_cnt > 2000:
        break
if inc_cnt > 1000:
    print('inf')
else:
    print(values[N])

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

vector<vector<ll>> G;
vector<ll> X;
vector<ll> ans;

void dfs(int v, int p, ll x) {
    ans[v] = x + X[v];
    for ( int q : G[v] ) {
        if ( q == p ) continue;
        dfs(q, v, ans[v]);
    }
};

ll solve() {
    ll N, Q, a, b, p, x;
    cin >> N >> Q;
    G.assign(N,vector<ll>());
    X.assign(N,0);
    ans.assign(N,0);
    for ( int i = 0; i < N-1; i++ ) {
        cin >> a >> b;
        a--, b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    for ( int i = 0; i < Q; i++ ) {
        cin >> p >> x;
        p--;
        X[p] += x;
    }

    dfs(0, -1, 0);
    for ( int i = 0; i < N; i++ ) {
        cout << ans[i] << " ";
    }
    cout << "\n";
    
    return 0;
}

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

Measured memory_bytes: 25856
from fractions import gcd
from functools import reduce
import numpy as np

def lcm_base(x, y):
    return (x * y) // gcd(x, y)

def lcm(numbers):
    return reduce(lcm_base, numbers, 1)

N, M = map(int, input().split())

A = list(map(int, input().split()))
A = list(map(lambda x: x // 2 , A))
A = np.array(A)

l = lcm(A)

if ((l//A % 2 == 1).sum() != N):
    print(0)
else:
    ans = (M//l + 1) // 2
    print(ans)

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

using namespace std;

const long long MOD = 1000000007;

int main() {

    int N;
    cin >> N;
    int a[N - 1], b[N - 1];
    vector<vector<int> > graph(N);
    map<pair<int,int>,int >ans;
    for (int i = 0; i < N - 1; i++) {
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
        graph[a[i]].push_back(b[i]);
        graph[b[i]].push_back(a[i]);
        ans[make_pair(a[i],b[i])]=-100;
        ans[make_pair(b[i],a[i])]=-100;



    }
    int kazu = -1;
    int kaishi;
    for (int i = 0; i < N; i++) {
        if (kazu < (int)graph[i].size()) {
            kazu = graph[i].size();
            kaishi=i;
        }
    }


    queue<int> bfs;
    bfs.push(kaishi);
    int used[N];
    for(int i=0;i<N;i++){
        used[i]=-1;
    }
    int dokokara[N];
    for(int i=0;i<N;i++){
        dokokara[i]=-100;
    }
    used[kaishi]=1;
    int maenoiro=-8;
    while (bfs.size() > 0) {
        int m=bfs.front();
        used[m]=1;
        bfs.pop();
        int iro=-1;

        for(int i=0;i<graph[m].size();i++){
            if(used[graph[m][i]]==1){
                continue;
            }
            iro++;

            if(ans[make_pair(dokokara[m],m)]==iro&&m!=kaishi){
                iro++;
            }

            ans[make_pair(m,graph[m][i])]=ans[make_pair(graph[m][i],m)]=iro;
            dokokara[graph[m][i]]=m;

            bfs.push(graph[m][i]);
        }
        //cout<<dokokara[m]<<endl;
        maenoiro=iro-1;
        //cout<<maenoiro<<endl;
        //cout<<m<<endl;
        //cout<<""<<endl;



    }
    cout<<kazu<<endl;
    for (int i = 0; i < N-1 ; i++) {
        cout<<ans[make_pair(a[i],b[i])]+1<<endl;
    }


}













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

int main() {
	int N = 0;
	cin >> N;
	int d;
	int ans = 0;
	vector<bool> is(101, false);
	for (int i = 0; i < N; i++) {
		cin >> d;
		if (!is[d]) {
			ans++;
			is[d] = true;
		}
	}
	cout << ans;
}

Measured memory_bytes: 256
/**
*    created: 07.07.2020 14:35:26
**/
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
// #include <boost/multiprecision/cpp_int.hpp>
// using bint = boost::multiprecision::cpp_int;
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define pcnt(bit) __builtin_popcountll(bit)
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> bool chmin(T &a, const T &b) {if (b < a) {a = b; return 1;} return 0;}
const long double pi = acos(-1.0);
const int INF = 1LL << 60;
const int MOD = 1000000007;
// const int MOD = 998244353;

signed main() {

    cin.tie(0);
    ios_base::sync_with_stdio(false);

    int x, a, b;
    cin >> x >> a >> b;
    int ov = b-a;
    if (ov <= 0) cout << "delicious" << endl; 
    else if (ov <= x) cout << "safe" << endl;
    else cout << "dangerous" << endl;
    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <cmath>
using namespace std;
int main()
{
    int N, T, A;
    cin >> N >> T >> A;
    vector<int> H;
    for(int i=0; i<N; i++)
    {
    	int x;
    	cin >> x;
        H.push_back(x);
    } 

    int cnt = 0; 
    double dist = fabs((double)(T) - (double)(H[0]) * 0.006-(double) (A));
    for(int i=1; i<N; i++)
    {
    	double temp = (double)(T) - (double)(H[i]) * 0.006;
    	if(fabs(temp-(double) (A))<dist) {
    		cnt = i;
    		dist = fabs(temp-(double) (A));
    		} 
    }

    cout << cnt + 1 << endl;
	return 0;
}


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

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

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iostream>
#include <sstream>
#include <functional>
#include <map>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <list>
#include <numeric>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> P;
const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;
#define rep(i,n) for(int (i)=0;(i)<(ll)(n);++(i))
#define repd(i,n,d) for(ll (i)=0;(i)<(ll)(n);(i)+=(d))
#define all(v) (v).begin(), (v).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))
#define mset(m,v) memset((m),(v),sizeof(m))
#define chmin(X,Y) ((X)>(Y)?X=(Y),true:false)
#define chmax(X,Y) ((X)<(Y)?X=(Y),true:false)
#define fst first
#define snd second
#define UNIQUE(x) (x).erase(unique(all(x)),(x).end())
template<class T> ostream &operator<<(ostream &os, const vector<T> &v){int n=v.size();rep(i,n)os<<v[i]<<(i==n-1?"":" ");return os;}

#define N 100010
ll n, A[2], s[N], x[2][N], r[2][N], dp[N];

int main(){
	cin>>n>>A[0]>>A[1];
	//if(A[0]<A[1]) swap(A[0], A[1]);
	rep(i, n) cin>>s[i];
	rep(i, 2){
		r[i][n] = n;
		r[i][n-1] = n;
		for(int j = n-2; j>=0; j--){
			if(s[j+1]-s[j]>=A[i]) r[i][j] = r[i][j+1];
			else r[i][j] = j;
		}
		int left = 0, right = 0;
		while(left<n){
			while(right<n && s[right]-s[left]<A[i]) right++;
			x[i][left] = right;
			left++;
		}
	}
	dp[0] = 1;
	rep(j, n){
		if(!dp[j]) continue;
		rep(i, 2){
			int i2 = i;
			int j2 = j;
			while(true){
				//cerr<<i<<" "<<j<<" "<<i2<<" "<<j2<<endl;
				if(x[i2][j2]>r[!i2][j2+1]+1) break;
				if(x[i2][j2]<=r[!i2][j2+1]){
					(dp[x[i2][j2]]+=dp[j])%=mod;
					break;
				}
				j2 = x[i2][j2]-1;
				i2 = !i2;
			}
			//cerr<<"LAST: "<<i<<" "<<j<<" "<<i2<<" "<<j2<<" "<<x[i2][j2]<<" "<<r[!i2][j2+1]<<endl;
		}
		//cerr<<"DP: "<<j<<endl;
		//rep(i, n+1) cerr<<dp[i]<<" "; cerr<<endl;
	}
	cout<<dp[n]<<endl;
	/*
	cerr<<"DEBUG"<<endl;
	cerr<<"x"<<endl;
	rep(i, n+1) cerr<<x[0][i]<<" "<<x[1][i]<<endl;
	cerr<<"r"<<endl;
	rep(i, n+1) cerr<<r[0][i]<<" "<<r[1][i]<<endl;
	cerr<<"dp"<<endl;
	rep(i, n+1) cerr<<dp[i]<<endl;
	*/

	return 0;
}


Measured memory_bytes: 4992
from copy import deepcopy
h, w, K = map(int, input().split())

g = [[0] * w for _ in range(h)]
for i in range(h):
    li = list(input())
    for j in range(len(li)):
        if li[j] == '#':
            g[i][j] = 1
ans = 0
for i in range(2<<h):
    for j in range(2<<w):
        gg = deepcopy(g)
        for k in range(h):
            for l in range(w):
                if ((i>>k)&1):
                    for mm in range(w):
                        gg[k][mm] = 0
                if ((j>>l)&1):
                    for m in range(h):
                        gg[m][l] = 0
        sum_ = 0
        for kk in range(h):
            for ll in range(w):
                sum_ += gg[kk][ll]
        if sum_ == K:
            ans += 1
print(ans//4)


Measured memory_bytes: 74636
#include <cstdio>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <cmath>
#include <string>
#include <map>
#include <unordered_map>
#include <queue>

using namespace std;

typedef long long LL;

int main() {
  int x, l;
  string s;
  cin >> s;
  cin >> x;
  l = s.length();
  for (int i = 0; i < l; i += 1) {
    if (s[i] != 'a') {
      if ('z' - s[i] + 1 <= x) {
        x -= 'z' - s[i] + 1;
        s[i] = 'a';
      }
    }
  }
  if (x != 0) {
    s[l - 1] = (s[l - 1] + x - 'a') % 26 + 'a';
  }
  cout << s << endl;
  return 0;
}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

using namespace std;

int main(){
    string s1;
    string s2;
    cin >> s2;
    int q;
    cin >> q;
    for(int i=0; i<q; i++){
        int q_y;
        cin >> q_y;
        if(q_y == 1){
          swap(s1, s2);
        }else if(q_y == 2){
          int f;
          char c;
          cin >> f;
          cin >> c;
          if(f == 1){
             s1 += c;
          }else if(f == 2){
             s2 += c;
          }
        }
    }

    reverse(s1.begin(), s1.end());
    s1 += s2;
    cout << s1 << endl;
    return 0;
}


Measured memory_bytes: 1128
import java.util.*;
public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		int t = s.length() - 2;
		String result = "";
		result = s.charAt(0) + String.valueOf(t) + s.charAt(s.length() -1);
		System.out.println(result);
	}
}

Measured memory_bytes: 23892
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<queue>
#include<cmath>
#include<functional>

using namespace std;

long f(vector<long>& A, vector<long>& F, long T){
    long sum=0;
    for(int i=0;i<A.size();i++){
        long s = (A[i]*F[i]-T);
        if(s <= 0){continue;}
        if(s % F[i] == 0){
            sum += (s/F[i]);
        }else{
            sum += (s/F[i] + 1);
        }
    }
    return sum;
}


int main(){
    long n, k;
    cin >> n >> k;
    vector<long> A(n), F(n);
    for(int i=0;i<n;i++){
        scanf("%ld",&A[i]);
    }
    for(int i=0;i<n;i++){
        scanf("%ld",&F[i]);
    }
    sort(A.begin(), A.end());
    sort(F.rbegin(), F.rend());
    long r=0;
    for(int i=0;i<n;i++){
        r = max(r, A[i]*F[i]);
    }
    r++;
    long l=0;
    while(l < r){
        long m = (l+r)/2;
        if(f(A,F,m) > k){
            l=m+1;
        }else{
            r=m;
        }
    }
    cout << r << endl;
    return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <map>
#define int long long int

using namespace std;



main()
{
    //freopen("input.txt", "r", stdin);
    int N;
    cin>>N;
    vector<int> X(N);
    for(int i = 0; i < N; ++i)
    {
        cin>>X[i];
    }
    long long ans = 1;
    int mod = 1e9+7;
    int i = 0;
    int sum = 0;
    for(int step = 0; step < N; ++step)
    {
        while(i < N)
        {
            //out<<"A"<<i<<' '<<X[i]<<' '<<sum<<endl;
            if (2 * sum + 1 > X[i])
            {
                break;
            }
            sum++;
            i++;
        }

        //out<<i<<' '<<sum<<endl;
        ans *= (sum + (i != N));
        ans %= mod;
        sum -= 1;
    }
    cout<<ans%mod<<endl;
}


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
  int main()
  {
   int a=0;
   int b=0;
   int ans=0;
   cin>>a>>b;
   ans=a*b;
    if(a>=10||b>=10)
    {
      ans=-1;
    }
    cout<<ans<<endl;
    return 0;
  }

Measured memory_bytes: 256
n = int(input())
lst = list(map(int, input().split()))
dic = {0:0, 1:0, 2:0}
for i in range(n):
  if lst[i] % 4 == 0:
    dic[2] += 1
  elif lst[i] % 2 == 0:
    dic[1] += 1
  else:
    dic[0] += 1
pre = 2
for i in range(n):
  if pre == 2:
    if dic[0] >= 1:
      dic[0] -= 1
      pre = 0
    else:
      print('Yes')
      exit()
  else:
    if dic[2] >= 1:
      dic[2] -= 1
      pre = 2
    else:
      print('No')
      exit()
print('Yes')

Measured memory_bytes: 20348
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  int N = S.size();
  int count = 0;
  for (int i = 0; i < N; i++) {
    if (S.at(i) == 'o'){
      count++;
    }
  }

  if (15-N + count >= 8){
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}
      
  
    

Measured memory_bytes: 3620
#include <iostream>
#include <vector>
#include <algorithm>
#include <cassert>
#include <functional>
#include <numeric>
#include <limits>
#include <iomanip>
#include <queue>
#include <cmath>
#include <math.h>
#include <map>
#include <string>
using namespace std;
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; }
const long long INF = 1LL << 60;
using pll = pair<long long, long long>;
#define min(a, b) ((a) < (b) ? (a) : (b))


//struct moji {
//    int 
//    string name;
//};

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

    int N;
    cin >> N;
    map<string, int> moji;

    for (int i = 0; i < N; i++) {
        string tmp;
        cin >> tmp;
        // Keyが存在しなくてもkeyを作るし、あったらsecondに+1する。
        moji[tmp]++;
    }

    int maxCount = 0;
    for (auto e : moji ) {
        maxCount = max(maxCount, e.second);
    }

    for (auto e:moji) {
        if (e.second == maxCount) {
            cout << e.first << endl;
        }
    }
 	return 0;
}


Measured memory_bytes: 17664
N,M=map(int,input().split())
flag = True
res = ""
List = []
for i in range (M):
  List.append(list(map(int, input().split())))
resList = ["10"]*N
for i in range(M):
  if resList[List[i][0]-1] == "10":
    resList[List[i][0]-1] = str(List[i][1])
  else:
    if resList[List[i][0]-1] != str(List[i][1]):
      flag = False
if resList[0] == "0":
  flag = False
elif resList[0] == "10" and N > 1:
  resList[0]="1"
elif resList[0] == "10" and N == 1:
  resList[0]="0"
  flag = False
if flag:
  for i in range(N):
    if resList[i] == "10":
      res += "0"
    else:
      res += resList[i]
  print(int(res))
else:
  if resList[0] == "0" and N ==1:
    print(0)
  else:
    print(-1)

Measured memory_bytes: 9260
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
	
	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		
		int h = sc.nextInt();
		int w = sc.nextInt();
		
		loop: for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (sc.next().equals("snuke")) {
					out.println((char) ('A' + j) + "" + (i + 1));
					break loop;
				}
			}
		}
		
		out.println();
		out.flush();
	}
	
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;
	
	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}
	
	private byte readByte() {
		if (hasNextByte()) {
			return buffer[ptr++];
		} else {
			return -1;
		}
	}
	
	private boolean isPrintableChar(int c) {
		return '!' <= c && c <= '~';
	}
	
	private void skipUnprintable() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
			ptr++;
		}
	}
	
	public boolean hasNext() {
		skipUnprintable();
		return hasNextByte();
	}
	
	public String next() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		StringBuilder sb = new StringBuilder();
		byte b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}
	
	public int nextInt() {
		if (!hasNext()) {
			throw new NoSuchElementException();
		}
		int n = 0;
		boolean minus = false;
		byte b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}
	
}

Measured memory_bytes: 8272
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#define mod 998244353
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

vl divisor(ll n) {
	vl divlist;
	for (ll i = 1; i * i <= n; i++) {
		if (n % i == 0) {
			divlist.push_back(i);
			if (i * i != n)
				divlist.push_back(n / i);
		}
	}
	sort(divlist.begin(), divlist.end(), less<ll>());
	return divlist;
}

int main() {
	ll N;
	string X;
	cin >> N;
	cin >> X;
	ll ans = 0;
	vl divlist = divisor(N);
	map<ll, ll> sum_a, sum_a_strictly; // 周期がa以下の和, ちょうどaの和
	rep(i, divlist.size()) {
		// 小さい約数(周期a)から順に判定
		ll a = divlist[i]; // 周期
		ll b = N / a; // 周波数
		if (b % 2 == 0) // (n !n ... n !n)
			continue;

		// 上位a[bit] がX.substr(0, a)未満ならOK
		string Xsubstr = X.substr(0, a);
		reverse(Xsubstr.begin(), Xsubstr.end());
		ll pow2 = 1;
		rep(j, a) {
			sum_a[a] += ((Xsubstr[j] == '1') * pow2);
			sum_a[a] %= mod;
			pow2 *= 2;
			pow2 %= mod;
		}

		// 上位a[bit] がX.substr(0, a)と等しいときの判定
		Xsubstr = X.substr(0, a);
		string Xcomp;
		rep(f, b) {
			rep(j, a) {
				char Xtmp = Xsubstr[j];
				if (f % 2 == 1)
					Xtmp = ('1' - Xtmp + '0');
				Xcomp.push_back(Xtmp);
			}
		}
		sum_a[a] += (X >= Xcomp);

		// 周期が(ちょうどaの約数,a自身を除く)の場合を引く
		sum_a_strictly[a] = sum_a[a];
		vl divlist_a = divisor(a);
		rep(j, divlist_a.size()) {
			ll atmp = divlist_a[j]; // 周期
			ll btmp = N / atmp; // 周波数
			if (atmp == a)
				continue;
			if (btmp % 2 == 0) // (n !n ... n !n)
				continue;
			sum_a_strictly[a] -= sum_a_strictly[atmp];
			sum_a_strictly[a] += mod;
			sum_a_strictly[a] %= mod;
		}
		ans += sum_a_strictly[a] * 2 * a;
		ans %= mod;
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 1244
#include <bits/stdc++.h>
using namespace std;
 
int main() {
   int n;
   cin>>n;
   vector<int> ans(100000,0);
  
   for(int i=1;i<=sqrt(n);i++){
   	  for(int j=1;j<=sqrt(n);j++){
      	for(int k=1;k<=sqrt(n);k++){
            int f=i*i+j*j+k*k+i*j+j*k+k*i-1;
        	ans[f]++; 
            
        }
      }
   }
   for(int i=0;i<n;i++){
   	cout<<ans[i]<<endl;
   }
}

Measured memory_bytes: 3484
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn pattern_count(a: i32, b: i32, c: i32, x: i32) -> i32 {
    let mut found: i32 = 0;
    for i in 0..(a + 1) {
        for j in 0..(b + 1) {
            for k in 0..(c + 1) {
                if i * 500 + j * 100 + k * 50 == x {
                    found = found + 1;
                }
            }
        }
    }
    return found;
}

fn main() {
    let a: i32 = read();
    let b: i32 = read();
    let c: i32 = read();
    let x: i32 = read();
    let count: i32 = pattern_count(a, b, c, x);
    println!("{}", count);
}


Measured memory_bytes: 4476
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;
typedef long long ll;
#include <cstring>

int main() {
  int n;
  ll k, cnt, ans = -10000000000, sum;
  cin >> n >> k;
  vector<ll> p(n), c(n);
  for (int i = 0; i < n; i++) {
    cin >> p[i];
    p[i]--;
  }
  for (int j = 0; j < n; j++) {
    cin >> c[j];
  }
  for (int i = 0; i < n; i++) {
    int x = i;
    cnt = 0LL;
    sum = 0LL;
    do {
      cnt++;
      sum += c[p[x]];
      x = p[x];
    } while (x != i);
    if (sum > 0) {
      sum = max(0LL, k / cnt - 1LL) * sum;
      x = i;
      if (max(0LL, k / cnt - 1LL) > 0) {
        ans = max(ans, sum);
      }
      for (int j = 0; j < k - max(0LL, k / cnt - 1LL) * cnt; j++) {
        sum += c[p[x]];
        ans = max(ans, sum);
        x = p[x];
      }
    } else {
      sum = 0;
      x = i;
      for (int j = 0; j < min(k, cnt); j++) {
        sum += c[p[x]];
        ans = max(ans, sum);
        x = p[x];
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3656
#include <iostream>
#include <vector>
#include <cmath>
// #include <string>
// #include <set>
// #include <algorithm>

using namespace std;
typedef unsigned long long ull;


void p() {
    cout << "\n";
}
template<class Head, class... Body>
void p(Head head, Body... body) {
    cout << head << ",";
    p(body...);
}

int f(ull A) {
    int count = 0;
    while (A > 0) {
        A /= 10;
        count += 1;
    }
    return count;
}

int F(ull A, ull B) {
    return max(f(A), f(B));
}

int main(int argc, char const *argv[]) {
    ull N;
    cin >> N;

    int A, B;
    for (int i = sqrt(N); i > 0; i--) {
        if (N % i == 0) {
            A = i;
            B = N / A;
            // p(A, B, f(A), f(B));
            break;
        }
    }

    cout << F(A, B) << endl;

    return 0;
}


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

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	vector<int> a(26);
	rep(i,s.size()){
		a.at(s.at(i)-'a')++;
	}
	bool ans=true;
	rep(i,26){
		if(a.at(i)%2==1) ans=false;
	}
	if(ans) cout << "Yes" << endl;
	else cout << "No" << endl;
}

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

typedef long long ll;
ll n, m, s, i;
int main()
{
	cin >> n >>m;
	s = (n - m) * 100 + m * 1900;
	for (i = 0; i < m; i++) s *= 2;
	cout << s << endl;
    return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline

N = int(input())
M = [None] * N

for i in range(N):
    M[i] = [int(v) for v in input().split()]
    
S = [[0 for _ in range(3)] for _ in range(N)]
S[0][0] = M[0][0]
S[0][1] = M[0][1]
S[0][2] = M[0][2]

for i in range(N - 1):
    for j in range(3):
        for k in range(3):
            if j != k:
                S[i + 1][k] = max(S[i + 1][k], S[i][j] + M[i + 1][k])

print(max(S[-1]))

Measured memory_bytes: 45660
b,c;char m[2][8]={"NO","YES"};main(a){for(scanf("%d",&a);~scanf("%d%d%d",&a,&b,&c);printf("%s\n",m[!!(a*a+b*b-c*c)+!!(a*a-b*b+c*c)+!!(a*a-b*b-c*c)<3]));return 0;}

Measured memory_bytes: 576
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($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)*}
    };
}

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)*}
    };
}

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:tt ]) => {{
        let len = read_value!($next, usize);
        (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    }};

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        ab: [(i64, i64)]
    }
    let mut tot = 0;
    for &(_a, b) in &ab { tot -= b }
    let mut d: Vec<i64> = ab.into_iter().map(|(a, b)| a + b).collect();
    d.sort();
    d.reverse();
    for i in 0..d.len() {
        if i % 2 == 0 {
            tot += d[i];
        }
    }
    puts!("{}\n", tot);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 10492
import scala.io.StdIn.{readLine,readInt}

object Main {

  def maxHeapify(n:Int, a:Array[Int], i:Int):Unit = {
    var largest = i
    if(i*2 <= n) {
      if(a(i*2-1) > a(i-1)) largest = i*2
      if(i*2+1<=n && a(i*2) > a(largest-1)) largest = i*2+1
      if(largest != i) {
        val temp = a(largest-1)
        a(largest-1) = a(i-1)
        a(i-1) = temp
        maxHeapify(n,a,largest)
      }
    }
  }

  def main(args:Array[String]) = {
    val n = readInt
    val a = readLine.split(" ").map(_.toInt)
    for(i<-n/2 to 1 by -1) {
      maxHeapify(n,a,i)
    }
    println(" "+a.mkString(" "))
  }
}

Measured memory_bytes: 189016
use std::io::{self, BufRead, Write};

fn solve<R, W>(reader: R, mut writer: W)
where
    R: BufRead,
    W: Write,
{
    let mut lines = reader.lines();
    let _ = lines.next().unwrap().unwrap();
    let line2 = lines.next().unwrap().unwrap();
    let line3 = lines.next().unwrap().unwrap();
    let line4 = lines.next().unwrap().unwrap();

    let a: Vec<i32> = line2.trim().split_whitespace()
        .map(|p| p.parse().unwrap())
        .collect();
    let b: Vec<i32> = line3.trim().split_whitespace()
        .map(|p| p.parse().unwrap())
        .collect();
    let c: Vec<i32> = line4.trim().split_whitespace()
        .map(|p| p.parse().unwrap())
        .collect();

    let mut ans = 0;
    let mut before = -2;
    for i in a {
        ans += b[(i - 1) as usize];
        if i == before + 1 {
            ans += c[(before - 1) as usize];
        }
        before = i;
    }

    writeln!(&mut writer, "{}", ans).unwrap();
}

fn main() {
    let stdio = io::stdin();
    let input = stdio.lock();

    let output = io::stdout();

    solve(input, output);
}

#[cfg(test)]
mod tests {
    use super::*;

    const TESTS: &'static [(&'static [u8], &'static [u8])] = &[
        (
            br"3
3 1 2
2 5 4
3 6", br"14
",
        ),
        (
            br"4
2 3 4 1
13 5 8 24
45 9 15", br"74
",
        ),
        (
            br"2
1 2
50 50
50", br"150
",
        ),
    ];

    #[test]
    fn test_b() {
        for &(input, expected) in TESTS {
            let mut output = Vec::new();
            solve(input, &mut output);
            let expected_str = String::from_utf8(expected.to_vec()).unwrap();
            let output_str = String::from_utf8(output).unwrap();
            assert_eq!(expected_str, output_str);
        }
    }
}


Measured memory_bytes: 4352
#include <stdio.h>
#include <set>
typedef long long ll;

int main(void) {
  ll i, j, k, ans = 0, tmp = 0;
  char s[110], t[110];
  bool flg = false;
  scanf("%s%lld", s, &k);
  for(i = 1; s[i]; ++i) if(s[i] != s[i - 1]) flg = true;
  if(flg) {
    for(i = 0; s[i]; ++i) {
      t[i] = s[i];
      if(i && t[i] == t[i - 1]) t[i] = '?', ++ans;
    }
    if(s[0] == t[i - 1]) s[0] = '?', ++tmp;
    for(i = 1; s[i]; ++i) if(s[i] == s[i - 1]) s[i] = '?', ++tmp;
    printf("%lld", ans + tmp * (k - 1));
  } else printf("%lld", i * k / 2);
  return 0;
}

Measured memory_bytes: 128
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		boolean[] s = new boolean[123456 * 2 + 10];
		Arrays.fill(s, true);

		s[1] = false;

		// テ・ツ篠淌・ツ崢?」ツ?禿」ツ??
		for (int i = 2; i * i < 123456 * 2 + 10; i++) {
			for (int j = i; j < 123456 * 2 + 10; j++) {
				if (s[j]) {
					if (j == i) {
						continue;
					} else if (j % i == 0) {
						s[j] = false;
					}
				}

			}
		}

		// System.out.println(s[17]);
		// System.out.println(s[19]);
		// System.out.println(s[23]);

		while (true) {
			int n = sc.nextInt();

			if (n == 0) {
				break;
			}

			int cnt = 0;

			for (int i = n + 1; i <= 2 * n; i++) {
				if (s[i]) {
					cnt++;
				}
			}

			System.out.println(cnt);

		}

	}
}

Measured memory_bytes: 20612
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		new Main().solve();
	}
	
	void solve(){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int k=sc.nextInt();
		long[]a=new long[n];
		long[] sum_a=new long[n];
		long[] sum_b=new long[n];
		for(int i=0;i<n;i++){
			a[i]=sc.nextLong();
			if(i==0){
				sum_a[i]=a[i];
				sum_b[i]=Math.max(0, a[i]);
			}else{
				sum_a[i]=sum_a[i-1]+a[i];
				sum_b[i]=sum_b[i-1]+Math.max(0, a[i]);
			}
		}
		long ans=0;
		for(int i=0;i<=n-k;i++){
			long sum_black=0;
			long sum_white=0;
			if(i==0)sum_black+=sum_a[i+k-1];
			else sum_black+=sum_a[i+k-1]-sum_a[i-1];
			
			if(i>0){
				sum_black+=sum_b[i-1];
				sum_white+=sum_b[i-1];
			}
			sum_black+=sum_b[n-1]-sum_b[i+k-1];
			sum_white+=sum_b[n-1]-sum_b[i+k-1];
			
			ans=Math.max(sum_black, ans);
			ans=Math.max(sum_white, ans);
			
		}
		System.out.println(ans);
	}
	
}


Measured memory_bytes: 64016
import * as fs from 'fs';

//in
// 2 5
// 1 WA
// 1 AC
// 2 WA
// 2 AC
// 2 WA
//out
// 2 2
// 一回もACならなかった問いのWAは0

const inp: string[] = fs.readFileSync('/dev/stdin', 'utf8').trim().split('\n');
const n = parseInt(inp[0].split(' ')[0]);
const m = parseInt(inp[0].split(' ')[1]);
inp.shift(); // 不要な引数を除く

const acList: any = {};
const waList: any = {};
let acTotal: number = 0;
let waTotal: number = 0;
for (let i: number = 0; i < m; i++) {
    const q: number = parseInt(inp[i].split(' ')[0]);
    if (q > n) continue;

    const status: string = inp[i].split(' ')[1];
    if (status === 'AC') {
        if (!acList[q]) {
            acList[q] = 1;
            acTotal++;

            // waCnt
            if (waList[q]) waTotal += waList[q];

        }
    } else if (status === 'WA') {
        if (acList[q]) continue;


        if (!waList[q]) {
            waList[q] = 1
        } else {
            waList[q]++
        }
    }
}

//


console.log(`${acTotal} ${waTotal}`);


Measured memory_bytes: 30876
#include<stdio.h>
#define X 2000
int solve(int,int);
int A[X],m[X];
int n;
int main(){
  int i,q;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }

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

    if(solve(0,m[i]) == 1)
      printf("yes\n");

    if(solve(0,m[i]) == 0)
      printf("no\n");
  }
  return 0;
}

int solve(int i,int m){
  int res;
  if(m == 0) return 1;
  if(i >= n) return 0;
  res = solve(i+1,m) || solve(i+1,m - A[i]);
}

Measured memory_bytes: 584
#include "bits/stdc++.h"
using namespace std;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 1e9 + 7, INF = 1e18;


lint D;
lint decrease[26];
lint satis[365][26];
lint prv[26];

lint downscore(lint passed) {
	lint sum = 0;
	REP(i, 26) {
		sum += decrease[i] * (passed - prv[i]);
	}
	return -sum;
}

int main() {
	cin >> D;
	REP(i, 26) {
		cin >> decrease[i];
	}
	REP(i, D) {
		REP(j, 26) {
			cin >> satis[i][j];
		}
	}

	REP(i, D) {
		lint maxv = -INF, max_idx = 0;
		REP(s, 26) {
			lint inst = 0;
			inst += satis[i][s];
			inst += downscore(i + 1);
			chmax(inst, 0ll);
			if (maxv < inst) {
				maxv = inst;
				max_idx = s;
			}
		}
		prv[max_idx] = i + 1;
		cout << max_idx + 1;
		if (i != D - 1) cout << endl;
	}
	return 0;
}


Measured memory_bytes: 3692
import math

N=int(input())
X=[0 for _ in range(N)]
Y=[0 for _ in range(N)]
for i in range(N):
  X[i],Y[i] = map(int, input().split())
s=0
for i in range(N):
  for j in range(N):
    if not i==j:
      s+=math.sqrt((X[i]-X[j])**2 + (Y[i]-Y[j])**2)*math.factorial(N-1)
print(s/math.factorial(N))

Measured memory_bytes: 9216