akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define print(x) cout << (x) << endl
typedef long long ll;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;

using namespace std;

int main(){
    int n;  cin >> n;
    string s;   cin >> s;
    s = 'z' + s;
    s += 'z';
    int l = s.length();
    vector<int> e(l+1,0);
    for(int i=1; i<l; i++){
        if(s[i] == 'E') e[i] = e[i-1] + 1;
        else    e[i] = e[i-1];
    }
    int ans = l - 1;
    for(int i=1; i<n+1; i++){
        ans = min(ans, i - e[i-1] + e[l-1] - e[i]);
    }
    ans--;
    print(ans);
}

Measured memory_bytes: 4820
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

N, H = MAP()

AB = [LIST() for _ in range(N)]
a, b = zip(*AB)
b = list(b)
a_max = max(a)

ans = 0
b.sort()

damage = 0
while damage < H:
	if 0 < len(b) and a_max < b[-1]:
		damage += b.pop()
		ans += 1
	else:
		ans += ceil((H-damage)/a_max)
		break
print(ans)

Measured memory_bytes: 36364
#include<bits/stdc++.h>
using namespace std;
bool isNum(char ch){ return ('0'<=ch&&ch<='9'); }
bool isAL(char ch){ return ('A'<=ch&&ch<='Z'); }
bool isAl(char ch){ return ('a'<=ch&&ch<='z'); }
 
string s;
map<string,string> mp;
int len;
char str[123456];
 
// ----------
int calc();
int getNum();
int getOp();
int pos;
int calcMain(){pos=0;return calc();}
 
int getNum(){
  if(str[pos]=='('){
    pos++;
    return calc();
  }
  int num=0;
  while(isNum(str[pos])){
    num*=10;
    num+=(str[pos]-'0');
    pos++;
  }
  return num;
}
 
int getOp(){
  pos++;
  return str[pos-1];
}
 
int calc(){
  stack<int> st;
  st.push(getNum());
  while(1){
    char op=getOp();
    if(op=='='||op==')')break;
    int num=getNum();
    if(op=='+')st.push(num);
    else{
      int k=st.top();
      st.pop();
      st.push(k*num);
    }
  }
  int res=0;
  while(!st.empty()){
    res+=st.top();st.pop();
  }
  return res;
}
// ----------
 
void solve(){
 
  int len=s.size(),size=0;
  for(int i=0;i<len;i++){
    char ch=s[i];
    if(ch=='('){
      str[size]=ch;size++;
    }else if(ch==')'){
      str[size-1]=')';
      str[size]='+';
      size++;
    }else if(isAL(ch)){
      string tmp="";
      tmp.push_back(ch);
      if(i+1<len&&isAl(s[i+1])){
        tmp.push_back(s[i+1]);
        i++;
      }
      tmp=mp[tmp];
      if(tmp==""){cout<<"UNKNOWN"<<endl;return;}
      for(int j=0;j<(int)tmp.size();j++){
        str[size]=tmp[j]; 
        size++;
      }
      str[size]='+';
      size++;
    }else if(isNum(ch)){
      str[size-1]='*';
      str[size]=ch;
      size++;
      if(i+1<len&&isNum(s[i+1])){
        str[size]=s[i+1];
        size++;
        i++;
      }
      str[size]='+';
      size++;
    }
  }//i
  str[size-1]='=';
  /*
  for(int i=0;i<size;i++){
    cout<<str[i];
  }
  cout<<endl;
  */
  cout<<calcMain()<<endl;
}
 
int main(){
  string a,b;
  while(cin>>a&&a.size()<=2){
    cin>>b;
    mp[a]=b;
  }
  while(cin>>s&&s!="0")solve();
  return 0;
}

Measured memory_bytes: 1228
def mht(a,b):
	return abs(a[0]-b[0])+abs(a[1]-b[1])
n,m=map(int,input().split())
p=[list(map(int,input().split())) for _ in range(n)]
c=[list(map(int,input().split())) for _ in range(m)]
#print(p)
#print(c)
for i in p:#全ての人に対してループ
	a=[10**9,0]#[最小距離、チェックポイントの番号]
	for j in range(m):#全てのチェックポイントに対してループ
		if mht(i,c[j])<a[0]:#最小距離を更新した場合
			a=[mht(i,c[j]),j+1]
	print(a[1])#i番目の学生が行くチェックポイント


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

int main()
{
    ll n,k;
    cin>>n>>k;
    ll r,p,s;
    cin>>r>>s>>p;
    string t;
    map< char , int > m;
    m.insert(make_pair('r', p));
    m.insert(make_pair('p', s));
    m.insert(make_pair('s', r));
    
    cin>>t;
    ll total = 0;
    for(ll i=0; i<k; i++){
        bool distinct = true;
        ll count = 0;
        ll j;
        for(j=i; j<n; j += k){
            if(j == i){
                count++;
                continue;
            }
            if(t[j] == t[j-k]){
                count++;
            }else{
                count = (count / 2) + (count % 2);
                total += count * m[t[j-k]];
                count = 1;
            }
        }

        count = (count / 2) + (count % 2);
        total += count * m[t[j-k]];
        count = 1;
    }
    cout<<total;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;

int main() {
  int n;
  cin >> n;
  vi L(100010,0);
  rep(i,n){
    ll m;
    cin >> m;
    L[m]++;
  }
  ll ans = 0;
  ll cnt = 0;
  rep(i,100010){
    if(L[i] > 0) ans++;
    if(L[i] >=2 && L[i]%2==0) cnt++;
  }
  cout<<ans-cnt%2<<endl;
  return 0;
}

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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)

#define mod 1e9+7;
#define inf 1e18+7;

