akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
typedef long long lint;
using namespace std;

const int l = 17;

vector<bitset<l>> any2any(bitset<l> start, bitset<l> goal, int dim) {
    if (dim == 1) {
        if (start == 0) {
            return {0, 1};
        } else {
            return {1, 0};
        }
    }
    if (start != bitset<l>(0)) {
        auto res = any2any(0, goal ^ start, dim);
        for (auto &e : res) {
            e ^= start;
        }
        return res;
    }
    if (goal[dim - 1] == 0) {
        int replace = -1;
        for (int i = 0; i < l; i++) {
            if (goal[i] == 1) {
                replace = i;
                break;
            }
        }
        goal[dim - 1] = 1, goal[replace] = 0;
        auto res = any2any(0, goal, dim);
        for (auto &e : res) {
            int a = e[dim - 1], b = e[replace];
            e[dim - 1] = b, e[replace] = a;
        }
        return res;
    }
    goal[dim - 1] = 0;
    auto y = goal ^ bitset<l>(1);
    auto half_0 = any2any(0, y, dim - 1);
    auto half_1 = any2any(y, goal, dim - 1);
    for (auto e : half_1) {
        e[dim - 1] = 1;
        half_0.push_back(e);
    }
    return half_0;
}

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    bitset<17> x(a), y(b);
    if (x.count() % 2 == y.count() % 2) {
        cout << "NO" << endl;
    } else {
        cout << "YES" << endl;
        auto res = any2any(x, y, n);
        for (auto e : res) {
            cout << e.to_ulong() << endl;
        }
    }
    return 0;
}

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

const int MAX = 2e5 + 1;

int n; ll h, nh;

void solve() {
	ll ans = 0;
	scanf("%d %lld", &n, &h);
	for (int i = 1; i < n; i++) {
		scanf("%lld", &nh);
		if (h > nh) ans += (h - nh);
		else h = nh;
	}
	printf("%lld", ans);
}

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

Measured memory_bytes: 3808
/*
これを入れて実行
g++ code.cpp
./a.out
 */
 
#include <iostream>
#include <stdio.h>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <math.h>
#include <tuple>
#include <iomanip>
#include <bitset>
#include <functional>
#include <cassert>

#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
 
using namespace std;
typedef long long ll;
typedef long double ld;
 
