akhauriyash/Code-Regression huggingface dataset:
n,k = map(int,input().split())
R,S,P = map(int,input().split())
t = input()
mod = []
for i in range(k):
    mod.append(t[i::k])
ans = 0
for i in range(k):
    lis = mod[i]
    dp = [0]*(len(lis)+1)
    if lis[0]=='r':
        dp[1] = P
    elif lis[0]=='p':
        dp[1] = S
    elif lis[0]=='s':
        dp[1] = R
    for j in range(1,len(lis)):
        if lis[j]=='r':
            dp[j+1] = P+dp[j]
        elif lis[j]=='p':
            dp[j+1] = S+dp[j]
        elif lis[j]=='s':
            dp[j+1] = R+dp[j]
        if lis[j-1] == lis[j]:
            dp[j+1] = dp[j]
            if j != len(lis)-1:
                lis = lis[:j]+'o'+lis[j+1:]
    ans += dp[-1]
print(ans)

Measured memory_bytes: 8828
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String stringN = sc.next();
    int N = Integer.parseInt(stringN);
    int sN = 0;
    for (int i = 0; i < stringN.length(); i++) {
      sN += Character.getNumericValue(stringN.charAt(i));
    }
    if (N % sN == 0) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 22356
def bfs(n,e,fordfs):
    #点の数、スタートの点、有向グラフ
    W = [-1]*n
    #各点の状態量、最短距離とか,見たかどうかとか
    W[e] = 0
    que = deque()
    que.append(e)
    len = [float("inf")]*n
    len[e] = 0
    while que:
        now = que.popleft()
        nowv = W[now]
        nowlen = len[now]
        for ne in fordfs[now]:
#            if nowv == W[ne]:
                #ループが嫌な時
#                return -1
            if W[ne] == -1:
                W[ne] = (nowv+1) % 2
                len[ne] = nowlen+1
                que.append(ne)
    return len
def examC(inf):
    N, M = LI()
    ab = [[] for i in range(M)]
    for i in range(M):
        ab[i] = LI()
    cur = 0
    for i in range(M):
        v = [[] for i in range(N)]
        for j in range(M):
            if j!=i:
                v[ab[j][0] - 1].append(ab[j][1] - 1)
                v[ab[j][1] - 1].append(ab[j][0] - 1)
        B  = bfs(N,0,v)
#        print(B)
        if inf in B:
            cur +=1
    print(cur)

import sys,copy,bisect,itertools
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC(inf)


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

int main()
{
    int n, m;
    while (cin >> n >> m)
    {
        if(n == 0&&m == 0)return 0;
        int cnt = 0, c, s, t;
        vector<int> f(501);
        vector<vector<int>> v(501);
        for (int i = 0; i < m; i++)
        {
            cin >> s >> t;
            v[s].push_back(t);
            v[t].push_back(s);
        }
        for (int i = 0; i < v[1].size(); i++)
        {
            f[v[1][i]] = 1;
            int l = v[1][i];
            for (int j = 0; j < v[l].size(); j++)
                f[v[l][j]] = 1;
        }
        for (int i = 2; i <= n; i++)
            if (f[i] == 1)
                cnt++;
        cout << cnt << endl;
    }
}


Measured memory_bytes: 3160
a,b,c,d = map(int,input().split())

if a%d == 0:
    if c-b*(a/d) <= 0:
        print('Yes')
    else:
        print('No')
else:
    if c-b*(a//d+1) <= 0:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 61780
use std::io;

fn main() {
    loop {
        let mut line = String::new();
        io::stdin().read_line(&mut line).ok();

        let mut iter = line.split_whitespace().map(|w| w.parse::<i32>().unwrap());
        let h = iter.next().unwrap();
        let w = iter.next().unwrap();

        if h == 0 && w == 0 { break; }

        for i in 0..h {
            for j in 0..w {
                if i == 0 || i == h-1 || j == 0 || j == w-1 {
                    print!("#");
                } else {
                    print!(".");
                }
            }
            println!("");
        }
        println!("");
    }
}



Measured memory_bytes: 5016
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
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; }
//V,P(大文字)使用不可

const ll INF=1000000000000000000;

signed main(){
    ll a,b,k;
    cin>>a>>b>>k;
    ll cnt=min(a,k);
    a-=cnt;
    k-=cnt;
    if(k>0){
        cnt=min(b,k);
        b-=cnt;
    }
    cout<<a<<' '<<b<<endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <climits>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <map>
#include <tuple>
#include <iostream>
#include <deque>
#include <array>
#include <set>
#include <functional>
#include <memory>
#include <stack>

struct Point3 {
	int x, y, z;
};
struct Point2 {
	int x, y;
	bool operator<(const Point2 other) const { return x < other.x; }
};
class NonChainablePoints {
	std::set<Point2> set;
public:
	NonChainablePoints() {};
	bool can_chain(const Point2& point) const {
		auto hint = set.lower_bound(point);
		return hint != set.begin() && (--hint)->y < point.y;
	}
	void insert(const Point2& point) {
		auto hint = set.lower_bound(point);
		if (hint == set.end() || hint->x != point.x || hint->y >= point.y) {
			while (hint != set.end() && hint->y >= point.y) hint = set.erase(hint);
			set.insert(point);
		}
	}
	bool is_empty() const { return set.empty(); }
	bool is_not_empty() const { return !is_empty(); }
};
int r(int& a, int& b) {
	constexpr int C = ~(1 << 31);
	constexpr int M = (1 << 16) - 1;
	a = 36969 * (a & M) + (a >> 16);
	b = 18000 * (b & M) + (b >> 16);
	return (C & ((a << 16) + b)) % 1000000;
}
void append_points(std::vector<Point3>& points, int a, int b, const int n) {
	for (auto i = 0; i < n; ++i) {
		Point3 p;
		p.x = r(a, b);
		p.y = r(a, b);
		p.z = r(a, b);
		points.push_back(p);
	}
}
int solve(const int m, const int n, const int a, const int b) {
	std::vector<Point3> points(m);
	for (auto& p : points) std::cin >> p.x >> p.y >> p.z;
	append_points(points, a, b, n);
	std::sort(points.begin(), points.end(), [](const Point3& a, const Point3& b) {return (a.z == b.z) ? a.x > b.x : a.z < b.z; });
	std::vector<NonChainablePoints> sets(m + n);
	for (const auto point : points) {
		const Point2 p{ point.x, point.y };
		auto left = 0;
		auto right = sets.size();
		while (left < right) {
			auto mid = (left + right) / 2;
			if (sets[mid].can_chain(p)) left = mid + 1;
			else right = mid;
		}
		sets[right].insert(p);
	}
	for (auto i = 0; i < sets.size(); ++i) {
		if (sets[i].is_empty()) return i;
	}
	return sets.size();
}
int main() {
	std::vector<int>result;
	while (true) {
		int m, n, a, b;
		std::cin >> m >> n >> a >> b;
		if (m == 0 && n == 0) break;
		result.push_back(solve(m, n, a, b));
	}
	for (const auto r : result) std::cout << r << '\n';
}


Measured memory_bytes: 26876
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b;
    cin >> a >> b;
    if(a<b){
        for(int i=0;i<b;i++)cout << a;
    }
    else{
        for(int i=0;i<a;i++)cout << b;
    }
}

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