typedef long long ll;

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

    int sum=0;
    vector<int>S;

    rep(i,n){
        int s;
        cin>>s;
        sum+=s;

        if(s%10!=0){
            S.push_back(s);
        }
    }

    if(sum%10!=0){
        cout<<sum<<endl;
        return 0;
    }

    sort(S.begin(),S.end());

    if(S.size()==0){
        cout<<0<<endl;
        return 0;
    }

    cout<<sum-S[0]<<endl;

}


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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> s(m), c(m);
  rep(i, m) cin >> s[i] >> c[i];

  map<ll, ll> mp;
  rep(i, m) {
    if (mp.find(s[i]) != mp.end() && mp[s[i]] != c[i]) {
      cout << -1 << endl;
      return 0;
    } else {
      mp[s[i]] = c[i];
    }
  }

  if (n == 1 && mp[1] == 0) {
    cout << 0 << endl;
    return 0;
  }

  rep(i, m) {
    if (s[i] == 1 && c[i] == 0 && n != 1) {
      cout << -1 << endl;
      return 0;
    }
  }

  string ans = "";
  if (mp.find(1) == mp.end())
    ans = "1";
  else
    ans = to_string(mp[1]);

  for (ll i = 2; i <= n; ++i) {
    if (mp.find(i) != mp.end())
      ans = ans + to_string(mp[i]);
    else
      ans = ans + "0";
  }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P std::pair<int,int>
#define PiP std::pair<int,std::pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp std::make_pair
#define prique(T) std::priority_queue<T,vector<T>,greater<T>>
using namespace std;
template<class T> inline void chmax(T& a, T b) { a = std::max(a, b); }
template<class T> inline void chmin(T& a, T b) { a = std::min(a, b); }

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x != 1;
}
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;
}
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 get_rand(int MIN, int MAX) {
	std::random_device rnd;
	std::mt19937 mt32(rnd());
	std::uniform_int_distribution<int>engine(MIN, MAX);
	return engine(mt32);
}
/*--------Library Zone!--------*/


int n, k;
int a[200005], sum[200005];
map<int, int>mp;
signed main() {
	cin >> n >> k;
	int ans = 0;
	REP(i, n + 1) {
		cin >> a[i];
		sum[i] += a[i];
		sum[i + 1] += sum[i];
	}
	mp[0] = 1;
	REP(i, n + 1) {
		if (i >= k) {
			mp[(sum[i - k] - (i - k) + k) % k]--;
		}
		ans += mp[(sum[i] - i + k) % k];
		mp[(sum[i] - i + k) % k]++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 16000
from math import factorial
def comb(n, r):
    return factorial(n) // factorial(r) // factorial(n - r)
n, blue = map(int, input().split())
red = n - blue
mod = 10 ** 9 + 7
for i in range(1, blue + 1):
    if red + 1 - i < 0:
        print('0')
        continue
    ans = comb(red + 1, i)
    ans %= mod
    ans *= comb(blue - 1, i - 1)
    ans %= mod
    print(ans)

Measured memory_bytes: 3316
fun main(args: Array<String>) {
  val s = readLine()!!
  val k = readLine()!!.toInt()
  val n = s.length
  val dp = Array(n, { Array(n, { IntArray(k + 1, { -1 } ) })})

  // Max length of Palindrome sub-sequence
  // [l, r]: Range (closed)
  // c: Change
  fun doDP(l: Int, r: Int, c: Int): Int {
    if (dp[l][r][c] >= 0) return dp[l][r][c]

    fun doDPInternal(l: Int, r: Int, c: Int): Int {
      if (l == r) return 1
      if (r - l == 1) {
        return if (s[l] == s[r] || c > 0) 2 else 1
      }
      // r - l >= 2
      if (s[l] == s[r]) {
        return doDP(l + 1, r - 1, c) + 2
      } else {
        val v1 = Math.max(doDP(l + 1, r, c), doDP(l, r - 1, c))
        if (c == 0) return v1
        val v2 = doDP(l + 1, r - 1, c - 1) + 2
        return Math.max(v1, v2)
      }
    }

    val value = doDPInternal(l, r, c)
    dp[l][r][c] = value
    return value
  }

  println(doDP(0, n - 1, k))
}


Measured memory_bytes: 156008
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define sz(x) int(x.size())
using ll = long long;
using P = pair<int,int>;
const ll LLINF = numeric_limits<long long>::max();
const int mod = 1000000007;
const int INF = 1001001001;
 
int main()
{
    int N,M,X;
    cin >> N >>M >>X;
    vector <int> C(N);
    int  A[N][M];
    for(int i=0;i<N;i++){
        cin >> C[i];
        for(int j=0;j<M;j++){
             cin >> A[i][j];
        }
    }
    ll ans = INF;
    rep(div,1<<(N)) {
        vector<int> id(M);
        bool flag = true;
        ll cos=0; 
        //cout << "sss"<<div << endl;
        rep(i,N) {
        // cout << div;
        int d = div;
            if (d>>i&1){
              cos += C[i];  
              for(int j=0;j<M;j++){
                    //cout << "j " << j  << endl;
                    //cout << "a "<<A[i][j] << endl;
                    id[j] += A[i][j];
                    //cout << "id "<<id[j] << endl;
                }       
            }
        }
        for(int j=0;j<M;j++){
            //cout << id[j] << " ";  
            if(id[j] < X){
                flag=false;
            }
        }
        //cout << endl;
        if(flag){
            ans = min(ans, cos);
        }
    }   
    if(ans == INF){
        ans =-1;
    }
    cout << ans;
 
 
 
    return 0;
}

Measured memory_bytes: 3604
#include<iostream>
#include<vector>
#include<cfloat>
#include<cmath>
#include<set>
using namespace std;

#define NONE DBL_MAX

struct Sphere{
  double x,y,z,r;
};

double dist(Sphere a, Sphere b)
{
  double d=sqrt( pow(a.x-b.x,2.0)+pow(a.y-b.y,2.0)+pow(a.z-b.z,2.0) );
  return a.r+b.r<d?d-a.r-b.r:0.0;
}

double prim(vector< vector<double> >v)
{
  double sum=0.0;
  int n=v.size();
  set<int>selected;
  set<int>::iterator it;
  double mincost;
  int mini;
  selected.insert(0);
  while(selected.size()!=n){
    mincost=DBL_MAX;
    for(it=selected.begin();it!=selected.end();it++){
      for(int i=0;i<n;i++){
        if(selected.find(i)!=selected.end())continue;
        if(v[*it][i]==NONE)continue;
        if(v[*it][i]>=mincost)continue;
        mincost=v[*it][i];
        mini=i;
       }
     }
    if(mini==NONE)break;
    sum+=mincost;
    selected.insert(mini);
  }
  return sum;
}

int main()
{
  int n;
  double x,y,z,r;
  while(cin>>n,n){
    vector<Sphere>list(n);
    vector< vector<double> >A(n,vector<double>(n,NONE));
    for(int i=0;i<n;i++)cin>>list[i].x>>list[i].y>>list[i].z>>list[i].r;
    for(int i=0;i<n;i++){
      for(int j=i+1;j<n;j++){
	A[i][j]=A[j][i]=dist(list[i],list[j]);
      }
    }
    printf("%.3f\n",prim(A));
  }
}

Measured memory_bytes: 1152
import sys
import collections
import math
from collections import Counter
from collections import deque

N = int(input())

d = 10**9 + 7


def prime_decomposition(n):
    i = 2
    table = []
    while i * i <= n:
        while n % i == 0:
            n /= i
            table.append(i)
        i += 1
    if n > 1:
        table.append(n)
    return table


cnt = Counter()

for i in range(2, N + 1):
    prime_list = prime_decomposition(i)
    tmpCnt = Counter(prime_list)
    cnt.update(tmpCnt)

# print(cnt)

ans = 1
for i in cnt.items():
    ans *= (i[1] + 1)

print(ans % d)

sys.exit(0)


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

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

    vector<P> vc(m);
    rep(i,m) cin >> vc[i].first >> vc[i].second;

    rep(i,1000){
        string s = to_string(i);
        if (s.size() != n) continue;

        bool flag = true;
        rep(j,m){
            if(vc[j].first > s.size()){
                flag = false;
                break;
            }
            if(s[vc[j].first - 1] - '0' != vc[j].second){
                flag = false;
                break;
            }
        }

        if(flag) {
            cout << s << endl;
            return 0;
        }
    }


    cout << -1 << endl;

    return 0;
    
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
    double n,d,a,b,c,num=0;
    cin>>n>>d;
    while(n--)
    {
        cin>>a>>b;
        a=pow(a,2);
        b=pow(b,2);
        c=pow(a+b,0.5);
        if (c<=d)
            num+=1;
    }
    cout<<num<<endl;
}


Measured memory_bytes: 4484
import java.util.*;
class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int N=sc.nextInt();
		int[] A=new int[N];
		int count=0;
		for(int i=0;i<N;i++){
			A[i]=sc.nextInt();
		}
		Out:while(true){
			for(int i=0;i<N;i++){
				if(A[i]%2 != 0){
					break Out;
				}
				A[i]/=2;
			}
			count++;
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 21844
import java.util.*;

public class Main {
	public static void main(String[] args) {  
  		Scanner sc = new Scanner(System.in);
      	int r = sc.nextInt();
      	int D = sc.nextInt();
      	int x2000 = sc.nextInt();
      
      	for(int i = 0; i < 10; i++) {
        	System.out.println(r * x2000 - D);
          	x2000 = (r * x2000 - D);
        }
    }
}

Measured memory_bytes: 22868
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int cnt = 0;
		for(int i = 1; i < n + 1; i++) {
			int tmp = sc.nextInt();
			if(tmp != i)
				cnt++;
		}
		if(cnt == 2 || cnt == 0) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}

	}

}


Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
int main()
{

	long long int l, r, d, count = 0;
	cin >> l >> r >> d;
	for (int i = l ; i <= r ; i++)
	{
		if (i % d == 0) count++;
	}

	cout << count << endl;
	return 0;

}

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