int dy4[4] = {-1, 0, +1, 0};
int dx4[4] = {0, +1, 0, -1};
int dy8[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
int dx8[8] = {0, 1, 1, 1, 0, -1, -1, -1};
 
const long long INF = 1LL << 62;
//const ll MOD = 1e9 + 7;
 
bool greaterSecond(const pair<int, int>& f, const pair<int, int>& s){
    return f.second > s.second;
}
 
ll gcd(ll a, ll b){
	if (b == 0)return a;
	return gcd(b, a % b);
}
 
ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll conbinationMemo[100][100];

void cmemoInit(){
    rep(i, 100){
        rep(j, 100){
            conbinationMemo[i][j] = -1;
        }
    }
}
 
ll nCr(ll n, ll r){
    if(conbinationMemo[n][r] != -1) return conbinationMemo[n][r];
    if(r == 0 || r == n){
        return 1;
    } else if(r == 1){
        return n;
    }
    return conbinationMemo[n][r] = (nCr(n - 1, r) + nCr(n - 1, r - 1));
}
 
ll nPr(ll n, ll r){
    r = n - r;
    ll ret = 1;
    for (ll i = n; i >= r + 1; i--) ret *= i;
    return ret;
}
//-----------------------ここから-----------
int main(void){
    string s;
    cin >> s;

    string ans = s;
    rep(i, s.size()){
        if(s[i] == '?'){
            ans[i] = 'D';
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 3832
#include <bits/stdc++.h>
using namespace std;
int n,s,dp[3300],mol=998244353,ans;
int main()
{
    cin>>n>>s;
    for(int i=1;i<=n;i++)
    {
        int x; cin>>x;
        dp[0]=i;
        for(int j=s;j>=x;j--) dp[j]=(dp[j]+dp[j-x])%mol;
        ans=(ans+dp[s])%mol;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <random>
#include <chrono>
#include <queue>
#include <math.h>
#include <string>
#include <sstream>
#include <stack>
#define inf 1e9+7
#define pb push_back
#define make make_pair
 
using namespace std;
 
#define ll long long
#define rep(i,n) for(ll i=0;i<n;i++)
#define PI 3.14159265359
long long gcd(long long a,long long b){ return b==0?a:gcd(b,a%b);}
long long lcm(long long a,long long b){ return a/gcd(a,b)*b;}


int main(){
    ll a[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    ll k;
    cin >> k;
    cout << a[k-1] << endl;
}



Measured memory_bytes: 256
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    n, m = map(int, input().split())
    L, R = 1, n
    for _ in range(m):
        l, m = map(int, input().split())
        if l > L: L = l
        if m < R: R = m
    print(max(0, R-L+1))
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 9132
using System;

namespace a
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();
            
            var t = Console.ReadLine();
            var t2 = t.Substring(0, s.Length);

            if(s.Equals(t2)){
                Console.WriteLine("Yes");
            }else{
                Console.WriteLine("No");
            }
        }
    }
}


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

public class Main {
    public static void main(String[] args) throws Exception {

        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        
        String[] input = br.readLine().split(" ");
        int x = Integer.parseInt(input[0]);
        int a = Integer.parseInt(input[1]);
        
        out.println(x < a ? 0 : 10);
        out.close();
        
    }
}

Measured memory_bytes: 32784
<?php
fscanf(STDIN, "%d", $N);
for ($n = 0; $n < 3; $n++) {
    fscanf(STDIN, "%s", $ABC);
    $arr = str_split($ABC);
    for ($i = 0; $i < $N; $i++) {
        if (!isset($sum[$i][$arr[$i]])) {
            $sum[$i][$arr[$i]] = 1;
        } else {
            $sum[$i][$arr[$i]]++;
        }
    }
}
$ans = 0;
for ($i = 0; $i < $N; $i++) {
    $ans += 3 - max($sum[$i]);
}
echo $ans;


Measured memory_bytes: 4984
#include <cstdio>
#include <climits>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <string>
#include <cstdio>
#include <climits>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <utility>
#include <queue>
#include <cstring>
#include <set>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
long long MOD = 1000000007;
long long INF = 1000000000000000; //10^15
typedef long long ll;
typedef unsigned long long ull;

int main(void) {
  int n;
  string s[100];
  int t[100];
  string x;
  cin >> n;
  rep(i, n) cin >> s[i] >> t[i];
  cin >> x;

  bool flag = false;
  int ans = 0;
  
  rep(i, n) {
    if (i > 0 && s[i - 1] == x) flag = true;
    if (flag) ans += t[i];
  }

  cout << ans << endl;

  return 0;
}


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

using namespace std;

int main(void){

	string data("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz");
	string conv;
	char inp,inp2;
	string ans;
	int n,m;

	while(1){
		ans=("");
		conv=("..............................................................");
		cin>>n;
		if(n==0) break;
		for(int i=0;i<n;i++){
			cin>>inp>>inp2;
			conv[data.find(inp)]=inp2;
		}

		cin>>m;

		for(int i=0;i<m;i++){
			cin>>inp;
			if(conv[data.find(inp)]!='.') ans+=conv[data.find(inp)];
			else ans+=inp;
		}

		cout<<ans<<endl;
	}

    return 0;
}

Measured memory_bytes: 1340
#include <cstdio>
#include <algorithm>

using namespace std;

int main() {
    int a, b, c, d, e, k;
    scanf("%d %d %d %d %d %d", &a, &b, &c, &d, &e, &k);
    printf("%s\n", k >= e-a ? "Yay!" : ":(");
    return 0;
}

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

int main() {
  double r, l, s;
  cin >> r;
  l = 2.000000 * r * M_PI;
  s = r * r * M_PI;
  cout << fixed << setprecision(6);
  cout << s << ' ' << l << "\n";
}


Measured memory_bytes: 3280
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#define rep(i, n) for(int i = 0; i < n; i++)
#define REP(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(),v.end()
#define INF 1e9
typedef long long ll;
using namespace std;

int N[201];
int main() {
    int a; cin >> a;
    rep(i,a) cin >> N[i];
    int ans = 0;
    int count = 0;
    while(count==0){
        rep(i,a){
            if(N[i]%2==0){
                N[i] /= 2;
            }else{
                count += 1;
                break;
            }
        }
        if(count == 0){
            ans += 1;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
A, B, K = map(int, input().split(' '))
A_set = set()
B_set = set()
for number in range(1, A+1):
    if A%number == 0:
        A_set.add(number)

for number in range(1, B+1):
    if B%number == 0:
        B_set.add(number)

A_Bset = A_set & B_set
A_Blist = list(A_Bset)
A_Blist.sort(reverse=True)
print(A_Blist[K-1])

Measured memory_bytes: 3064
N = int(input())
T = list(map(int,input().split()))
M = int(input())
P,X = [],[]
for i in range(M):
    p,x = map(int,input().split())
    P.append(p-1)
    X.append(x)
sumT = sum(T)
for i in range(M):
    print(sumT + X[i] - T[P[i]])

Measured memory_bytes: 3064
import math
import collections

N = int(input())
a = math.factorial(N)
check = []
ans = 1
i = 2

while a != 1:
    if a % i == 0:
        a //= i
        check.append(i)
    else:
        i += 1
        
check = collections.Counter(check).values()
for i in check:
    ans *= (i+1)
    ans %= 10**9+7
print(ans)

Measured memory_bytes: 3316
#include<stdio.h>
#define N 1000000

/*????????????????????£?¨?*/
void insertionSort(int [],int,int);
void shellSort(int [],int);

/*??°????????????*/
int cnt =0;


/*main??¢??°*/
int main(){

  int A[N],i,num;
  scanf("%d",&num);

  for(i=0;i<num;i++) scanf("%d",&A[i]);
  shellSort(A,num);
  printf("%d\n",cnt);
  for(i=0;i<num;i++) printf("%d\n",A[i]);

  return 0;
}

/*?????§????????????*/
void shellSort(int A[],int n){
  int i=0,m=0;
  int G[n];

  G[0]=0;
  for(i=0;i<n;i++){
      G[i+1] = 3*G[i]+1;
      m++;
      if(G[i+1]>n)break;
  }
  while(1){
    if(G[m]>N)m--;
    else m--; break;
     }

  if(m==0)m=1;

  printf("%d\n",m);
  for(i=m;i>1;i--)printf("%d ",G[i]);
  printf("%d\n",G[1]);
  for(i=m;i>=0;i--){
    insertionSort(A,n,G[i]);
  }
}

/*sort*/
void insertionSort(int A[],int n, int g){

  int i,j,v;
  for(i=g;i<=n-1;i++){
    v = A[i];
    j=i-g;
    while(j>=0 && A[j]>v){

      A[j+g] = A[j];
      j=j-g;
      cnt++;
    }
    A[j+g] = v;
  }
}

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

int main() {
  ll x;cin >> x;
  if( x >= 30 ){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 3524
#include <iostream>
 
using namespace std;
 
int main(){
  int n1,n2,n3;

  cin >> n1 >> n2 >> n3;

 if(n1 < n2 && n2 < n3)
    cout << "Yes" << endl;
 else
    cout << "No" << endl;

  return 0;
   
}

Measured memory_bytes: 3100
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <cassert>
using namespace std;

int N, Q;
vector<vector<int>> G;
vector<int> ans;

void dfs(int s, int p){
    for(int t : G[s]){
        if(t == p) continue;
        ans[t] += ans[s];
        dfs(t, s);
    }
}

int main(){
    cin >> N >> Q;
    G.resize(N);
    ans.resize(N);

    for(int i=0; i<N-1; i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    for(int i=0; i<Q; i++){
        int p, x;
        cin >> p >> x;
        p--;
        ans[p] += x;
    }

    dfs(0, -1);

    for(int i=0; i<N; i++)
        cout << ans[i] << " ";
    cout << endl;
}

Measured memory_bytes: 23552
using System;
using System.Collections.Generic;
using static System.Console;

class Program
{
    public static void Main()
    {
	string s = ReadLine();
	string t = ReadLine();

	int N = 'z'-'a'+1;
	
	List<int>[] d0 = new List<int>[N];
	for (int i = 0; i < N; i++)
	{
	    d0[i] = new List<int>();
	}

	for (int i = 0; i < s.Length; i++)
	{
	    char c = s[i];
	    d0[c-'a'].Add(i);
	}

	int [][] d = new int[N][];
	for (int i = 0; i < N; i++)
	{
	    d[i] = d0[i].ToArray();
	}

	int [,] m = new int[s.Length, N];

	for(int i = 0; i < s.Length; i++)
	{
	    for (int j = 0; j < N; j++)
	    {
		if (d[j].Length > 0)
		{
		    int x = Array.BinarySearch(d[j], i);
		    if (x < 0)
		    {
			x = ~x;
			if (x >= d[j].Length){ x = 0; }
		    }
		    int pos = d[j][x];
		    if (pos >= i){ pos -= i; }
		    else         { pos += s.Length - i; }
		    m[i, j] = pos + 1;
		}
	    }
	}

	long ans = 0;
	int ct = 0;
	for(int i = 0; i < t.Length; i++)
	{
	    char c = t[i];
	    int k = m[ct, c-'a'];
	    if (k == 0){ WriteLine(-1); return; }
	    ans += k;
	    ct = (ct + k) % s.Length;
	}

	WriteLine(ans);
    }
}


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

const ll infll=9223372036854775806;
const int inf=2147483646;

int main()
{
	//freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	int i,ans=0,s=0;
	string a;
	cin>>a;
	for (i=0;i<a.size();i++){
		if (a[i]=='A'||a[i]=='C'||a[i]=='G'||a[i]=='T'){
			s++;
		}
		else {
			ans=max(ans,s);
			s=0;
		}
	}
	cout<<max(ans,s);
	return 0;
}

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

using namespace std;
typedef long long ll;
ll t , k,n,x , y , a, b,c , d ,sum;
string s;
const int N=200001;
char ch;
int occ[N],arr[N];
int ans[31];
int main()
{
    cin >> n;
    for(int i = 0 ; i < n ; i++)
    {
        cin >> arr[i];
        x=0;
        y=arr[i];
        while(y>0)
        {
            if(y%2==1)
            {
                ans[x]++;
            }
            x++;
            y/=2;
        }
    }
    for(int i = 0 ; i < n ; i++)
    {
        //cout << arr[i] << "\n";
        x=0;
        y=arr[i];
        sum=0;
        while(y>0)
        {
            //cout << x << " " << ans[x] << "\n";
            if(y%2==1)
            {
                ans[x]--;
            }
            x++;
            y/=2;
        }
        y=1;
        for(int j=0 ;j<31 ;j++)
        {
            if(ans[j]%2==1)
            {
                sum+=y;
            }
            y*=2;
            //cout << j <<" " <<  ans[j] << " " << sum << "\n";
        }
        y=arr[i];
        x=0;
        while(y>0)
        {
            if(y%2==1)
            {
                ans[x]++;
            }
            x++;
            y/=2;
        }
        cout << sum << " ";
    }
    return 0;
}


Measured memory_bytes: 4396
#include<iostream>
using namespace std;
long long a,b,mn1,mx1,mn2,mx2;
int main()
{
    cin>>a>>b;
    if(a%2==1)
    {
        mn1=a*25/2+1;
        mx1=(a+1)*25/2-1;
    }
    else
    {
        mn1=a*25/2;
        mx1=(a+1)*25/2;
    }
    mn2=b*10;
    mx2=(b+1)*10-1;
    if(mx1<mn2||mx2<mn1) cout<<-1;
    else cout<<max(mn1,mn2);
    //system("pause");
}


Measured memory_bytes: 256
// 2011/08/16 Tazoe

#include <iostream>
#include <string>
using namespace std;

int main()
{
	for(int i=0; i<9; i++){
		string cls;
		int am, pm;
		cin >> cls >> am >> pm;
		cout << cls << ' ' << am+pm << ' ' << 200*am+300*pm << endl;
	}

	return 0;
}

Measured memory_bytes: 0
function main(input) {
  input = input.trim().split("\n");
  const [n, d] = input[0].split(" ").map(n => Number(n));
  const xs = [];
  for (let i = 0; i < n; i++) {
    xs.push(input[i+1].split(" ").map(n => Number(n)));
  }
  let result = 0;
  for (let i = 0; i < n; i++) {
    for (let j = i+1; j < n; j++) {
      const x1 = xs[i];
      const x2 = xs[j];
      let sum = 0;
      for (let k = 0; k < d; k++) {
        sum += Math.abs(x1[k] - x2[k])**2;
      }
      const distance = Math.sqrt(sum);
      if (Number.isInteger(distance)) result++;
    }
  }
  console.log(result);
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7500
#include<stdio.h>
#include<string.h>

int main(){

    int i;
    char a[21];

    while ( (fscanf(stdin, "%s", a)) != EOF){
        for (i=strlen(a)-1; i >= 0; i--){
            printf("%c", a[i]);
        }
        printf("\n");
    }

    return 0;
}

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

int N, M, P, X[100];

int main() {
  while (1) {
    scanf("%d%d%d", &N, &M, &P);
    if (N == 0) break;
    M--;
    int sum = 0;
    for (int i = 0; i < N; i++) scanf("%d", &X[i]), sum += X[i];
    if (X[M] == 0) printf("0\n");
    else printf("%d\n", (100 - P) * sum / X[M]);
  }
}



Measured memory_bytes: 2564
#C問題
#UnionFind(normal)
class UnionFind():
    # 作りたい要素数nで初期化
    # 使用するインスタンス変数の初期化
    def __init__(self, n):
        self.n = n
        # root[x]<0ならそのノードが根かつその値が木の要素数
        # rootノードでその木の要素数を記録する
        self.root = [-1]*(n+1)
        # 木をくっつける時にアンバランスにならないように調整する
        self.rnk = [0]*(n+1)

    # ノードxのrootノードを見つける
    def Find_Root(self, x):
        if(self.root[x] < 0):
            return x
        else:
            # ここで代入しておくことで、後の繰り返しを避ける
            self.root[x] = self.Find_Root(self.root[x])
            return self.root[x]
    # 木の併合、入力は併合したい各ノード
    def Unite(self, x, y):
        # 入力ノードのrootノードを見つける
        x = self.Find_Root(x)
        y = self.Find_Root(y)
        # すでに同じ木に属していた場合
        if(x == y):
            return 
        # 違う木に属していた場合rnkを見てくっつける方を決める
        elif(self.rnk[x] > self.rnk[y]):
            self.root[x] += self.root[y]
            self.root[y] = x

        else:
            self.root[y] += self.root[x]
            self.root[x] = y
            # rnkが同じ（深さに差がない場合）は1増やす
            if(self.rnk[x] == self.rnk[y]):
                self.rnk[y] += 1
    # xとyが同じグループに属するか判断
    def isSameGroup(self, x, y):
        return self.Find_Root(x) == self.Find_Root(y)

    # ノードxが属する木のサイズを返す
    def Count(self, x):
        return -self.root[self.Find_Root(x)]

    
"""
実装例
ABC126E 1or2

#E問題
#UnionFind(normal) 
UFコードは省略
    
if __name__ == "__main__":
  
    N,M = map(int,input().split())
    uf = UnionFind(N+1)
    for i in range(M):
        X,Y,Z = map(int,input().split())
        if not uf.isSameGroup(X,Y):
            uf.Unite(X,Y)
    ans=0
    for j in uf.root[1:N+1]:
        if j < 0:
            ans+=1
    print(ans)
"""


N,M = map(int,input().split())
edges = []

for i in range(N):
    Linput = list(map(int,input().split()))
    k = Linput[0]
    for j in range(k):
        L = Linput[j+1]+N-1
        edges.append([i,L])
        
uf = UnionFind(N+M)
for edge in edges:
    x,y = edge[0],edge[1]
    if not uf.isSameGroup(x,y):
        uf.Unite(x,y)
        
flag = 0
for i in range(N-1):
    I = i+1
    if not uf.isSameGroup(0,I):
        flag = 1
        break
        
print("YES" if flag == 0 else "NO")

Measured memory_bytes: 23216
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Hassan El Desouky
 */

#include <iostream>
#include <fstream>

#include "bits/stdc++.h"

using namespace std;
#define el '\n'
#define F first
#define S second
#define FOR(i,a,b) for(int i = a; i <= b; ++i)
#define FORD(i,a,b) for(int i = a; i >= b; --i)
#define RI(i,n) FOR(i,1,n)
#define REP(i,n) FOR(i,0,(n)-1)
#define SQR(x) (x)*(x)
typedef long long ll;
typedef pair<int, int>	pii;
typedef pair<ll, ll>	pll;
typedef long double ld;
typedef vector<int>		vi;
typedef vector<pii>		vpii;
const double EPS = 1e-9;
const int N = 1e3+2, M = 2e5+5, OO = 0x3f3f3f3f;
//int dx[] = {1,-1,0,0} , dy[] = {0,0,1,-1}; // 4 Direction
//int dx[] = {1,-1,0,0,1,1,-1,-1}, dy[] = {0,0,1,-1,1,-1,1,-1}; // 8 Directio
/* int dx[] = {1,-1,1,-1,2,2,-2,-2} , dy[] = {2,2,-2,-2,1,-1,1,-1}; */ // Knight Direction
/* int dx[] = {2,-2,1,1,-1,-1} , dy[] = {0,0,1,-1,1,-1}; */ // Hexagonal Direction


class AIrohaAndHaikuABCEdition {
public:
	void solve(std::istream& in, std::ostream& out) {
	    vector<int> v(3);
	    for (int& x: v) in >> x;
	    sort(v.begin(), v.end());
	    int arr[] = {5, 5, 7};
	    bool f = 0;
	    for (int i = 0; i < 3; ++i) {
	        if ((v[i] % arr[i]) == 0) continue;
	        else {
	            f = 1;
                break;
	        }
	    }
	    if (f) out << "NO\n";
	    else out << "YES\n";
	}
};


int main() {
	AIrohaAndHaikuABCEdition solver;
    ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr);
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
N = int(input())
X = list(map(int,input().split()))

a = min(X)
b = max(X)

ans = []

for i in range(a,b+1):
  S = 0
  for j in range(N):
    S += (X[j]-i)**2

  ans.append(S)
  
print(min(ans))

Measured memory_bytes: 3064
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <numeric>
#include <iostream>
#include <random>
#include <map>
#include <unordered_map>
#include <queue>

#pragma GCC optimize("Ofast")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define rep2(i, n) for(int i = 2; i < (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printin(a) printf(a ? "possible\n" : "inposible\n")
#define printdb(a) printf("%.50lf\n", a)//少数出力
#define printdbd(a) printf("%.16lf\n", a)//少数出力(桁少なめ)
#define prints(s) printf("%s\n", s.c_str())//string出力
#define all(x) (x).begin(), (x).end()
#define allsum(a, b, c) ((a + b) * c / 2)//等差数列の和、初項,末項,項数
#define pb push_back
#define priq priority_queue
#define rpriq priq<int, vector<int>, greater<int>>
#define deg_to_rad(deg) (((deg)/360.0)*2.0*PI)
#define rad_to_deg(rad) (((rad)/2.0/PI)*360.0)
#define Please return
#define AC 0
#define ushi int
#define tapu main
#define nichia (
#define kunn void
#define wara )

using ll = long long;

const int INF = 1073741823;
const int MINF = -1073741823;
const ll LINF = ll(4661686018427387903);
const ll MOD = 1000000007;
const double PI = acos(-1);

using namespace std;

void scans(string& str) {
	char c;
	scanf("%c", &c);
	if (c == '\n')scanf("%c", &c);//最初の改行対策
	while (c != '\n' && c != -1) {
		str += c;
		scanf("%c", &c);
	}
}

void scanc(char& str) {
	char c;
	scanf("%c", &c);
	if (c == -1)return;
	while (c == '\n') {
		scanf("%c", &c);
	}
	str = c;
}

double acot(double x) {
	return PI / 2 - atan(x);
}

/*-----------------------------------------ここからコード-----------------------------------------*/

int main(){

	int a;
	scanf("%d", &a);
	printf("%s\n", a < 1000 ? "ABC" : "ABD");

	Please AC;
}


Measured memory_bytes: 256
import java.util.Scanner;


public class Main {
	static Scanner sc = new Scanner(System.in);
	static int L;
	static int M[] = new int[12];
	static int N[] = new int[12];
	
	//main
	public static void main(String[] args) {
		while(read()){
			solve();
		}
	}
	
	//read
	static boolean read(){
		if(sc.hasNextInt()){
			if((L = sc.nextInt()) == 0) return false;
		}
		
		for(int i=0; i<12; i++){
			M[i] = sc.nextInt();
			N[i] = sc.nextInt();
		}
		return true;
	}
	
	//solve
	static void solve(){
		
		for(int i=0; i<12; i++){
			L -= M[i] - N[i];
			if(L <= 0){
				System.out.println(i+1);
				return;
			}
		}
		
		System.out.println("NA");
	}
}

Measured memory_bytes: 12000
n = int(input())
c = sorted(list(map(int, input().split())))
mod = 10 ** 9 + 7
ans = 0
for i,v in enumerate(c):
  ans = (ans + (v * pow(2,n+i,mod) * ((n-i-1) * pow(2,max(0,n-i-2),mod) + pow(2,n-i-1,mod))) % mod) % mod
print(ans)

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 n;
    cin >> n;
    vector<vector<int32>> adj(n);
    REP(i,n-1){
        int32 a,b;
        cin >> a >> b;
        a--;b--;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    vector<int32> c(n);
    REP(i,n)cin >> c[i];
    sort(ALL(c),greater<int32>());
    vector<int32> res(n,-1);
    int64 sum = 0;
    res[0] = c[0];
    queue<int32> que;
    que.push(0);
    int32 idx = 1;
    while(!que.empty()){
        int32 x = que.front();
        que.pop();
        for(int32 y : adj[x]){
            if(res[y] > 0)continue;
            res[y] = c[idx];
            idx++;
            que.push(y);
            sum += res[y];
        }
    }
    cout << sum << endl;
    REP(i,n){
        if(i != 0)cout << " ";
        cout << res[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 1152
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <bitset>
#include <map>
#include <tuple>
#include <unordered_map>
#include <list>
#include <numeric>
#include <utility>
#include <iterator>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <ctime>
#include <cassert>

#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007

#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define pb push_back
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<long long>vll;
typedef pair<int,int> pi;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
int ddx[8]={-1,-1,0,1,1,1,0,-1};
int ddy[8]={0,1,1,1,0,-1,-1,-1};
bool debug=false;

/*---------------------------------------------------*/

int main(){
  int n;
  cin >> n;
  vector<int> a(n*3);
  for(int i = 0; i < n * 3; i++){
    cin >> a[i];
  }

  priority_queue<int, vector<int>, greater<int> > pq;
  vector<ll> front(n + 1, 0);
  ll sum = 0;
  for(int i = 0; i < n; i++){
    sum += a[i];
    pq.push(a[i]);
  }
  front[0] = sum;
  int index = 1;
  for(int i = n; i < n * 2; i++){
    pq.push(a[i]);
    int p = pq.top();pq.pop();
    sum = sum + a[i] - p;
    front[index++] = sum;
  }

  priority_queue<int> pq2;
  vector<ll> back(n + 1, 0);
  sum = 0;
  for(int i = n * 3 - 1; i >=  n * 2; i--){
    sum += a[i];
    pq2.push(a[i]);
  }
  back[0] = sum;
  index = 1;
  for(int i = n * 2 - 1; i >= n; i--){
    pq2.push(a[i]);
    int p = pq2.top();pq2.pop();
    sum = sum + a[i] - p;
    // for(auto x : back)cout << x << " ";cout << endl;
    back[index++] = sum;
  }

  ll ans = LLONG_MIN;
  for(int i = 0; i < n + 1; i++){
    ans = max(ans, front[i] - back[n - i]);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4088
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

const int MAX_N = 8;

int dp[1 << (MAX_N - 1)][MAX_N + 1];
int d[MAX_N + 1][MAX_N + 1];

int N, M;

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

    cin >> N >> M;

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

    for (int i = 2; i <= N; i++) {
        dp[0][i] = d[1][i];
    }
    dp[0][1] = 1;

    for (int i = 1; i < (1 << (N - 1)); i++) {
        for (int j = 2; j <= N; j++) {
            int smv = i & (~(1 << (j - 2)));
            dp[i][j] += dp[smv][1] * d[1][j];
            for (int k = 0; k < N - 1; k++) {
                if (((i >> k) & 1) && (i & (1 << (j - 2)))) {
                    dp[i][j] += dp[smv][k + 2] * d[k + 2][j];
                }
            }
        }
    }

    ll ans = 0;

    for (int j = 2; j <= N; j++) {
        ans += dp[(1 << (N - 1)) - 1][j];
    }

    cout << ans << "\n";

    return 0;
}


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

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

    map<int, int> counter;
    int temp;
    for (int i=0;i<n;i++){
        cin >> temp;
        ++counter[temp];
    }

    int delete_target_number = 0;
    for (auto &item : counter){
        if (item.first == item.second){
            continue;
        } else {
            if (item.first < item.second){
                delete_target_number += item.second - item.first;
            } else {
                delete_target_number += item.second;
            }
        }

    }
    cout << delete_target_number << endl;
    return 0;
}

Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define pb push_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<PP,vector<PP>,greater<PP>> SPQ;
using vi=vector<ll>;
using vvi=vector<vector<ll>>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
bool chmin(auto &a,auto b){if(a>b){a=b;return true;}return false;}
bool chmax(auto &a,auto b){if(a<b){a=b;return true;}return false;}
void outvi(vi v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<endl;}
void outvvi(vvi v){rep(i,v.size()){rep(j,v[i].size()){if(j)cout<<' ';cout<<v[i][j];}cout<<endl;}}

int main(){
  ll n;cin>>n;
  string a,b;cin>>a>>b;
  rep(i,n)cout<<a[i]<<b[i];
  cout<<endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
        public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int n = sc.nextInt();
            int m = sc.nextInt();
            int total = 0;
            int [] votes = new int[n];
            for(int i = 0; i<n; i++){
                votes[i] = sc.nextInt();
                total += votes[i];
            }
            Arrays.sort(votes);
            double threshold = (double)1/(4*m)*(double)total;
            for(int i = votes.length-1; i>=n-m; i--){
                if(votes[i]<threshold) {
                    System.out.println("No");
                    return;
                }
            }
            System.out.println("Yes");
        }
    }


Measured memory_bytes: 21716
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
#include <map>
#include <stack>
//#include <bits/stdc++.h>
using namespace std;
typedef long long int lli;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)
int main(void)
{
    int A, B, C;
    int K;
    cin >> A >> B >> C >> K;
    for (int i = 0; i < K; i++)
    {
        if (A >= B)
        {
            B *= 2;
        }
        else if (B >= C)
        {
            C *= 2;
        }
    }
    if (A < B && B < C)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define IOS                      \
    ios::sync_with_stdio(false); \
    cin.tie(0)

// *start on @date: 2020-02-22 20:52

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

int s[105];

int main()
{
    IOS;
    int n;
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> s[i];
    ll maxn = 99999999;
    for (int i = 1; i < 101; i++)
    {
        ll now = 0;
        for (int j = 0; j < n; j++)
            now += (s[j] - i) * (s[j] - i);
        if (now < maxn)
            maxn = now;
    }
    cout << maxn;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long int ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }
const int MOD=1000000007;

bool isPowerOfTwo (ll x)  
{  
    return x && (!(x&(x-1)));  
}
bool isPrime(int n) 
{ 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
    if (n%2 == 0 || n%3 == 0) return false; 
  
    for (int i=5; i*i<=n; i=i+6) 
        if (n%i == 0 || n%(i+2) == 0) 
           return false; 
  
    return true; 
}
int highestPowerof2(unsigned int n) 
{ 
    // Invalid input 
    if (n < 1) 
        return 0; 
  
    int res = 1;
    for (int i=0; i<8*sizeof(unsigned int); i++) 
    { 
        int curr = 1 << i; 
        if (curr > n) 
           break; 
  
        res = curr; 
    } 
  
    return res; 
} 
long long binpow(long long a, long long b) {
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a;
        a = a * a;
        b >>= 1;
    }
    return res;
}       
////////////////////////////////////////////////////////////////////

int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);  
  cout.tie(NULL);
  ll t=1;
  while(t--)
  {
    string s;
    cin>>s;
    int ans=0;
    int count=0;
    REP(i,s.length())
    {
        if(s[i]=='0')
        count++;
        else
        {
            ans++;
        }
    }
    cout<<min(count,ans)*2;
  }  
  return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define ifor(i,n) for(i=0;i<n;i++)
#define ll long long
int main()
{
     ios_base::sync_with_stdio(false);
     cin.tie(NULL);
    ll int  i,n,t,p=INT_MAX,j=0,x,a=0,b,l=0,r=0,y;
     string s,m;
     cin>>a>>b>>x;
     p=x-a-b;
     l=4*a*b;
     if(p<0){
        cout<<"No"<<endl;
     }
     else{
        p*=p;
        if(p>l){
            cout<<"Yes"<<endl;
        }
        else{
            cout<<"No"<<endl;
        }     }
     return EXIT_SUCCESS;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  vector<bool> n(1000000001,false);
  int N;
  string ans="YES";
  cin >> N;
  for(int i=0; i<N; i++){
  	int a;
    cin >> a;
    if(n.at(a))ans="NO";
    n.at(a)=true;
  }
  cout << ans << endl;
}

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

long long n;
vector<long long> a, memo;

long long solve();

int main() {
  cin >> n;
  ++n;
  a.resize(n);
  for (auto &p : a) cin >> p;
  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long res = 0, now = 1;
  memo.assign(n, 0);
  memo[n - 1] = a[n - 1];
  for (int i = n - 2; i >= 0; --i) memo[i] = memo[i + 1] + a[i];
  now = 1;
  for (int i = 0; i < n; ++i) {
    now = min(memo[i], now);
    res += now;
    now -= a[i];
    if (i != n - 1 && now <= 0) return -1;
    if (i == n - 1 && now != 0) return -1;
    now *= 2;
  }
  if (n == 1 && a[0] != 1) return -1;
  return res;
}

Measured memory_bytes: 4748
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug {
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
      }
  }

#[fastout]
fn main() {
    input!{
        a: usize,
        b: usize,
    }

    let east = (1+b-a)*(b-a)/2;
    println!("{}", east-b);

}


Measured memory_bytes: 2196
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <map>
#include <set>
#include <cstdio>
#include <cmath>
#define rep(i,l,n) for(lint i=l;i<n;i++)
#define rer(i,l,n) for(lint i=l;i<=n;i++)
#define alint(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define pb(a) push_back(a)
#define mk(a,b) make_pair(a,b)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef vector<lint> vli;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main(){
	int n,m;
    while(1){
        cin>>n>>m;
        if(n==0 && m==0) break;
        vector<int> a(n),b(m);
        int asum=0,bsum=0;
        for(int i=0;i<n;i++){
            cin>>a[i];
            asum+=a[i];
        }
        for(int j=0;j<m;j++){
            cin>>b[j];
            bsum+=b[j];
        }
        int d=asum-bsum;
        bool f=0;
        if(d%2==0){
            rep(i,0,n){
            	rep(j,0,m){
            		if(a[i]==b[j]+d/2){
            			f=1;
            			o(a[i]<<" "<<b[j]);
            			break;
            		}
            	}
            	if(f) break;
            }
        }
        if(f==0) o(-1);
    }
}

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

int main() {
  int x = 700;
  string s;
  cin >> s;
  for(int i = 0;i < 3;i++) {
    if(s.at(i) == 'o') {
      x = x + 100;
    }
  }
  cout << x << endl;
}

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

struct Card {
    char suit, value;
};

void bubble (struct Card A[], int n){
    for (int i = 0; i < n; i++) {
        for (int j = n-1; j > i ; j--) {
            if (A[j].value < A[j - 1].value) {
                Card t = A[j]; A[j] = A[j - 1]; A[j - 1] = t;
            }
        }
    }
}

void selection(struct Card A[], int n) {
    for (int i = 0; i < n; i++) {
        int minj = i;
        for (int j = i; j < n; j++) {
            if (A[j].value < A[minj].value) minj = j;
        }
        Card t = A[i];
        A[i] = A[minj]; 
        A[minj] = t;
    }
}

void print(struct Card A[], int n ) {
    for (int i = 0; i < n; i++) {
        if (i) cout << " ";
        cout << A[i].suit << A[i].value;
    }
    cout << endl;
}

bool isStable(struct Card C1[], struct Card C2[], int n) {
    for (int i = 0; i < n; i++) {
        if (C1[i].suit != C2[i].suit) return false;
    }
    return true;
}

int main() {
    Card C1[100], C2[100];
    int n;
    
    cin  >> n;
    for (int i = 0; i < n; i++) {
        cin >> C1[i].suit >> C1[i].value;
        
    }
    
    for (int i = 0; i < n; i++) C2[i] = C1[i];
    
    bubble(C1, n);
    selection(C2,n);
    
    print(C1, n);
    cout <<"Stable" << endl;
    print(C2, n);
    
    if(isStable(C1, C2,n)) {
        cout << "Stable" << endl;
    } else {
        cout << "Not stable" << endl;
    }
    
    return 0;
}


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

int main(){
    int n;
    cin >> n;
    int dp[100010];
    dp[0]=0;
    int num;
    for(int i = 1; i <= 100000; i++)
    {
        dp[i] = 1e7;
        num=1;
        while(num<=i){
            dp[i] = min(dp[i], dp[i-num]+1);
            num*= 6;
        }
        num=1;
        while(num<=i){
            dp[i]= min(dp[i], dp[i-num]+1);
            num *= 9;
        }
        
    }
    
    cout << dp[n] << endl;
    return 0;
}

Measured memory_bytes: 640
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines

def main():
    n, k = map(int, input().split())
    r, s, p = map(int, input().split())
    t = input()

    dp = [[0] * 3 for _ in range(n + k)]
    for i1 in range(k):
        i2 = i1 + k
        while i2 - k < n:
            dp[i2][0] = max(dp[i2-k][1], dp[i2-k][2])
            dp[i2][0] += r if t[i2-k] == 's' else 0
            dp[i2][1] = max(dp[i2-k][0], dp[i2-k][2])
            dp[i2][1] += s if t[i2-k] == 'p' else 0
            dp[i2][2] = max(dp[i2-k][0], dp[i2-k][1])
            dp[i2][2] += p if t[i2-k] == 'r' else 0
            i2 += k
    r = 0
    for j1 in range(-k, 0, 1):
        r += max(dp[j1])
    print(r)

if __name__ == '__main__':
    main()

Measured memory_bytes: 31664
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
typedef long long ll;
const int inf = 1e9;
int main(){
    string s, t;
    cin >> s >> t;
    int n = s.size(), m = t.size();
    vector<vector<int> > lp(n+1, vector<int>(m+1));
    rep(i,n+1)lp[i][0] = i;
    rep(i,m+1)lp[0][i] = i;
    REP(i,1,n+1)REP(j,1,m+1){
        if(s[i-1] == t[j-1])lp[i][j] = min(lp[i-1][j]+1, min(lp[i][j-1]+1, lp[i-1][j-1]));
        else lp[i][j] = min(lp[i-1][j]+1, min(lp[i][j-1]+1, lp[i-1][j-1]+1));
    }
    cout << lp[n][m] << endl;

    //rep(i,n+1)rep(j,m+1)cout << lp[i][j] << ((j < m)?" ":"\n");

    return 0;
}


Measured memory_bytes: 6872
#include<cstdio>
using namespace std;
int n,dp[(1<<20)+1][21],a[21],b[21],c[21];
int main() {
	scanf("%d", &n);
	int ans = 0;
	for (int i = 1; i <= n; ++i)scanf("%d", &a[i]);
	for (int i = 1; i <= n; ++i)scanf("%d", &b[i]);
	for (int i = 1; i < n; ++i)scanf("%d", &c[i]);
	for (int i = 1; i <= n; ++i) {
		ans += b[a[i]];
		if (a[i - 1] == a[i] - 1)ans += c[a[i-1]];
	}
	printf("%d", ans);
}

Measured memory_bytes: 128
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <utility>
#include <complex>
#include <stack>

using namespace std;

typedef complex<double> P;

int main(){
	int a[5];
	for (int i = 0; i < 5; i++)
	{
		cin>>a[i];

	}
	sort(a,a+5);

	for (int i = 0; i < 5; i++)
	{
		printf("%d%c",a[4-i],(i == 4) ? '\n' : ' ');
	}

	return 0;
}

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


signed main() {
  int N, M;
  cin >> N >> M;
  
  int kake = 1;
  for( int i = 0; i < M; i++ ){
    kake *= 2;
  }
  
  cout << ((1900*M) + 100*(N-M)) * kake << endl;
    
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) {
  return x == 0 ? 1 : log10(x) + 1;
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

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

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

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

template <typename T>
void debugV(const vector<T> v) {
#ifdef _DEBUG
  rep(i, v.size()) {
    cout << i << ":" << v[i] << " ";
  }
  cout << endl;
#else
  (void)v;
#endif
}

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

signed main() {
  ll N, K;
  cin >> N >> K;
  ll ans = 0;
  rep(i, N + 1) {
    if (i <= K) {
      continue;
    }
    ll p = N / i;
    ll m = max((ll)0, i - K);
    ans += p * m;
    ll amari = N % i;
    if (K == 0) {
      ans += amari;
    } else {
      ll d = max((ll)0, amari - K + 1);
      ans += d;
    }
  }
  COUT(ans);
  return 0;
}

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

int main(){
    int n;
    cin >> n;
    vector<int> p(n),q(n),jisho(n);
    rep(i,n){
        cin >> p.at(i);
    }
    rep(i,n){
        cin >> q.at(i);
    }
    rep(i,n){
        jisho.at(i) = i+1;
    }
    int a,b,count=0;
    do{
        count++;
        rep(i,n){
            if(p==jisho){
                a=count;
            }
            if(q==jisho){
                b=count;
            }
        }
    }while(next_permutation(jisho.begin(),jisho.end()));
    cout << abs(a-b) << endl;
    return 0;
}


Measured memory_bytes: 3576
import Control.Monad
g b a c = if null a then c else (head b)*(head a)+g (tail b) (tail a) c
f :: [Int]->[[Int]]->Int->[Int]
f b a c = if null a then [] else (if (g b (head a) c)>0 then [1] else [0]) ++(f b (tail a) c)
main=do
 [n,m,c]<-map read.words<$>getLine
 b<-map read.words<$>getLine
 a<-map ((map read).words)<$>replicateM n getLine
 print$sum$f b a c

Measured memory_bytes: 1020
using System;

namespace AtCoder0804
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str=Console.ReadLine().Split();
            int a = Int32.Parse(str[0]);
            int b = Int32.Parse(str[1]);
            int c = Int32.Parse(str[2]);
            int ans = c - (a - b) > 0 ? c - (a - b) : 0;
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store") // to restrict undesirable precision
#pragma GCC optimize ("-fno-defer-pop")// to pop argument of function as soon as it returns
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define takeline cin.ignore();
#define sc second
#define N 3000005
#define endl "\n"
#define mod 1000000007
//((1.0l)*BIG MULTIPLY MAGIC?)
// string to integer stoi()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();
//-----------------------------------------------
int main(){

	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll a,b;
	cin>>a>>b;
	if(b==1){
		cout<<"0";return 0;
	}
	ll l,r,mid,an;
	l=1; r=1e10;
	while(r>=l){
		mid=(l+r)/2;

		ll c=a*mid-(mid-1);
		if(c>=b){
			an=mid;
			r=mid-1;
		}
		else l=mid+1;
	}
	cout<<an;
	return 0;
}

Measured memory_bytes: 256