int main() {
    long int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    const long int dx = tx - sx, dy = ty - sy;
    cout << string(dy, 'U') << string(dx, 'R');
    cout << string(dy, 'D') << string(dx, 'L');
    cout << 'L' <<  string(dy + 1, 'U') << string(dx + 1, 'R') << 'D';
    cout << 'R' <<  string(dy + 1, 'D') << string(dx + 1, 'L') << 'U' << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#pragma warning(disable:4996)

using namespace std;

int main() {
	int a, b, h;
	scanf("%d", &a);
	scanf("%d", &b);
	scanf("%d", &h);
	printf("%d", (a+b)*h / 2);

	return 0;
}

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

int main(){
  int n;
  cin >> n;
  string c;
  cin >> c;
  int ri = n-1;
  for(int i=n-1;i>=0;i--){
    if(c[i]=='W')ri--;
    else break;
  }
  int li = 0;
  for(int i=0;i<n;i++){
    if(c[i]=='R')li++;
    else break;
  }
  int ans = 0;
  while(li<ri){
    if(c[li]=='W' && c[ri]=='R')ans++;
    li++;ri--;
    while(c[li]=='R')li++;
    while(c[ri]=='W')ri--;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3748
#include <cstdio>
#include <algorithm>
using namespace std;
int N;
int a[300003];
long long int ans;
int main(){
  scanf("%d",&N);
  for(int i=0;i<3*N;i++)scanf("%d",&a[i]);
  sort(a,a+3*N);
  for(int i=N;i<3*N;i+=2)ans+=a[i];
  printf("%lld\n",ans);
  return 0;
}


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

typedef long long int ll;
typedef pair<ll, ll> p_ll;
typedef vector<pair<ll, ll>> vec_p; //vector<pair<ll, ll>> pairs(n) ,pairs.at(i) = make_pair(i*i, i)

#define ture ture
#define flase false
#define falg flag

#define REP(i, x) for (ll i = 0; i < (ll)(x); i++)
#define REPS(i, x) for (ll i = 1; i <= (ll)(x); i++)
#define RREP(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (ll i = ((ll)(x)); i > 0; i--)
#define all(x) (x).begin(), (x).end()

const ll MOD = pow(10, 9) + 7;
const ll LLINF = pow(2, 61) - 1;//llの最大9*10^18
const int INF = pow(2, 30) - 1;

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

ll ans = 0;
ll S;



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

  
    //string S;
    cin >> S;

    if(S<=2){
        cout << 0 << endl;
    }
    else{
        vector<ll> vec(2000 + 1);
        REPS(i, S)
        {
            vec.at(i) = 0;
        }

        vec.at(3) = 1;
        vec.at(4) = 1;
        vec.at(5) = 1;
        vec.at(6) = 2;
        if(S>=7){
            for (ll i = 7; i <= S; i++)
            {
                for (ll j = 3; j <= (i - 3); j++)
                {
                    vec.at(i) += vec.at(j);
                    vec.at(i) %= MOD;
                }
                vec.at(i)++;
                vec.at(i) %= MOD;
            }
        }


        cout << vec.at(S)%MOD << endl;
    }



}


Measured memory_bytes: 3664
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define pb push_back
#define eb emplace_back
#define mpr make_pair
#define fi first
#define se second
using ll=long long int;
static const ll mod = 1e9 + 7;
static const ll INF = 1LL << 50;
using namespace std;

int main(){
	ll n;
	cin>>n;
	vector<ll>a(n+1),b(n+1);
	ll cnt=0;
	rep(i,n)cin>>a[i+1];
	for(int i=n;i>=1;--i){
		ll sum=0;
		for(int j=2;;++j){
			if(i*j>n)break;
			sum+=b[i*j];
		}
		if(sum%2==a[i])b[i]=0;
		else {
			b[i]=1;
			++cnt;
		}
	}
	cout<<cnt<<endl;
	rep(i,n){
		if(b[i+1]){
			cout<<i+1;
			--cnt;
			if(cnt)cout<<" ";
		}
	}
	cout<<endl;
		return 0;
}




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



int main() {
    string s;
    cin >> s;
    
    if(s.back() == 's') {
        cout << s << "es" << endl;
    }
    else {
        cout << s << "s" << endl;
    }

        
    
    
    return 0;
}




Measured memory_bytes: 3628
N = int(input())
town = [None]*N

for i in range(N):
    town[i] = list(map(int, input().split()))

avr_temp = 0
for i in range(N):
    for j in range(i+1, N):
        #町iから町jまでの距離を求める。
        avr_temp += ((town[i][0]-town[j][0])**2+(town[i][1]-town[j][1])**2)**0.5
avr = avr_temp * 2 / N
print(avr)

Measured memory_bytes: 3064
{-# LANGUAGE Strict #-}
import           Data.Vector.Unboxed ((!))
import qualified Data.Vector.Unboxed as V

main :: IO ()
main = do
  n <- readLn
  s <- getLine
  print $ solve n s

solve :: Int -> String -> Int
solve n s = rgb - a
  where s' = V.fromList s
        rgb = product $ map (\c -> count (== c) s) ['R', 'G', 'B']
        a = count
              (\(i, j, k) -> s' ! i /= s' ! j
                             && s' ! j /= s' ! k
                             && s' ! k /= s' ! i)
              [(i, j, k) | i <- [0 .. n - 3]
                       , j <- [i + 1 .. i + (n - 1 - i) `div` 2]
                       , let k = i + (j - i) * 2]

count :: (a -> Bool) -> [a] -> Int
count p = length . filter p


Measured memory_bytes: 4484
#include <algorithm>
#include <cstring>
#include <iostream>
#include <vector>
#include <cmath>
#include <math.h>
#include <stdio.h>
#include <iomanip>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <string>
#define rep(i,n) for (int i = 0; i < (n); ++i)

using namespace std;
const int MOD = 1000000007;


typedef long long int ll; 
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;

void floatOutPutSetup(){
    cout << fixed;
    cout << setprecision(10);
}

int main(){
    char c;
    cin >> c;
    cout << ++c ;

    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
	int n,a=0,b,ans=0;
	
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%d",&b);
		if(b>a)ans+=b-a;
		a=b;
	}
	printf("%d",ans);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define MAX 10010
int main(){
    int n;
    int x=-1;
    scanf("%d",&n);
    for(int i=3;i<=n;i++){
        
        if(i%3 == 0){
            printf(" %d",i);
        }else{
            x = i;
            do{
                if(x%10 ==3){
                    printf(" %d",i);
                    break;
                }
                x /=10;
            }while(x);
        } 
           
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define ss second
#define ff first
#define pb push_back
int main(){
    ios_base::sync_with_stdio(0);
    ll a,b,c;
    cin>>a>>b>>c;
    ll o=a,p=c,l=b;
    if(a>0&&c>0){

        a-=p;
        c-=o;
    }
    if(b>0&&c>0){
        b-=c;
    }
    if(a<0){
        cout<<0<<" ";
    }
    else{
        cout<<a<<" ";
    }
    if(b<0){
        cout<<0;
    }
    else {
        cout<<b;
    }
    return 0;
}



Measured memory_bytes: 256
fn main() {
    proconio::input! {
        n:usize
    }
    let mut ans = 0;
    //    let mut i = 1;
    let s = (n as f64).sqrt() as usize;

    for i in 1..s + 1 {
        let c = n / i;
        ans += i * c * (c + 1) / 2;
        // さらに、c について、いくつかまとめて計算。
        if c != i {
            let d = n / (i + 1);
            ans += (c * (c + 1) - d * (d + 1)) * i * (i + 1) / 4
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 2164
#include "bits/stdc++.h"
using namespace std;
int main(){
  string a,b;
  cin >> a >> b;
  if(a.size() > b.size()){
    cout << "GREATER";
  }else if(a.size() < b.size()){
    cout << "LESS";
  }else{
    for(int i=0;i<a.size();i++){
      if(a[i] > b[i]){
        cout << "GREATER";
        return 0;
      }else if(a[i] < b[i]){
        cout << "LESS";
        return 0;
      }
    }
    cout << "EQUAL";
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
#define F first
#define S second
#define pb push_back
#define mp make_pair 
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = n - 1; i>= 0; i--)
#define debug(x) cout << '>' << #x << ':' << x << endl;
#define sq(a) (a)*(a)
#define nl "\n"
using namespace std;
//using namespace __gnu_pbds;
//typedef tree<int,null_type,less<int>,rb_tree_tag,
//tree_order_statistics_node_update> indexed_set;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;
typedef vector<ll> vll;


const double pi = 3.14159265359;
const int MAXN = 100005;
ll mod=1000000007;

ll gcd(ll a, ll b){
	return b? gcd(b,a%b):a;
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	map<pair<ll,ll>,pair<ll,ll>> slope;
	int n;
	ll pw[2*MAXN]= {1};
	pw[0] = 1;
	for(int i = 1; i <= 2*MAXN - 1; i++) pw[i] = (pw[i-1]*2)%mod;
	cin>>n;
	
	ll z = mod-1;	
	rep(i,n){
		ll x,y;
		cin>>x>>y;
		if(x == 0 and y == 0){
		 	z++;continue;
		}
		if(make_pair(x,y) < make_pair(0ll,0ll)) x = -x, y = -y;
		ll g = gcd(abs(x),abs(y));
		x /= g, y /= g;		
		if(y <= 0) slope[{-y,x}].second++;
		else slope[{x,y}].first++;
	}
	ll r = 1;
	for(auto& p:slope){
		r = (r*(pw[p.second.first] + pw[p.second.second] - 1)%mod)%mod;	
	} 
	cout<<(r + z)%mod<<nl;
	
	return 0;
}



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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
from collections import deque
from fractions import gcd
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def inputI(): return int(input().strip())
def inputS(): return input().strip()
def inputIL(): return list(map(int,input().split()))
def inputSL(): return list(map(str,input().split()))
def inputILs(n): return list(int(input()) for _ in range(n))
def inputSLs(n): return list(input().strip() for _ in range(n))
def inputILL(n): return [list(map(int, input().split())) for _ in range(n)]
def inputSLL(n): return [list(map(str, input().split())) for _ in range(n)]

#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])
    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])
    return arr

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#############
# Main Code #
#############

N = inputI()

graph = [[] for _ in range(N)]
edges = []
 
for _ in range(N - 1):
  a, b = inputIL()
  edges.append((a-1, b-1))
  
for a, b in edges:
  graph[a].append(b)
  graph[b].append(a)
  
k = max(len(edges) for edges in graph)

colors = [color for color in range(1, k + 1)]
usedcolor = [ None for _ in range(N) ]
colored = {}

def youcanusethiscolor(u):
  for c in colors:
    if c == usedcolor[u]:
      continue
    yield c
    
for u in range(N):
  color = youcanusethiscolor(u)
  for v in graph[u]:
    if (u,v) not in colored and (v,u) not in colored:
      now = next(color)
      colored[(u,v)] = colored[(v,u)] = now
      usedcolor[v] = now
  
print(k)
for a,b in edges:
  print(colored[(a,b)])

Measured memory_bytes: 124204
#include <iostream>
using namespace std;
int n, t, ansC = (1<<20);
int main () {
    cin >> n >> t;
    for ( int i = 0 ; i < n ; i ++ ) {
        int c, tt;
        cin >> c >> tt;
        if ( tt <= t ) {
            ansC = min( c, ansC );
        }
    }
    if ( ansC == (1<<20) ) {
        cout << "TLE\n";
        return 0;
    }
    cout << ansC << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define cool ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int  long long int
#define pb push_back
#define fe first
#define se second
#define endl "\n"
#define pii pair<int, int>

#define PI 3.14159265358979323846
const int N = 5e3 + 10;
const int INF=2e9;

int MOD=1e9+7;	
int n;
int h[30];

void solve() {
  cin>>n;
  string s;
  cin>>s;
  int len=s.size();
  for(int i=0;i<len;i++) {
	   h[s[i]-'a']++;
	  }
	  int tot=1;
	  for(int i=0;i<=26;i++) {
		    tot=tot*(h[i]+1)%MOD;		  
		  }
		  
		   tot--;
		   
		 
		  
		  
		   
		   cout<<tot;		
}				   

int32_t main() {
  cool;
  int t = 1;
  while (t--)
	solve();

  return 0;
}


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

const char* s[5]={"","AC","WA","TLE","RE"};
int a[10],n;
char st[10];

int main() {
	scanf("%d",&n);
	a[1]=a[2]=a[3]=a[4]=0;
	for (int i=1;i<=n;++i) {
		scanf("%s",st);
		if (st[0]=='A') a[1]++;
		if (st[0]=='W') a[2]++;
		if (st[0]=='T') a[3]++;
		if (st[0]=='R') a[4]++;
	}
	for (int i=1;i<=4;++i) {
		printf("%s x %d\n",s[i],a[i]);
	}
}

Measured memory_bytes: 3840
#include <bits/stdc++.h>
#define N 100006
using namespace std;
long long n,m,x,y,s[4*N],f[4*N];
inline long long read()
{
	long long x=0,c=getchar();while(c<48)c=getchar();
	while(c>47)x=x*10+c-48,c=getchar();return x;
}
inline void down(long long i,long long l,long long r)
{
	if(f[i]){
		if(l!=r)f[i<<1]=f[i<<1|1]=f[i];
		s[i]=f[i]*(r-l+1);f[i]=0;
	}
}
void cover(long long i,long long l,long long r,long long x,long long y,long long p)
{
	if(x>y)return;down(i,l,r);
	if(x<=l&&r<=y){f[i]=p;return;}
	long long mid=(l+r)>>1;
	if(x<=mid)cover(i<<1,l,mid,x,y,p);
	if(y>mid)cover(i<<1|1,mid+1,r,x,y,p);
	down(i<<1,l,mid);down(i<<1|1,mid+1,r);
	s[i]=s[i<<1]+s[i<<1|1];
}
long long query(long long i,long long l,long long r,long long x,long long y)
{
	down(i,l,r);
	if(x<=l&&r<=y)return s[i];
	long long mid=(l+r)>>1,tmp=0;
	if(x<=mid)tmp=query(i<<1,l,mid,x,y);
	if(y>mid)tmp+=query(i<<1|1,mid+1,r,x,y);
	return tmp; 
}
inline long long find()
{
	long long l=1,r=x,ans;
	while(l<=r){
		long long mid=(l+r)>>1;
		if(query(1,1,n,mid,mid)*(x-mid+1)-query(1,1,n,mid,x)<=y)r=mid-1,ans=mid;
		else l=mid+1;
	}
	y-=(query(1,1,n,ans,ans)*(x-ans+1)-query(1,1,n,ans,x));
	return ans;
}
int main()
{
	n=read();m=read();
	while(m--){
		x=read();y=read();
		long long lmax=find(),cs=y/(x-lmax+1),res=y%(x-lmax+1);
		long long t=query(1,1,n,lmax,lmax);
		cover(1,1,n,lmax,lmax+res-1,t+cs+1);
		cover(1,1,n,lmax+res,x,t+cs);
	}
	for(long long i=1;i<=n;i++)printf("%lld\n",query(1,1,n,i,i));
}

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

int n, pos;
vector<int> pre, in, post;

void rec(int l, int r){
    if(l>=r) return;
    int root=pre[pos++];
    int m = distance(in.begin(),find(in.begin(), in.end(), root));
    rec(l,m);
    rec(m+1,r);
    post.push_back(root);
}

void solve(){
    pos=0;
    rec(0,pre.size());
    for(int i=0; i<n; i++){
        if( i )cout<<" ";
        cout << post[i];
    }
    cout <<endl;
}

int main(){
    int k;
    cin >> n;
    for(int i=0; i<n; i++){
        cin >> k;
        pre.push_back(k);
        
    }
    
    for(int i=0; i<n; i++){
        cin >> k;
        in.push_back(k);
    }
    
    solve();
    return 0;
}


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

using namespace std;
typedef long long int ll;
#define vll vector<ll>
#define vvll vector<vll>
#define mll map<ll,ll>
#define f(i,m,n) for(i=m;i<n;i++)
#define ee endl
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define take(v,n) for(i=0;i<n;i++) cin>>v[i];
#define NO() cout<<"NO"<<endl
#define YES() cout<<"YES"<<endl
#define fast ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define sot(v) sort(v.begin(),v.end());
bool isPrime(int n) 
{ 
    // Corner cases 
    if (n <= 1)  return false; 
    if (n <= 3)  return true; 
  
    // This is checked so that we can skip  
    // middle five numbers in below loop 
    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; 
}

void solve()
{
	ll i,j,k,l,n;
	cin>>n;
	n%=1000;
	cout<<(1000-n)%1000<<ee;
}


int main() {
    fast;
    ll i,j,l,k,t,n;
    //cin>>t;
    t=1;
    while(t--)
    solve();
}

Measured memory_bytes: 3608
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 A[] = new int[N];
		PriorityQueue<Integer> pq = new PriorityQueue<Integer>();
		for(int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
			pq.add(A[i]);
		}
		int B[][] = new int[M][2];
		for(int i = 0; i < M; i++) {
			B[i][0] = sc.nextInt();
			B[i][1] = sc.nextInt();
		}
		Arrays.sort(B, Comparator.comparingInt(o -> o[1]));
		
		for(int i = M - 1; i >= 0; i--) {
			for(int j = 0; j < B[i][0]; j++) {
				if(pq.peek() < B[i][1]) {
					pq.poll();
					pq.add(B[i][1]);
				} else {
					break;
				}
			}
		}
		long ans = 0;
		for(int i = 0; i < N; i++) {
			ans += pq.poll();
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 100688
#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <queue>
#include <string>
#include <unordered_map>
#include <vector>
using namespace std;

int main()
{
    int n, k;
    cin >> n >> k;
    int ans = INT32_MAX;
    vector<int> x(n);
    int y = -1;
    for (int i = 0; i < n; i++) {
        cin >> x[i];
        if (x[i] >= 0 && y == -1) y = i;
    }

    // any x[i] < 0
    if (y == -1) {
        cout << abs(x[n - k]) << endl;
        return 0;
    }
    // any x[i] >=0
    if (y == 0) {
        cout << abs(x[k - 1]) << endl;
        return 0;
    }

    for (int i = 0; i <= n - k; i++) {
        if (y <= i) {
            ans = min(ans, abs(x[i + k - 1] - x[i]) + abs(x[i]));
        } else if (y > i + k - 1) {
            ans = min(ans, abs(x[i + k - 1] - x[i]) + abs(x[i + k - 1]));
        } else {
            int tmpans = min(2 * abs(x[i]) + abs(x[i + k - 1]),
                             2 * abs(x[i + k - 1]) + abs(x[i]));
            ans = min(ans, tmpans);
        }
    }

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

Measured memory_bytes: 640
#include<stdio.h>
int main()
{
    int a, b;
    scanf("%d %d", &a, &b);
    int x = b;
    while (x > 0)
    {
        a *= 10;
        x /= 10;
    }
    a += b;
    x = 0;
    while (a > x*x)
        x++;
    if (a == x * x)
        printf("Yes\n");
    else
        printf("No\n");
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <cstdint>
#include <vector>

int main() {
    int n;
    std::cin >> n;
    
    int max = 0;
    int ans;

    for (int i = 1; i <= n; i++) {
        int cnt = 0;
        int num = i;
        for (; num % 2 == 0;) {
            cnt++;
            num /= 2;
        }

        if (max <= cnt) {
            max = cnt;
            ans = i;
        }
    }


    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 256
while l = gets do
  c = Array.new(14,0)
  l.split(",").map(&:to_i).each{|x| c[x]+=1}
  if c.member?(4)
    puts "four card"
  elsif c.member?(2)
    if c.member?(3)
      puts "full house"
    elsif c.index(2)!=c.rindex(2)
      puts "two pair"
    else puts "one pair"
    end
  elsif c.member?(3)
    puts "three card"
  elsif (t=c.join)=~/1{5}/ || t=~/010{8}1{4}/
    puts "straight"
  else
    puts "null"
  end
end

Measured memory_bytes: 6040
#include <iostream>
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define lli long long int
using namespace std;
#define S second
#define F first
#define pb push_back 
#define M1 1000000007
#define M2 998244353
#define plli pair<lli,lli>
#define setit set<lli>::iterator seti
#define mapit map<lli,lli> ::iterator mapi
#define MP make_pair
#define MT make_tuple
// map      iterator->first  iterator.first
// map      mp[key]=value
// set      *s.begin()
// vector   v[j]=value
// pair     p.first p.second
// vector of pairs v[j].first v[j].second
// tuple    get<index>(tuple_name)
// vector of tuples get<index>(v[j])  sort(v.begin(),v.end())
//priority queue .top() .pop() .push()
// __gcd(x,y)
#define fr(j,a,b) for(j=a;j<b;j++)

int power(int x, unsigned int y, int p)  
{    int res = 1;    
     x = x % p;
     if (x == 0) return 0;
     while (y > 0)  
     {  if (y & 1)  
        res = (res*x) % p;  
        y = y>>1;
        x = (x*x) % p;  
     }  
    return res;  
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    lli t,i,j,n,x,p,k,l,y;
    //cin>>t;
        cin>>n>>k;
        p=0;
        lli a[n+1];
        a[0]=0;
        vector<lli> b;
        map<lli,lli> mp;
        for(j=1;j<=n;j++){
            cin>>a[j];
        }
        l=1;
        for(j=1;;j++){
            b.push_back(a[l]);
            if(mp[a[l]]>0){
                x=j;
                y=mp[a[l]];
                break;
            }
            mp[a[l]]=j;
            l=a[l];
        }
        lli d=x-y;
        if(k<n-1){cout<<b[k-1];}
        else{
            k=y+((k-y)%d);
            cout<<b[k-1];
        }    
}

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

//solution:
signed main() {
    int k, n = 0; cin >> k;
    for(int i = 1; i <= k; ++i) {
      n = (10 * n % k + 7) % k;
      if(n == 0) {
        cout << i;
        exit(0);
      }
    }
    cout << -1;
    return 0;
} //farewell, until we meet again..

Measured memory_bytes: 3608
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <list>
#include <cmath>
#include <stack>
#include <string>
#include <cstring>
#include <numeric>
const int inf=1e9+7;
const int mod=1e9+7;
using namespace std;
//
int N;
int A[100001];
int a[100001];
int main(){
	cin>>N;
	int AA=0,aa=0;
	for(int i=0;i<N;i++){
		int num;
		cin>>num;
		if(i%2==0){
			AA++;
			A[num]++;
		}else{
			aa++;
			a[num]++;
		}
	}
	int maA=0,maa=0;
	int mA,ma;
	for(int i=0;i<=100000;i++){
		if(maA<A[i]){
			maA=A[i];
			mA=i;
		}
		if(maa<a[i]){
			maa=a[i];
			ma=i;
		}
	}
	sort(A,A+100001,greater<int>());
	sort(a,a+100001,greater<int>());
	if(mA==ma){
		cout<<min((AA-A[1])+(aa-a[0]),(AA-A[0])+(aa-a[1]))<<endl;
	}else{
		cout<<(AA-A[0])+(aa-a[0])<<endl;
	}
	return 0;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> x(n);
  for(int i=0; i < n; i++) cin >> x[i];
  int ans = pow(100, 2)*105;
  for(int p=0; p <= 100; p++) {
    int hp = 0;
    for(int i=0; i < n; i++) hp += pow(x[i]-p, 2);
    ans = min(ans, hp);
  }
  cout << ans << endl;
}


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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

const int INF=1001001001001001001ll;

int N;
int T[222];
int V[222];

int v[222222];

int dp[22222][111];
signed main(){
    cin>>N;
    rep(i,N)cin>>T[i];
    rep(i,N)cin>>V[i];
    rep(i,N)T[i+1]+=T[i];

    int X=T[N-1];
    rep(i,N){
        for(int j=(i?T[i-1]:0);j<T[i];j++)v[j]=V[i];
    }

    fill_n(*dp,22222*111,-INF);
    dp[0][0]=0;
    rep(i,X){
        rep(j,v[i]+1){
            chmax(dp[i+1][j],dp[i][j]+4*j);
            if(j+1<=v[i])chmax(dp[i+1][j+1],dp[i][j]+4*j+2);
            if(j+1<=v[i]){
                chmax(dp[i+1][j],dp[i][j]+4*j+1);
            }
            if(j)chmax(dp[i+1][j-1],dp[i][j]+4*j-2);
        }
    }

    printf("%.20f\n",dp[X][0]/4.0);
    return 0;
}


Measured memory_bytes: 20736
package main

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

func main() {
	n := getInt()

	m := make(map[int]int, 3)
	for i := 0; i < n; i++ {
		tmp := getInt()
		m[tmp]++
	}
	l := len(m)

	switch l {
	case 3:
		if n%3 != 0 {
			fmt.Println("No")
			return
		}
		ks := make([]int, 3)
		i := 0
		for k, v := range m {
			ks[i] = k
			i++
			if v != n/3 {
				fmt.Println("No")
				return
			}
		}
		if ks[0]^ks[2] != ks[1] || ks[1]^ks[0] != ks[2] || ks[2]^ks[1] != ks[0] {
			fmt.Println("No")
			return
		}
	case 2:
		if n%3 != 0 {
			fmt.Println("No")
			return
		}
		ks := make([]int, 2)
		vs := make([]int, 2)
		i := 0
		for k, v := range m {
			ks[i] = k
			vs[i] = v
			i++
		}
		if max(vs...) != min(vs...)*2 {
			fmt.Println("No")
			return
		}
		if vs[0] < vs[1] {
			if ks[0] != 0 {
				fmt.Println("No")
				return
			}
		} else {
			if ks[1] != 0 {
				fmt.Println("No")
				return
			}
		}

	case 1:
		for k := range m {
			if k != 0 {
				fmt.Println("No")
				return
			}
		}
	default:
		fmt.Println("No")
		return
	}

	fmt.Println("Yes")
}

func max(ns ...int) int {
	max := ns[0]
	for i := 1; i < len(ns); i++ {
		if max < ns[i] {
			max = ns[i]
		}
	}
	return max
}

func min(ns ...int) int {
	min := ns[0]
	for i := 1; i < len(ns); i++ {
		if min > ns[i] {
			min = ns[i]
		}
	}
	return min
}

// -----------------------------------------

var scanner = wordScanner()

func wordScanner() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	return sc
}

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

func getIntSlice(n int) []int {
	is := make([]int, n)
	for i := range is {
		is[i] = getInt()
	}
	return is
}

func getString() string {
	scanner.Scan()
	s := scanner.Text()
	return s
}


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

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


fac = [-1] * (10**6+1)
finv = [-1] * (10**6+1)
inv = [-1] * (10**6+1)

fac[0] = fac[1] = 1
finv[0] = finv[1] = 1
inv[1] = 1

def initNCMMod(limit):
    for i in range(2, limit):
        fac[i] = fac[i-1] * i % mod
        inv[i] = mod - inv[mod%i] * (mod // i) % mod
        finv[i] = finv[i-1] * inv[i] % mod
initNCMMod(10**5 + 3)
def NCMMod(n, k):
    if n < k:
        return 0
    if (n < 0 or k < 0):
        return 0
    return fac[n] * (finv[k] * finv[n-k] % mod) % mod

def main():
    N, K =LI()
    A = sorted(LI())
    m = A[0]
    if m < 0:
        for i in range(N):
            A[i] -= m
    arr = []
    cumA = [0] * (N+1)
    for i in range(N):
        A[i] %= mod
        cumA[i+1] = A[i] + cumA[i]
        cumA[i+1] %= mod
    ans = 0
    # [l, r) = A[l] + ... + A[r-1]
    if K >= 2:
        for d in range(K-2, N):
            ans += NCMMod(d, K-2) * (((cumA[N] - cumA[d+1]) % mod - (cumA[N-d-1] - cumA[0]) % mod)) % mod
            ans %= mod
    print(ans)

main()



Measured memory_bytes: 109164
s = input()
t = ''
for c in s:
    if c != 'x':
        t += c
if t[::-1] != t:
    print(-1)
    exit()
m = len(t)
l = [0] * (m + 1)
ind = 0
for c in s:
    if c == 'x':
        l[ind] += 1
    else:
        ind += 1
ans = 0
for i in range((m+1)//2):
    ans += abs(l[i] - l[-1-i])
print(ans)

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

typedef long long lint;

lint ans=0;
int a[200010],n;

int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++) scanf("%d",&a[i]);
	int cur=0,end=0;
	for(int start=0;start<n;start++){
		while(end<n&&(cur&a[end])==0){
			cur^=a[end];end++;
		}
		ans+=end-start;
		cur^=a[start];
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = LLONG_MAX;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(16);

	//cout << setprecision(10) << scientific << ans << endl;
}

signed main() {
	ll k, x;

	cin >> k >> x;

	ll s = x - k + 1;
	ll t = x + k;

	vector<ll> v;

	FOR(i, s, t) {
		v.push_back(i);
	}

	cout << v << endl;
}

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

int main() {
  ll N, K;
  cin >> N >> K;
  vector<ll> a(N);
  rep(i, N) cin >> a[i];
  ll l = 0, r = 1e9;
  while (r - l > 1) {
    ll x = (l + r) / 2;
    auto f = [&](ll x){
      ll now = 0;
      rep(i, N) now += (a[i] - 1) / x;
      return now <= K;
    };
    if (f(x)) r = x; else l = x;
  }
  
  cout << r << endl;
  return 0;
}


Measured memory_bytes: 4772
#include<bits/stdc++.h>
#define LL long long
#define maxn 100005
using namespace std;
int a[maxn];
void solve(int n)
{
	int mx=0,mn=n;
	for(int i=1;i<=n;i++)
	{
		mx=max(mx,a[i]);
		mn=min(mn,a[i]);
	}
	if(mx-mn>=2)
	{
		puts("No");
		return ;
	}
	if(mx==mn)
	{
		if(mx==n-1) puts("Yes");
		else if(mx*2<=n) puts("Yes");
		else puts("No");
		return ;
	}
	int cnt=0;
	for(int i=1;i<=n;i++)
		if(a[i]==mn) cnt++;
	if(cnt<mx&&2*(mx-cnt)+cnt<=n)
	{
		puts("Yes");
		return ;
	}
	puts("No");
	return ;
}
int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	solve(n);
}

Measured memory_bytes: 640
loop do
  w = gets.to_i
  @num ||= 1
  break if w==0
  n = gets.to_i
  dp = Array.new(n+1){ Array.new(w+1){ {v: 0, w: 0}}}
  n.times.map{ gets.split(",").map(&:to_i) }.each_with_index do |(vi,wi), i|
    w.times do |j|
      t = dp[i][[j+1-wi,0].max]
      dp[i+1][j+1] = if j+1>=wi && t[:v]+vi >= dp[i][j+1][:v]
        if t[:v]+vi==dp[i][j+1][:v]
          t[:w]+wi<dp[i][j+1][:w] ? {v: t[:v]+vi, w: t[:w]+wi} : dp[i][j+1]
        else
          {v: t[:v]+vi, w: t[:w]+wi}
        end
      else
        dp[i][j+1]
      end
    end
  end
  puts "Case #{@num}:"
  puts dp[n][w][:v]
  puts dp[n][w][:w]
  @num += 1
end

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

int main() {
    int N, M;
    while (cin >> N >> M, N || M) {
        vector<int> v(N), m(N);
        for (int i = 0; i < M; i++) {
            int s, k;
            cin >> s >> k;
            if (k == 1) {
                int t;
                cin >> t;
                v[t-1] += s;
                m[t-1] += s;
            } else {
                for (int j = 0; j < k; j++) {
                    int t;
                    cin >> t;
                    v[t-1] += s;
                }
            }
        }

        int first = -1, second = -1, idx, idy;
        for (int i = 0; i < N; i++) {
            if (first < v[i]) {
                second = first;
                idy = idx;
                first = v[i];
                idx = i;
            } else if (second < v[i]) {
                second = v[i];
                idy = i;
            }
        }

        int ans = 0;
        for (int i = 0; i < N; i++) {
            if (idx == i) {
                ans = max(ans, second - m[i]);
            } else {
                ans = max(ans, first - m[i]);
            }
        }

        cout << ans+1 << endl;
    }

    return 0;
}

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



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

    int H, W;
    cin >> H >> W;
    vector<vector<int>> aij(H, vector<int>(W));
    vector<vector<int>> bij(H, vector<int>(W));
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            int a;
            cin >> a;
            aij.at(i).at(j) = a; 
        }
    }
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            int b;
            cin >> b;
            bij.at(i).at(j) = b;
        }
    }
    vector<vector<vector<bool>>> dp(H, vector<vector<bool>>(W, vector<bool>(6401, false)));
    dp.at(0).at(0).at(abs(aij.at(0).at(0) - bij.at(0).at(0))) = true;
    for(int i = 1; i < H + W - 1; i++){
        int currentH = i + 1;
        int currentW = -1;
        while(currentH >= 0){
            currentH--;
            currentW++;
            if(currentH >= H || currentH < 0 
            || currentW >= W || currentW < 0){
                continue;
            }
            int ababs = abs(aij.at(currentH).at(currentW) - bij.at(currentH).at(currentW));
            for(int j = 0; j < min((i + 1) * 80 + 1, 6321); j++){
                if(currentH > 0){
                    dp.at(currentH).at(currentW).at(j) = dp.at(currentH).at(currentW).at(j) | dp.at(currentH - 1).at(currentW).at(abs(j - ababs));
                    dp.at(currentH).at(currentW).at(j) = dp.at(currentH).at(currentW).at(j) | dp.at(currentH - 1).at(currentW).at(j + ababs); 
                }
                if(currentW > 0){
                    dp.at(currentH).at(currentW).at(j) = dp.at(currentH).at(currentW).at(j) | dp.at(currentH).at(currentW - 1).at(abs(j - ababs)); 
                    dp.at(currentH).at(currentW).at(j) = dp.at(currentH).at(currentW).at(j) | dp.at(currentH).at(currentW - 1).at(j + ababs); 
                }
            }
        }
    }
    for(int i = 0; i < 81; i++){
        if(dp.at(H - 1).at(W - 1).at(i)){
            cout << i << endl;
            break;
        }
    }
    return 0;
}



Measured memory_bytes: 7808
X = int(input())

def Base_10_to_n(X, n):
    X = X-1
    alphabet = 'abcdefghijklmnopqrstuvwxyz'
    if (int((X)/n)):
        return Base_10_to_n(int(X/n), n)+alphabet[X%n]
    return alphabet[X%n]
print(Base_10_to_n(X, 26))

Measured memory_bytes: 61704
import java.util.*;
import static java.lang.Math.*;
import static java.util.Arrays.*;

public class Main {

	int INF = 1 << 28;
	int[] dx = {0,1,2,0,1,2,0,1,2};
	int[] dy = {0,0,0,1,1,1,2,2,2};
	int[] dz1 = {0,3,6,0,3,6,0,3,6};
	int[] dz2 = {0,0,0,3,3,3,6,6,6};
	void run() {
		Scanner sc = new Scanner(System.in);
		int n= sc.nextInt();
		for(int i=0;i<n;i++) {
			int[][] np = new int[9][9];
			boolean[][] fnp = new boolean[9][9];
			for(int j=0;j<9;j++) for(int k=0;k<9;k++) np[j][k] = sc.nextInt();
			for(int j=0;j<9;j++) for(int k=0;k<9;k++) for(int l=k+1;l<9;l++) {
				if( np[j][k] == np[j][l] ) fnp[j][k] = fnp[j][l] = true;
				if( np[k][j] == np[l][j] ) fnp[k][j] = fnp[l][j] = true;
				if( np[dz2[j]+dy[k]][dz1[j]+dx[k]] == np[dz2[j]+dy[l]][dz1[j]+dx[l]] )
					fnp[dz2[j]+dy[k]][dz1[j]+dx[k]] = fnp[dz2[j]+dy[l]][dz1[j]+dx[l]] = true;
			}
			for(int j=0;j<9;j++) {
				for(int k=0;k<9;k++) {
					if(fnp[j][k]) System.out.print("*");
					else System.out.print(" ");
					System.out.print(np[j][k]);
				}
				System.out.println();
			}
			if(i+1!=n)
			System.out.println();
		}
	}

	public static void main(String[] args) {
		new Main().run();
	}

	void debug(Object... os) {
		System.err.println(Arrays.deepToString(os));
	}
}

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

const int MAXN = 105;
int n, a[MAXN], d[MAXN], mx;

int main() {
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i], d[a[i]]++, mx = max(mx, a[i]);
	if (n == 2 && d[1] != 2)
		return cout << "Impossible", 0;
	if (mx % 2 == 1 && d[(mx + 1) / 2] != 2)
		return cout << "Impossible", 0;
	if (mx % 2 == 0 && d[mx / 2] != 1)
		return cout << "Impossible", 0;
	for (int i = mx / 2 + 1; i <= mx; i++)
		if (d[i] < 2)
			return cout << "Impossible", 0;
	int k;
	if (mx % 2 == 0)
		k = mx / 2;
	else
		k = (mx + 1) / 2;
	for (int i = 0; i < k; i++)
		if (d[i] > 0)
			return cout << "Impossible", 0;
	cout << "Possible";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define froop1(a,n) for(long long i = a;i < n;i++)
#define froop2(a,n) for(int i = a;i > n;i--)
int main(){
	long long N,M;
  cin >> N >> M;
  cout << N*(N - 1)/2 + M *(M - 1)/ 2 << endl;
  
 }

Measured memory_bytes: 3572
#include <stdio.h>
#include<stdlib.h>
#include<math.h>
//#include<strint.h>

int fact(int n){
  if(n==0){
    return 1;
  }
  else return n*fact(n-1);
}

int surv(int arr[],int n){
  int kazu=0;
  int i;
  for(i=0;i<n;i++){
    if(arr[i]==1){
      kazu++;
    }
  }
  return kazu;
}

int main(void)
{
  int n;
  scanf("%d",&n);
  int p[n],q[n],pi[n],qi[n];
  int i,j;
  int pno=0,qno=0;
  for(i=0;i<n;i++){
    scanf("%d",&p[i]);
    pi[i]=1;//一が存在する；
  }
  for(i=0;i<n;i++){
    scanf("%d",&q[i]);
    qi[i]=1;
  }
  for(i=0;i<n;i++){
    pno=pno+surv(pi,p[i])*fact(n-i-1);
    pi[p[i]-1]=0;
    //printf("fact=%d\n",fact(n-i-1));
    //printf("surv=%d\n",surv(pi,p[i]));
  }
  //printf("pno=%d\n",pno);
  for(i=0;i<n;i++){
    qno=qno+surv(qi,q[i])*fact(n-i-1);
    qi[q[i]-1]=0;
    //printf("fact=%d\n",fact(n-i-1));
    //printf("surv=%d\n",surv(qi,q[i]));
  }
    //printf("qno=%d\n",qno);

  if(qno>pno){
    printf("%d",qno-pno);
    return 0;
  }
  else{
    printf("%d",pno-qno);
  }





  return 0;
}


Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int N,C,p,z=0;
    cin>>N>>C;
    
    for(int i=0;i<C;i++){
        cin>>p;
        z+=p;
    }
        if(z%(N+1)==0){
        cout<<z/(N+1)<<endl;
    }
    else if(z%(N+1)>0){
        cout<<z/(N+1)+1<<endl;
    }
    }




Measured memory_bytes: 3096
#include <iostream>
#include <vector>

using namespace std;


struct UnionFind {
    vector<long long> par, rank, cnt; // par[i]:iの親の番号,rank[r]:rを根とする木の高さ,cnt[r]:rを根とする木の要素数

    UnionFind(long long N){ //全て根として初期化
        for(long long i = 0; i < N; i++){
            par.push_back(i);
        }
        rank.assign(N, 0);
        cnt.assign(N, 1);
    }

    long long root(long long x){ // xの根を返す
        if(par[x] == x){
            return x;
        }
        
        return par[x] = root(par[x]);
    }

    void unite(long long x, long long y){ // xの木とyの木を併合
        long long rx = root(x); 
        long long ry = root(y);
        if(rx == ry){
            return;
        }
        
        if(rank[rx] < rank[ry]){
            par[rx] = ry;
            cnt[ry] += cnt[rx]; 
        }else{
            par[ry] = rx;
            cnt[rx] += cnt[ry];
            if(rank[x] == rank[y]){
                rank[rx] ++;
            }
        }
    }

    long long tsize(long long x){ //　xの木の要素数を返す
        long long rx = root(x);

        return cnt[rx];
    }

    bool same(long long x, long long y){ // xとyが同一の木に存在するかを返す
        long long rx = root(x);
        long long ry = root(y);

        return rx == ry;
    }
};


int main(){
    long long N, M;
    cin >> N >> M;
    vector<long long> a(M), b(M);
    for(long long i = 0; i < M; i++){
        cin >> a[i] >> b[i];
        a[i]--; b[i]--;
    }

    UnionFind tree(N);
    vector<long long> ans(M);
    ans[M-1] = (N*(N-1))/2;
    for (long long i = M-1; i >= 1; i--){
        long long as = tree.tsize(a[i]), bs = tree.tsize(b[i]);
        bool isCom = tree.same(a[i],b[i]);
        tree.unite(a[i],b[i]);
        long long us = tree.tsize(a[i]);
        ans[i-1] = ans[i] - (isCom ? 0 : (us*(us-1)-as*(as-1)-bs*(bs-1))/2);
    }

    for(long long i = 0; i < M; i++){
        cout << ans[i] << endl;
    }


    return 0;
}

Measured memory_bytes: 6132