int main() {
	string s;
	cin >> s;
	if (s[2] == s[3] && s[4] == s[5]) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;	
}


Measured memory_bytes: 256
#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<string.h>
#include<vector>
#include<stdlib.h>
#include<math.h>
#include<queue>
#include<deque>
#include<ctype.h>
#include<map>
#include<set>
#include<stack>
#include<string>
#define INF 0x3f3f3f3f
#define FAST_IO ios::sync_with_stdio(false)
const double PI = acos(-1.0);
const double eps = 1e-6;
const int MAX=1e5+10;
const int mod=1e9+7;
typedef long long ll;
using namespace std;
#define gcd(a,b) __gcd(a,b)
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll qpow(ll a,ll b){ll r=1,t=a; while(b){if(b&1)r=(r*t)%mod;b>>=1;t=(t*t)%mod;}return r;}
inline ll inv1(ll b){return qpow(b,mod-2);}
inline ll exgcd(ll a,ll b,ll &x,ll &y){if(!b){x=1;y=0;return a;}ll r=exgcd(b,a%b,y,x);y-=(a/b)*x;return r;}
inline ll read(){ll x=0,f=1;char c=getchar();for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;for(;isdigit(c);c=getchar()) x=x*10+c-'0';return x*f;}
//freopen( "in.txt" , "r" , stdin );
//freopen( "data.txt" , "w" , stdout );



char s[100005];
int main()
{
    int i,j,len,flag=1;
    char s1[15]=" dream",s2[15]=" dreamer",s3[15]=" erase",s4[15]=" eraser";

    scanf("%s",s+1);
    len=strlen(s+1);

    for(i=1;i<=len;i++)
    {
        for(j=1;j<=7;j++)
        {
            if(s[i+j-1]!=s2[j])
                break;
        }
        if(j==8 && s[i+j-1]!='a')
        {
            i=i+6;
            continue;
        }


        for(j=1;j<=6;j++)
        {
            if(s[i+j-1]!=s4[j])
                break;
        }
        if(j==7)
        {
            i=i+5;
            continue;
        }

        for(j=1;j<=5;j++)
        {
            if(s[i+j-1]!=s1[j])
                break;
        }
        if(j==6)
        {
            i=i+4;
            continue;
        }

        for(j=1;j<=5;j++)
        {
            if(s[i+j-1]!=s3[j])
                break;
        }
        if(j==6)
        {
            i=i+4;
            continue;
        }

        flag=0;
    }

    if(flag)
        printf("YES\n");
    else
        printf("NO\n");
    return 0;
}



Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cassert>
#include <memory.h>
#include <queue>
#include <cstdio>
#include <cstdlib>
#include <set>
#include <map>
#include <cctype>
#include <iomanip>
#include <sstream>
#include <cctype>
#include <fstream>
#include <cmath>
using namespace std;

#define rep(i, n) for(int i = 0; i< (int)(n); i++)
#define all(c) (c).begin(), (c).end()
#define iter(c) __typeof((c).begin())
#define pb(e) push_back(e)
#define foreach(c, i) for(iter(c) i = (c).begin(); i != c.end(); ++i)
#define mp(a, b) make_pair(a, b)

typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1000 * 1000 * 1000 + 7;
const double EPS = 1e-10;
const int maxS = 400;

inline ll encode(const vector<int> &cards){
  ll res = 0;
  rep(i, 13){
    res = res << 3 | cards[i];
  }
  return res;
}

inline vector<int> decode(ll code){
  vector<int> cards;
  rep(i, 13){
    cards.pb((code >> (12 - i) * 3) & 7);
  }
  return cards;
}



set<ll> memo[maxS];
vector<int> res;

bool dfs(int sum, ll code){
  if(code == 0)  return true;
  if(memo[sum].count(code)) return false;

  memo[sum].insert(code);
  
  vector<int> v = decode(code);
  rep(i, 13){
    int n = i + 1;
    if(v[i] == 0 || sum % n > 0) continue;
    
    v[i]--;
    if(dfs(sum - n, encode(v))){
      //cout << n << endl;
      res.push_back(n);
      return true;
    }
    
    v[i]++;
  }
  return false;
}

int main(){
  int N, c;
  while(cin >> N && N){
    //    cout << N << endl;
    int sum = 0;
    res = vector<int>();
    rep(i, maxS) memo[i].clear();
    
    vector<int> v(13, 0);
    rep(i, N){
      cin >> c;
      sum += c;
      v[--c]++;
    }

    //    rep(i, 13) cout << v[i] << endl;
    if(dfs(sum, encode(v))){
      assert(N == (int)res.size());
      rep(i, N) cout << res[i] << (i == N - 1 ? '\n' : ' ');
    }else{
      cout << "No" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1492
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	int n,m;
	cin>>n>>m;
	int nmax=50;
	int a[nmax],b[nmax],c[nmax],d[nmax];
	for(int i=0;i<n;i++){
		cin>>a[i]>>b[i];
	}
	for(int j=0;j<m;j++){
		cin>>c[j]>>d[j];
	}
	
	for(int i=0;i<n;i++){
		int min_d=abs(a[i]-c[0])+abs(b[i]-d[0]),checkpoint=1;
		for(int j=1;j<m;j++){
			int cu_d=abs(a[i]-c[j])+abs(b[i]-d[j]);
			if(min_d>cu_d){
				min_d=cu_d;
				checkpoint=j+1;
			}
		}
		cout<<checkpoint<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
int main(){
	string s;
	cin>>s;
	bool even=true;
	for(char c='a';c<='z';c++){
		int cnt=0;
		for(int i=0;i<s.length();i++){
			if(s[i]==c){
				cnt++;
			}
		}
		if(cnt%2==1)even=false;
	}
	cout<<(even?"Yes":"No")<<endl;
}

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

int main(void) {
  int a, b;

  cin >> a >> b;
  if (a == 1) a += 13;
  if (b == 1) b += 13;

  if (a == b) cout << "Draw" << endl;
  else if (a > b) cout << "Alice" << endl;
  else cout << "Bob" << endl;

  return 0;
}


Measured memory_bytes: 256
"use strict";
function Main(input) {
    var nums = input.split(" ").map(function(value) { return value - 0; });
    console.log((Math.min(nums[1], nums[2])), Math.max((nums[1] + nums[2]) - nums[0], 0));
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

N = int(input())
L = [int(input()) for _ in range(N)]
ma = max(L)

s = 0
f = True
for v in L:
    if ma == v and f:
        f = False
        s += v // 2
    else:
        s += v
        
print(s)

Measured memory_bytes: 2940
N,W=map(int,input().split())
w=[0 for i in range(N)]
v=[0 for i in range(N)]
for i in range(N):
    w[i],v[i]=map(int,input().split())
V=sum(v)
INF=10**15
dp=[[INF for j in range(V+1)] for i in range(N+1)]
#dp[i][j]:iまで試して価値の合計がjのときの重さの最小値
dp[0][0]=0
for i in range(N):
    for j in range(V+1):
        if j-v[i]>=0:
            dp[i+1][j]=min(dp[i][j],dp[i][j-v[i]]+w[i],INF)
        else:
            dp[i+1][j]=min(dp[i][j],INF)
b=[]
for i in range(V+1):
    if dp[N][i]!=INF:
        b.append((dp[N][i],i))
ans=0
for (x,y) in b:
    if x<=W:
        ans=max(ans,y)
print(ans)


Measured memory_bytes: 171628
import sys

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
printV = lambda x: print(*x, sep="\n")
printH = lambda x: print(" ".join(map(str,x)))
def IS(): return sys.stdin.readline()[:-1]
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LI1(): return list(map(int1, sys.stdin.readline().split()))
def LII(rows_number): return [II() for _ in range(rows_number)]
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def LLI1(rows_number): return [LI1() for _ in range(rows_number)]
mo = 10**9+7

def main():
	n=II()
	d,x=MI()
	ans = x
	for _ in range(n):
		a = II()
		times = (d-1)//a+1
		ans += times
	print(int(ans))


if __name__ == '__main__':
	main()

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>

using namespace std;

int main(){
   int a,b;
   double A,B;
   double GCD,LCM;
   double z;
   
   while(cin>>A>>B){
      if(A<B){
         z = A;
         A = B;
         B = z;
      }
      a = static_cast<int>(A);
      b = static_cast<int>(B);
   
      while(1){
         if(a%b == 0){
            GCD = static_cast<double>(b);
            break;
         }
         z = a%b;
         a = b;
         b = z;
      }
      LCM = A*B/GCD;
      
      printf("%.0lf %.0lf\n",GCD,LCM);
   }
   return 0;
}

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

typedef long long ll;
const ll mod = 998244353;

#define FOR(i, s, e) for (ll i = s; i < e; i++)
#define FOr(i, s, e) for (ll i = s; i >= e; i--)

#define PI acos(-1)
#define sz 100005

void fastio()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}

// int arr[1000006];

void solve()
{
	string s, t; cin >> s >> t;

	ll cnt = 0;

	FOR(i, 0, s.size())
	{
		if (s[i] != t[i]) cnt++;
	}
	cout << cnt << '\n';
}

int main()
{
	fastio();

	int t = 1; //cin >> t;
	while (t--)
		solve();

	return 0;
}


Measured memory_bytes: 3800
n=int(input())
s=str(input())
t=len(s)
r=set()
g=set()
b=set()
a=0
for i in range(n):
    if s[i]=='R':
        r.add(i)
    if s[i]=='G':
        g.add(i)
    if s[i]=='B':
        b.add(i)
d=len(r)*len(g)*len(b)
for ri in r:
    for gi in g:
        dist = abs(ri-gi)
        if ri > gi:
            bi = dist + ri
            if bi in b:
                d -= 1
            bi = gi - dist
            if bi in b:
                d -= 1
        else:
            bi = dist + gi
            if bi in b:
                d -= 1
            bi = ri - dist
            if bi in b:
                d -= 1

        if (ri + gi) % 2 == 0:
            bi = (ri+gi)/2
            if bi in b:
                d -= 1
print(d)

Measured memory_bytes: 9368
from operator import mul
from functools import reduce


def cmb(n, r):
	if n < r:
		return 0
	r = min(n - r, r)
	if r == 0:
		return 1
	numer = reduce(mul, range(n, n - r, -1))
	denom = reduce(mul, range(1, r + 1))
	return numer // denom % INF


N, K = map(int, input().split())
INF = 10 ** 9 + 7

for i in range(1, K + 1):
	print(cmb(K - 1, i - 1) * cmb(N - K + 1, i) % INF)

Measured memory_bytes: 9628
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int lld;

const lld mod = 1e9+7;
const lld INF = 1e9;
const lld MAXN = 1e9;

int main()
{
	lld n,m;
	cin >> n >> m;

	lld x = min(n,m);
	lld y = max(n,m);

	if (y == 1)
	{
		cout << 1 << endl;
	}else if (x == 1)
	{
		cout << y-2 << endl;
	}else if (x == 2)
	{
		cout << 0 << endl;
	}else
	{
		cout << (x-2)*(y-2) << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
//#define num 1000000007
#define pi acos(-1.0)
//cout << fixed << setprecision (20);   小数点以下2０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'0'+=16;        で大文字に
//'大文字'+=32;    で小文字に
//s[i]-'0'でchar文字→int数に;
//string s = to_string(int数);
//int n = stoi(string文字列)
//実行時間制約2秒では２×10^8回くらいまで計算できる


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

  vector<int> p(n);
  vector<int> d(k);
  
  rep(i,k) {
    cin >> d[i];
    rep(j,d[i]){
    int x;
    cin >>x;
    p[x-1]++;
    }
  }
  
 rep(i,n){
   if(p[i]==0)ans++;
 }
  
  cout << ans << endl;    
  
  
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define FORR(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))

#define DEBUG(x) cout<<#x<<": "<<(x)<<endl

int n,k,q;
int a[125252];
int cnt[125252];

int main(){
	scanf("%d%d%d",&n,&k,&q);
	REP(i,q)scanf("%d",a+i),a[i]--;
	REP(i,q)cnt[a[i]]++;
	REP(i,n){
		int pnt = k - (q-cnt[i]);
		puts(pnt>0 ? "Yes" : "No");
	}
	return 0;
}

Measured memory_bytes: 1408
import java.util.Scanner;

public class Main
{
	public static void main(String[] args)
	{
		Scanner scanner = new Scanner(System.in);
		String in = scanner.nextLine();
		int len = in.length();
		int max = 0, tmp = 0;
		for (int i = 0; i < len; i++)
		{
			if (in.charAt(i) == 'A' || in.charAt(i) == 'G' || in.charAt(i) == 'T' || in.charAt(i) == 'C')
			{
				tmp++;
				if (max < tmp)
				{
					max = tmp;
				}
			} else
			{
				tmp = 0;
			}
		}
		System.out.println(max);
	}
}


Measured memory_bytes: 22868
#include <stdio.h>

int main(void) {
	int N, K, X, Y;
	int horieyui;
	if (scanf("%d", &N) != 1) return 1;
	if (scanf("%d", &K) != 1) return 1;
	if (scanf("%d", &X) != 1) return 1;
	if (scanf("%d", &Y) != 1) return 1;

	horieyui = X * (N <= K ? N : K);
	if (N > K) horieyui += Y * (N - K);
	printf("%d\n", horieyui);
	return 0;
}


Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main(){
	int N, L;
	cin >> N >> L;

	if (L > 0){
		cout << (N - 1) * (2 * L + N) / 2 << endl;
	} else if (L + N - 1 < 0){
		cout << (N - 1) * (2 * L + N - 2) / 2 << endl;
	} else {
		cout << N * (2 * L + N - 1) / 2 << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int n, hen[3], i, j, k, co;
	scanf("%d", &n);
	for (i = 0; i < n; i++){
		scanf("%d %d %d", &hen[0], &hen[1], &hen[2]);
		for (j = 0; j < 3; j++){
			hen[j] *= hen[j];
		}
		for (j = 0; j < 3; j++){
			for (k = 0; k < 3; k++){
				if (hen[j] < hen[k]){
					co = hen[j];
					hen[j] = hen[k];
					hen[k] = co;
				}
			}
		}
		//printf("%d %d %d", hen[0], hen[1], hen[2]);
		if (hen[0] + hen[1] == hen[2]) printf("YES\n");
		else printf("NO\n");
	}
	return (0);
}

Measured memory_bytes: 580
//↓見なくていいよ！ここから--------------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  console.error("\n");
  var start = new Date();
  Main();
  var end = new Date() - start;
  
  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function makeClone(obj){return JSON.parse(JSON.stringify(obj));}
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}

//↑見なくていいよ！ここまで--------------------------------------------------
function Main(){
	var N = nextInt();
	var list = nextIntArray();
	var sum = 0;
	for(var i = 0; i < N; i++){
		if(i % 2 == 0){
			sum += list[i] * 2;
		}else{
			sum -= list[i] * 2;
		}
	}
	var output = new Array(N);
	output[0] = sum / 2;
	for(var i = 1; i < N; i++){
		output[i] = list[i - 1] * 2 - output[i - 1];
	}
	myout(myconv(output,8));
}


Measured memory_bytes: 48864
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define N 100010
#define NO !printf("No\n")
#define YES !printf("Yes\n")
typedef long long ll;
inline ll read(){
	ll x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')f=-1;
		c=getchar();
	}
	while(c>='0'&&c<='9'){
		x=(x<<1)+(x<<3)+c-'0';
		c=getchar();
	}
	return x*f;
}
int n,a[N],cnt[5],num[5],tot;
int main(){
	n=read();
	for(int i=1;i<=n;++i){
		a[i]=read();
		bool ok=false;
		for(int j=1;j<=tot;++j){
			if(num[j]==a[i]){
				++cnt[j];
				ok=true;
				break;
			}
		}
		if(!ok){
			++tot;
			if(tot>3)return NO;
			num[tot]=a[i];
			cnt[tot]=1;
		}
	}
	if(tot==1&&num[1]==0)return YES;
	if(tot==2){
		if(!num[1]&&2*cnt[1]==cnt[2])return YES;
		if(!num[2]&&2*cnt[2]==cnt[1])return YES;
	}
	if(tot^3||cnt[1]^cnt[2]||cnt[2]^cnt[3])return NO;
	return num[1]^num[2]^num[3]?NO:YES;
	return 0;
}




Measured memory_bytes: 3944
//https://onlinejudge.u-aizu.ac.jp/challenges/sources/JOI/Prelim/0510?year=2007

#include <bits/stdc++.h>

using namespace std;

int main() {
    int sumA = 0;
    for (int i = 0; i < 4; ++i) {
        int a;
        cin >> a;
        sumA += a;
    }

    int sumB = 0;
    for (int i = 0; i < 4; ++i) {
        int b;
        cin >> b;
        sumB += b;
    }

    cout << max(sumA, sumB) << endl;
    return 0;
}

/*
 *
 */


Measured memory_bytes: 3076
#include<stdio.h>
int main (){

    char strS[52];
    int N;
    int K;

    1<=N<=50;

    1<=K<=N;

    scanf("%d %d", &N, &K);

    scanf("%s", &strS);

    strS[K-1] += 32;

    printf("%s", strS);


    return 0;
}

Measured memory_bytes: 1656
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;

//using Graph = vector<vector<edge>>;
using dou =long double;
string yes="yes";
string Yes="Yes";
string YES="YES";
string no="no";
string No="No";
string NO="NO";

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; }
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(ll i = m; i < (ll)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define query int qq;std::cin >> qq;rep(qqq,qq)
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
#define case std::cout <<"Case #" <<qqq+1<<": "
#define RES(a,i,j) a.resize(i);rep(ii,i)a[ii].resize(j); 
#define as assign
#define ffor for(;;)
#define ppri(a,b) std::cout << a<<" "<<b << std::endl
#define pppri(a,b,c) std::cout<<a<<" "<<b<<" "<<c<<std::endl
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define ssum(a) accumulate(a,0ll) 
#define gre(n) greater<n>()

typedef long long ll;
//
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
//typedef long long T;
const int INF = 1000000000;
const double dINF = 1000000000;
const ll INF64 = 922337203685477580ll;
const ll MOD = 1000000007ll;
//const ll MOD = 67280421310721ll;
const dou pi=3.141592653589793;
//メモ
//二次元配列のresizeのしかた
//vv.resize(n);
//for(size_t i=0; i<n; i++){
// vv[i].resize(n);
//}

//メモ
//負の辺を持つ最短経路問題では到達不可経路でも初期化値より小さくなりうるので注意しよう！
int main(){
    ll x;
    std::cin >> x;
    ll ans=0;
    ans=(x/11)*2;
    x%=11;
    if(x!=0){
        if(x<7)ans++;
        else ans+=2;
    }
    std::cout << ans << std::endl;
}

Measured memory_bytes: 256
use std::io::*;
use std::str::*;

fn read<T: FromStr>(s: &mut StdinLock) -> T {
    let s = s.by_ref().bytes().map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok().unwrap()
}

fn main() {
    let s = stdin();
    let mut s = s.lock();
    let s = &mut s;

	let n = read::<i64>(s);
	
	let mut p:usize = 0;
	for a in 1..=n-1 {
		let d = (n-1) / a;
		if d == 0 {
			break;
		}
		p += d as usize;
	}

	println!("{}", p);

	
}


Measured memory_bytes: 2168
// Ver19.02
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF 1 << 29
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int main()
{
  int n, maybe1, maybe2;
  scanf("%d", &n);
  maybe1 = (n / 100) * 100 + (n / 100) * 10 + (n / 100);
  maybe2 = maybe1 + 111;
  if (n <= maybe1)
    printf("%d\n", maybe1);
  else
    printf("%d\n", maybe2);
  return 0;
}


Measured memory_bytes: 128
def cin():
	return map(int,input().split())

def cino(test=False):
    if not test:
        return int(input())
    else:
        return input()
def cina():
  return list(map(int,input().split()))

def ssplit():
    return list(input().split())


import math
a,b,c = cin()
print(b//c - a//c+(a%c==0))

Measured memory_bytes: 3316
N = gets.to_i
MOD = (10**9) + 7

STRING = %w(A G C T)
BLACK3 = %w(AGC GAC ACG)
BLACK = {
  /.AG/ => 'C',
  /.AC/ => 'G',
  /.GA/ => 'C',
  /A.G/ => 'C',
  /AG./ => 'C'
}

STRING_3 = STRING.repeated_permutation(3).map(&:join).reject { |s| BLACK3.include?(s) }
STRING_3_WITH_NEXT = STRING_3.each_with_object({}) { |str3, obj|
  obj[str3] = STRING - BLACK.each_with_object([]) {
    |(reg, str), obj|
    obj << str if reg === str3
  }
}

dp = Array.new(N+1) { Hash.new(0) }

STRING_3.each { |str| dp[3][str] = 1 }

4.step(N) do |i|
  STRING_3_WITH_NEXT.each do |str, next_strs|
    next_strs.each do |next_str|
      dp[i][str[1..2]+ next_str] = (dp[i - 1][str] + dp[i][str[1..2]+ next_str])%MOD
    end
  end
end

puts (dp[N].values.reduce(:+)%MOD)

Measured memory_bytes: 2428
#include<bits/stdc++.h>
#define Fst first
#define Snd second
#define RG register
#define mp make_pair
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long LL;
typedef long double LD;
typedef unsigned int UI;
typedef unsigned long long ULL;
template<typename T> inline void read(T& x) {
	char c = getchar();
	bool f = false;
	for (x = 0; !isdigit(c); c = getchar()) {
		if (c == '-') {
			f = true;
		}
	}
	for (; isdigit(c); c = getchar()) {
		x = x * 10 + c - '0';
	}
	if (f) {
		x = -x;
	}
}
template<typename T, typename... U> inline void read(T& x, U& ... y) {
	read(x), read(y...);
}
LL n;
vector<int> G;
//#define rua
int main() {
//	ios::sync_with_stdio(false);
#ifdef rua
	freopen("GG.in","r",stdin);
#endif
  read(n); ++n;
  int k=40;
  while(!(n>>k&1)) --k;
  int cnt=k;
  for(int i=0;i<k;++i) {
    if(n>>i&1) G.push_back(++cnt);
    G.push_back(i+1);
  }
  //G.push_back(k);
  printf("%d\n",G.size()*2);
  for(auto v: G) printf("%d ",v);
  for(int i=1;i<=k;++i) printf("%d ",i);
  for(int i=cnt;i>k;--i) printf("%d ",i);
  return 0;
}


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

int main(){
	
	int n;
	cin>>n;
	int arr[n];
	for(int i=0;i<n;i++){
		
		cin>>arr[i];
	}
	int index[n];
	for(int i=0;i<n;i++){
		index[arr[i]-1] = i+1;
		
	}
	for(int i = 0;i<n;i++){
		cout<<index[i]<<" ";
		
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 1536
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <string>
#include <iomanip>
#define faster       ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define f(i,a,b) for(ll i=a;i<b;i++)
#define r(i,a,b) for(ll i=a;i>b;i--)
using namespace std;
typedef long long ll;
typedef long double ld;

void max_self(ll &a, ll b){
  a=max(a,b);
}

int main(){

ll n,w; cin>>n>>w;
vector <ll> dp(w+1);

f(i,0,n){
  ll weight,value; cin>>weight>>value;

  r(j,w-weight,-1){
    max_self(dp[j+weight],dp[j]+value);
  }

}

ll ans=0;
f(i,0,w+1){
  max_self(ans,dp[i]);
}

cout << ans << endl;

}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long N = sc.nextLong();
    long K = sc.nextLong();

    long cnt = (K % 2 == 1 ? N/K : N/(K/2));

    if (K % 2 == 0) {
      long n1 = cnt/2;
      long n2 = cnt - n1;
      System.out.println(n1*n1*n1 + n2*n2*n2);
    } else {
      System.out.println(cnt*cnt*cnt);
    }
  }
}

Measured memory_bytes: 23636
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func intMin(x, y int) int {
	return int(math.Min(float64(x), float64(y)))
}

func main() {
	sc.Split(bufio.ScanWords)

	H, W := scanInt(), scanInt()

	C := [10][10]int{}
	for i := 0; i < 10; i++ {
		for j := 0; j < 10; j++ {
			C[i][j] = scanInt()
		}
	}

	Map := [10][100]int{}
	for i := 0; i < 10; i++ {
		Map[i][1] = C[i][1]
	}

	INF := int(math.Pow10(10))
	for j := 2; j < 100; j++ {
		for i := 0; i < 10; i++ {
			Map[i][j] = INF
			for k := 0; k < 10; k++ {
				Map[i][j] = intMin(Map[i][j], C[i][k]+Map[k][j-1])
			}
		}
	}

	A := [10]int{}
	for i := 0; i < H; i++ {
		for j := 0; j < W; j++ {
			a := scanInt()
			if a != -1 {
				A[a]++
			}
		}
	}

	ans := 0
	for i := 0; i < 10; i++ {
		ans += A[i] * Map[i][99]
	}
	fmt.Println(ans)
}


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

int main(){
	int a[3],i;
		for(i=0;i<3;i++){
			cin>>a[i];
		}if(a[0]==1){
			if(a[1]==1){
				cout<<"Open"<<endl;
			}
		}if(a[2]==1){
			cout<<"Open"<<endl;
		}else if(a[0]==1&&a[1]==1&&a[2]==0){
			
		}
		
		else{
			cout<<"Close"<<endl;
		}
	
	return 0;
}

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

#define ll long long

ll n;
ll a[2001];

ll abc (ll x, ll y) {
  if (x - y > 0) {
    return x - y;  
  }  
  return y - x;
}

ll solve (ll i, ll z, ll w, ll part) {
  // (i + 1) ~ n個見る
  if (i == n) {
    return abc(z, w);  
  }  
  ll max = -1;
  ll min = -1;
  for (ll j = i + 1; j <= n; j++) {
    // jまで取る
    ll sub;
    if (part == 0) {
      sub = solve (j, a[j], w, 1);    
    }  
    else {
      sub = solve (j, z, a[j], 0);  
    }
    if (min == -1 || min > sub) {
      min = sub;  
    }
    if (max < sub) {
      max = sub;  
    }
  }
  if (part == 0) {
    return max;    
  }
  return min;
}

int main () {
  ll z, w;
  cin >> n >> z >> w;
  a[0] = 0;
  for (ll i = 1; i <= n; i++) {
    cin >> a[i];  
  }    
  // all とる時
  int all = abc(a[n], w);
  // all 手前
  int sub = -1;
  if (n > 1) {
    sub = abc(a[n - 1], a[n]);    
  }
  if (all > sub) {
    cout << all << endl;  
  }
  else {
    cout << sub << endl;  
  }
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <sstream>
#include <cmath>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>

using namespace std;

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

int main(){

	double eps = 10e-7;
	double xA,yA,xB,yB,xC,yC,xD,yD;
	while(~scanf("%lf %lf %lf %lf %lf %lf %lf %lf",
		&xA,&yA,&xB,&yB,&xC,&yC,&xD,&yD)){
			if((xB-xA)*(xD-xC)+(yB-yA)*(yD-yC) == 0){
				cout << "YES" << endl;
			}else{
				cout << "NO" << endl;
			}
	}
}

Measured memory_bytes: 0
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include <vector>
#include <map>

using namespace std;
using ll = long long int;

template <class T> ostream &operator<<(ostream &os, vector<T> &v) {
  for (auto i = v.begin(); i != v.end(); i++) {
    os << *i << " ";
  }
  return os;
}

ll gcd(ll a, ll b) {
  ll tmp;
  if ( b > a) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while (a % b !=0) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}

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

int main(void) {
  int n, m;
  cin>>n>>m;
  int e[10][10];
  for(int i=0; i<10; i++) {
    for(int j=0; j<10; j++) {
      e[i][j] = 0;
    }
  }
  for(int i=0; i<m; i++) {
    int x, y;
    cin>>x>>y;
    e[x][y] = 1;
    e[y][x]= 1;
  }
  vector<int> v;
  for(int i=2; i<=n; i++) {
    v.push_back(i);
  }
  int cnt=0;
  do {
    int prev = 1;
    bool f = true;
    for(auto &it : v) {
      if(!e[prev][it]) {
	f = false;
	break;
      }
      prev = it;
    }
    if(f)
      cnt++;
  }while(next_permutation(v.begin(), v.end()));
  std::cout << cnt << std::endl;
  return 0;
}



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

const int MAXN = 55;
char G[MAXN][MAXN];

int dir[8][2] = {0,1, 1,0, 0,-1, -1,0 ,1,1, -1,-1, -1,1, 1,-1};

int main()
{
    int h,w,cnt;
    int x,y;
    scanf("%d %d",&h,&w);
    for(int i = 0 ; i < h; ++i)
        scanf("%s",&G[i]);

    for(int i = 0; i < h; ++i)
    {
        for(int j = 0; j < w; ++j)
        {
            if(G[i][j] == '#')
                continue;
            cnt = 0;
            for(int k = 0; k < 8; ++k)
            {
                x = i + dir[k][0];
                y = j + dir[k][1];
                if(x < 0 || y < 0 || x > h || y > w)
                    continue;
                if(G[x][y] == '#')
                    ++cnt;
            }
            G[i][j] = '0'+cnt;
        }
    }

    for(int i = 0; i < h; ++i)
        puts(G[i]);
    return 0;
}


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

int main()
{
	std::string s[3];
	for (int i = 0; i < 3; i++)
		std::cin >> s[i];
	unsigned int i[3]{};
	int turn{};
	while (i[turn] != s[turn].size())
	{
		int next{s[turn][i[turn]] - 'a'};
		i[turn]++;
		turn = next;
	}
	printf("%c\n", turn + 'A');

	return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.math.*;
import java.util.*;
import java.util.stream.*;

class Main {
    static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    static final PrintWriter pw = new PrintWriter(System.out);

    public static void main(String[] args) throws IOException {
        int num = Integer.parseInt(br.readLine());
        String[] inputs = br.readLine().split(" ");
        int[] nums = new int[num];
        int min = 101, max = 0;
        for (int i = 0; i < num; i++) {
            nums[i] = Integer.parseInt(inputs[i]);
            max = max > nums[i] ? max : nums[i];
            min = min < nums[i] ? min : nums[i];
        }

        int ans = 1000001;
        for (int i = min; i <= max; i++) {
            int sum = 0;
            for (int j = 0; j < num; j++) {
                int diff = nums[j] - i;
                sum += diff * diff;
            }
            ans = sum > ans ? ans : sum;
        }

        pw.println(ans);
        pw.flush();
    }
}

Measured memory_bytes: 21204