akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    char c;
    cin >> c;
    char ans;
    if (c == 'A' || c == 'T') ans = 'A'^'T'^c;
    else ans = 'G'^'C'^c;
    cout << ans << endl;
}

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

#define int long long
#define ll long long
#define ffor(i,n) for(int i = 0;i < (n); ++i)
#define fro(i,j,n) for(int i = (j);i < (n); ++i)
#define all(v) v.begin(),v.end()
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int,int>
#define vpii vector<pii>
#define ff first
#define ss second
const int mod = 1e9 + 7;
int add(int a,int b){
	return (a + b)%mod;
}
int sub(int a,int b){
	return add(a,mod - 1);
}
int mul(int a,int b){
	return (a*b)%mod;
}
vi a,b,c,d;
vi seq;
int n,m,q,ans;

void solve(int idx,int val){
	if(idx == n){
		int cur = 0;
		for(int i = 0;i < q; ++i){
			if(seq[b[i]] - seq[a[i]] == c[i]){
				cur += d[i];
			}
		}
		ans = max(ans,cur);
	}else{
		for(int i = val;i <= m; ++i){
			seq.push_back(i);
			solve(idx + 1,i);
			seq.pop_back();
		}
	}
}
signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
    cin >> n >> m >> q;
    a = b = c = d = vi(q);
    ffor(i,q){
    	cin >> a[i] >> b[i] >> c[i] >> d[i];
    	--a[i],--b[i];
    }
    solve(0,1);
    cout << ans;
}

Measured memory_bytes: 3636
def knapsack(V,n):
    if n == -1:
        return V
    if (V,n) in OS_dict.keys():
        return OS_dict[(V,n)]
    elif V < cost[n]:
        r = knapsack(V,n-1)
        OS_dict[(V, n)] = r
        return r
    else:
        r = min(knapsack(V-cost[n],n)+value[n],knapsack(V,n-1)) 
        OS_dict[(V,n)] = r
        return r



N = int(input())
now = 9
cost = []
value = []
while now <= N:
    cost.append(now)
    now *= 9
now = 6
while now <= N:
    cost.append(now)
    now *= 6
for x in range(len(cost)):
    value.append(1)
OS_dict = {}
V = N
best = knapsack(V,len(cost)-1)
print(best)

Measured memory_bytes: 37320
#include<iostream>
using namespace std;
int main()
{
	int n,a,b,s=0,c;
	cin>>n>>a>>b;
	for(int i=1;i<=n;i++)
	{
		c=i%10+i/10%10+i/100%10+i/1000%10+i/10000%10;
		if(a<=c&&c<=b)s+=i;
	}
	cout<<s<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
using namespace std;
using ll = long long;
int main() {
	int K, S; cin >> K >> S;
	int ans = 0;
	for (int x = 0; x <= K; x++) {
		for (int y = 0; y <= K; y++) {
			int z = S - (x + y);
			if (0 <= z && z <= K) ans++;
		}
	}
	cout << ans << endl;
	//system("pause");
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define rer(i,l,n) for(int i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pii;

int main(){
	while(1){
		int a,ans=0;
		cin>>a;
		if(a==0) break;
		a=1000-a;
		while(1){
			if(a==0) break;
			if(a>=500) a-=500;
			else if(a>=100) a-=100;
			else if(a>=50) a-=50;
			else if(a>=10) a-=10;
			else if(a>=5) a-=5;
			else if(a>=1) a-=1;
			ans++;
		}
		o(ans);
	}
}

Measured memory_bytes: 1160
#include <iostream>

using namespace std;

int main() {
	int cards[4][13];
	int a, n, i, j;
	char ch;
	cin >> n;
	for (i = 0; i < 4; i++) {
		for (j = 0; j < 13; j++) {
			cards[i][j] = 0;
		}
	}
	for (i = 0; i < n; i++) {
		cin >> ch >> a;
		if (ch == 'S') {
			cards[0][a - 1] = 1;
		}
		else if (ch == 'H') {
			cards[1][a - 1] = 1;
		}
		else if (ch == 'C') {
			cards[2][a - 1] = 1;
		}
		else {
			cards[3][a - 1] = 1;
		}
	}
	for (i = 0; i < 4; i++) {
		for (j = 0; j < 13; j++) {
			if (cards[i][j] == 1) {
				continue;
			}
			if (i == 0) {
				cout << "S " << j + 1 << endl;
			}
			else if (i == 1) {
				cout << "H " << j + 1 << endl;
			}
			else if (i == 2) {
				cout << "C " << j + 1 << endl;
			}
			else {
				cout << "D " << j + 1 << endl;
			}
		}
	}

	return 0;
}


Measured memory_bytes: 3120
#include<iostream>
using namespace std;
main(void){
    int n,c=1;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)cin>>a[i];
    for(int i=0;i<n;){
        if(a[i]==2) {
        cout<<c;return 0;
        } else if(c>n){
            cout<<-1;return 0;
        }else{
         i=a[i]-1; c++;
        }
    }cout<<-1;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7  
using ll = long long; 
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;


int main(){
     int n,m;
     cin>>n>>m;
     vector<int>v(m);
     rep(i,n){
         int k;
         cin>>k;
         rep(i,k){
             int a;
             cin>>a;
             a--;
             v[a]++;
         }
     }
     int ans=0;
     rep(i,m){
         if(v[i]==n)ans++;
     }
     cout<<ans<<endl;
}

Measured memory_bytes: 256
N,M,K=map(int,input().split())
P=998244353

t,c=(M*pow(~-M,~-N,P)),1
for k in range(1,K+1):
  c=(c*(N-k)*pow(k,P-2,P))%P
  t=(t+M*c*pow(~-M,(~-N-k),P))%P
print(t%P)


Measured memory_bytes: 9148
C=[list(map(int,input().split())) for _ in range(3)]
for i in range(2):
    if not(C[0][i+1]-C[0][i] == C[1][i+1]-C[1][i] == C[2][i+1]-C[2][i]):
        print('No')
        exit()
    if not(C[i+1][0]-C[i][0] == C[i+1][1]-C[i][1] == C[i+1][2]-C[i][2]):
        print('No')
        exit()
print('Yes')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define ll long long int
#define Y printf("YES\n")
#define N printf("NO\n")
#define pi acos(-1)
#define pb push_back
#define fr first
#define sc second
#define srt(a) sort(a.begin(),a.end())
#define rev(a) reverse(a.begin(),a.end())
#define r0 return 0

using namespace std;

int main()
{
     string s,str;

     cin>>s;

     str=s;

     reverse(s.begin(),s.end());

     ll k=0;

     for(ll i=0;i<s.size();i++)
     {
         if(s[i]!=str[i])k++;
     }

     cout<<(k+1)/2<<endl;
}


Measured memory_bytes: 3580
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <math.h>
using namespace std;

int main(){
  int n;cin>>n;
  int h[n];
  for(int i=0;i<n;i++){
    cin>>h[i];
  }
  int ans=0;
  for(int i=0;i<n;i++){
    //bool型で初期化していく
    bool a=true;
    for(int j=0;j<i;j++){
      if(h[j]>h[i]){
        a=false;
        break;
    }
  }
    if(a) ans++;
  }
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
// ACM-ICPCà\I2007 A. ICPC ¾_Wv\tgEFA

#include <iostream>
#include <vector>

using namespace std;

int main(){
	int n;
	while(cin >> n, n){
		if(n==0) break;
		int m = 9999999, M = 0, sum = 0;
		for(int i=0;i<n;i++){
			int tmp; cin >> tmp;
			m = min(m,tmp);
			M = max(M,tmp);
			sum += tmp;
		}
		cout << (sum-m-M)/(n-2) << endl;
	}
}

Measured memory_bytes: 0
import bisect
# python template for atcoder1
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline


def solve2():
    N = int(input())
    L = list(map(int, input().split()))
    L = sorted(L)
    ans = 0
    for i in range(N):
        for j in range(i+1, N):
            min_sum = L[i]+L[j]
            more_than = bisect.bisect_left(L[j+1:], min_sum)
            ans += more_than
    print(ans)


solve2()


Measured memory_bytes: 52664
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 10000000000000000

template <typename T>
struct BIT{
	vector<T> v;
	int n;
	
	const T init_value = 0;
	
	BIT(int sz){
		n=sz+1;
		v.resize(n,init_value);
	}
	
	BIT(vector<T> &x){
		n=x.size()+1;
		v.resize(n,init_value);
		
		for(int i=0;i<x.size();i++){
			add(i,x[i]);
		}
		
	}

	void add(int x,T val){
		x++;
		while(x < n){
			v[x] = func(v[x],val);
			x += x & (-x);
		}
	}
	
	//区間[0,r)におけるクエリ処理
	T query(int r){
		T ret = init_value;
		
		while(r>0){
			ret = func(v[r],ret);
			r -= r & (-r);
		}
		
		return ret;
	}
	
	T query(int l,int r){
		return query(r) - query(l);
	}
	
	T func(T a,T b){
		return a+b;
	}
	
};

int main(){

	int N,Q;
	cin>>N>>Q;
	
	vector<int> c(N);
	for(int i=0;i<N;i++){
		cin>>c[i];
		c[i]--;
	}
	
	vector<vector<pair<int,int>>> q(N+1,vector<pair<int,int>>());
	
	for(int i=0;i<Q;i++){
		int l,r;
		cin>>l>>r;
		l--;r--;
		q[r].emplace_back(l,i);
	}
	
	BIT<int> B(N+5);
	
	vector<int> last(N,N);
	B.add(N,N);
	vector<int> ans(Q);
	for(int i=0;i<N;i++){
		B.add(last[c[i]],-1);
		B.add(i,1);
		last[c[i]]=i;
		
		for(int j=0;j<q[i].size();j++){
			ans[q[i][j].second] = B.query(q[i][j].first,i+1);
		}
	}
	
	for(int i=0;i<Q;i++){
		cout<<ans[i]<<endl;
	}
	
	
	return 0;
}

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

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

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

    if(a >= b && a >= c){
        printf("%d\n", a * 10 + b + c);
    }else if(b >= a && b >= c){
        printf("%d\n", b * 10 + a + c);
    }else if(c >= a && c >= b){
        printf("%d\n", c * 10 + a + b);
    }

    return 0;

} 



Measured memory_bytes: 256
package main

import (
	"bufio"
	_ "container/heap"
	"fmt"
	"os"
	_ "sort"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	return a / gcd(a, b) * b
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
const MOD = int(1e+9) + 7
const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	defer wtr.Flush()
	N, A, B := sc.nextInt(), sc.nextInt(), sc.nextInt()
	H := sc.nextIntSlice(N)
	f := func(num int) bool {
		total := 0
		for i := 0; i < N; i++ {
			rest := max(H[i]-num*B, 0)
			if rest > 0 {
				total += ceil(rest, A-B)
			}
		}
		return total <= num
	}
	l := 0
	r := int(1e+9)
	for abs(r-l) > 1 {
		mid := (r + l) / 2
		if f(mid) {
			r = mid
		} else {
			l = mid
		}
	}

	fmt.Fprintln(wtr, r)
}


Measured memory_bytes: 3072
import sys
from heapq import heappush, heappop, heapify
import math
from math import gcd
import itertools as it
import collections
from collections import deque 

input = sys.stdin.readline

def inp():
    return int(input())
def inpl():
    return list(map(int, input().split()))
def _debug(obj):
    print(obj, file=sys.stderr)

# ---------------------------------------

N, W = inpl()
INF = 10**12
dp = [[INF] * 100001 for i in range(N + 1)]
dp[0][0] = 0
for i in range(1, N + 1):
    w, v = inpl()
    for j in range(0, 100001):
        if j - v >= 0:
            dp[i][j] = min(dp[i-1][j], dp[i-1][j-v] + w)
        else:
            dp[i][j] = dp[i-1][j]
            
ans = 100000
while dp[N][ans] > W:
    ans -= 1

_debug(dp[N][ans])
print(ans)

Measured memory_bytes: 152492
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC126C
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] input = Console.ReadLine().Split().Select(int.Parse).ToArray();

            int N = input[0];
            int K = input[1];

            double ans = pre(N, K) / N;

            Console.WriteLine(ans);
            Console.ReadKey();
        }
        
        static double pre(int N, int K)
        {
            double ans = 0;
            if (K == 1) return 1;

            if (N >= K)
            {
                ans += N - K + 1;
                N = K - 1;
            }

            return ans + pre(N, (K+1) / 2) / 2.0;
        }

        //    if (K == 1) return 0;

        //        double ans = 0;
        //        if (N >= K) ans += (N - K + 1) * 2 / fixedN;

        //        int newK = K / 2;
        //        if (N >= newK)
        //        {
        //            double add = N - newK + 1;
        //    ans += add / fixedN;
        //            N = newK - 1;
        //        }

        //double ret = pre(N, newK) / 2.0;
        //Console.WriteLine(ret);
        //        return ans + ret;
    }
}


Measured memory_bytes: 13268
fn main(){
    let mut sc = Scanner::new();
    while sc.read() {
        let k = sc.next();
        let s = sc.next();
        let mut ans = 0;
        for i in 0..k+1 {
            for j in 0..k+1 {
                if i + j <= s  && s - i - j <= k {
                    ans += 1;
                }
            }
        }
        println!("{}", ans);
    }
}

#[allow(dead_code)]
struct Scanner {
    buf: Vec<u8>, i: usize, next: Option<String>,
}

#[allow(dead_code)]
impl Scanner {
    fn new() -> Scanner {
        Scanner { buf: vec![], i: 0, next: None, }
    }

    fn next<T: std::str::FromStr>(&mut self) -> T {
        self.wrapped::<T>().unwrap()
    }

    fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        let mut res = Vec::<T>::with_capacity(n);
        for _ in 0..n { res.push(self.next()) }
        res
    }

    fn wrapped<T: std::str::FromStr>(&mut self) -> Option<T> {
        self.read();
        self.next.take().and_then(|s| s.parse::<T>().ok())
    }

    fn read(&mut self) -> bool {
        if self.next.is_some() { return true }
        let mut s = String::with_capacity(16);
        while let Some(c) = self.get_char() {
            if !c.is_whitespace() { s.push(c); }
            else if !s.is_empty() { break; }
        }
        self.next = if !s.is_empty() { Some(s) } else { None };
        self.next.is_some()
    }

    fn get_char(&mut self) -> Option<char> {
        if self.i >= self.buf.len() {
            use std::io::BufRead;
            let reader = std::io::stdin();
            let mut buffer = reader.lock();
            let len = match buffer.fill_buf() {
                Ok(bytes) => {
                    self.buf.resize(bytes.len(), b'\0');
                    // self.buf.copy_from_slice(bytes); // AtCoderのRustには未実装
                    for i in 0..bytes.len() { self.buf[i] = bytes[i]; }
                    Some(bytes.len())
                },
                Err(_) => None,
            };
            self.i = 0;
            if len.is_some() { buffer.consume(len.unwrap()); }
            if len.is_none() || len.unwrap() == 0 { return None }
        }
        self.i += 1;
        Some(self.buf[self.i - 1] as char)
    }
}


Measured memory_bytes: 380
#include <bits/stdc++.h>
using namespace std;
int main()
{	
	int N , K;
	cin >> N >> K;
	vector<int> cannot(10);
	while(K--)
	{
		int D;
		cin >> D;
		cannot[D] = 1;
	}
	for(int i = N;; i++)
	{
		int j = i;
		bool bad = false;
		while(j)
		{
			int D = j % 10;
			bad |= cannot[D];
			j /= 10;
		}
		if(!bad)
		{
			cout << i;
			return 0;
		}
	}
	return 0;
}


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

#ifdef DEBUG
#define debug(x) cout << #x << ": " << x << endl
#else
#define debug(x)
#endif

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REPS(i, n) for(int i = 1; i <= (n); i++)
#define ALL(v) (v).begin(), (v).end()

#define pb push_back
#define mp make_pair
#define mt make_tuple

using namespace std;

using ll = long long;
using pi = pair<int, int>;
using pl = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;

const ll INF = 1e18;
const ll MOD = 1e9+7;

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


signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    string S, T; cin >> S >> T;
    if(S == T.substr(0, T.length()-1)) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3612
use std::collections::VecDeque;
fn main() {
    let (n, m) = {
        let a = getvec::<usize>();
        (a[0], a[1])
    };
    let mut stations = vec![vec![]; n];
    let mut edges = vec![];
    for _ in 0..m {
        let (p, q, c) = {
            let a = getvec::<usize>();
            (a[0] - 1, a[1] - 1, a[2] - 1)
        };
        stations[p].push(c);
        stations[q].push(c);
        edges.push((p, q, c));
    }
    let mut offset : Vec<usize>= vec![0; n + 1];
    offset[0] = n;
    for i in 0..n {
        stations[i].sort();
        stations[i].dedup();
        offset[i + 1] = offset[i] + stations[i].len();
    }
    let mut adj = vec![vec![]; offset[n]];
    for i in 0..n {
        for j in offset[i]..offset[i + 1] {
            adj[j].push(i);
        }
    }
    for &e in &edges {
        let (u, v, c) = e;
        let x = offset[u] + stations[u].binary_search(&c).unwrap();
        let y = offset[v] + stations[v].binary_search(&c).unwrap();
        adj[x].push(y);
        adj[y].push(x);
    }
    let inf = 1000000000;
    let mut dist = vec![inf; offset[n]];
    let mut deq : VecDeque<usize> = VecDeque::new();
    deq.push_back(0); dist[0] = 0;
    while let Some(u) = deq.pop_front() {
        if u < n {
            for v in offset[u]..offset[u + 1] {
                if dist[v] > dist[u] + 1 {
                    dist[v] = dist[u] + 1;
                    deq.push_back(v);
                }
            }
        }
        else {
            for &v in &adj[u] {
                if dist[v] > dist[u] {
                    dist[v] = dist[u];
                    deq.push_front(v);
                }
            }
        }
    }
    println!("{}", if dist[n - 1] == inf {-1} else {dist[n - 1]});
}

fn next_line() -> String {
    let mut input = String::new();
    std::io::stdin().read_line(&mut input).unwrap();
    input
}
 
#[allow(dead_code)]
fn getnum<T : std::str::FromStr>() -> T {
    let res = next_line();
    let res = res.trim().parse::<T>().ok().unwrap();
    res
}
 
#[allow(dead_code)]
fn getvec<T : std::str::FromStr>() -> Vec<T> {
    let res = next_line();
    let res : Vec<T> = res.split_whitespace().map(|x| x.parse::<T>().ok().unwrap()).collect();
    return res;
}

Measured memory_bytes: 42364
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const int INF = 1001001001;
const long long INFL = (1LL<<60);
const double eps = (1e-9);

ll mod = 1000000007;

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

  ll n;
  cin >> n;

  ll ans = 0;

  vector<ll> divisors;
  for (ll i = 1; i * i <= n; ++i) {
    if (n % i == 0) {
      divisors.push_back(i);
      if (i != n / i) {
        divisors.push_back(n / i);
      }
    }
  }

  for (auto& v : divisors) {
    ll m = v - 1;
    if (m <= 1) continue;
    if (n / m == n % m) {
      ans += m;
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
//using namespace boost::multiprecision;
typedef long long int ll;
typedef long double ld;
#define PI 3.141592653589793
#define MOD 1000000007
#define ALL(obj) (obj).begin(),(obj).end()
template<class T>inline bool chmax(T& a,T b){if (a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T& a,T b){if (a>b){a=b;return 1;}return 0;}
const ll INF = 1LL << 62;

//四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

struct edge{//グラフに使うヤツ
    ll from,to,cost;
};

typedef vector<vector<edge> > G;
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}

int main() {
    ll n,k;
    cin >> n >> k;
    ll p[n],c[n];
    for (ll i=0;i<n;i++){
        cin >> p[i];
        p[i]=p[i]-1;
    }
    for (ll i=0;i<n;i++){
        cin >> c[i];
    }
    ll point[n]; 
    ll v[n];
    fill(v,v+n,-INF);
    ll v2[n];
    fill(v2,v2+n,-INF);
    ll lc[n];
    for (ll i=0;i<n;i++){
        ll q=p[i],f=1,d=c[i];
        while (q!=i){
            d+=c[q];
            q=p[q];
            f++;
        }
        point[i]=d;
        lc[i]=f;
    }
    ll kc[n];
    fill(kc,kc+n,k);
    for (ll i=0;i<n;i++){
        ll z=(k%lc[i]);
        if (k%lc[i]==0){
            z=lc[i];
            kc[i]=kc[i]-lc[i];
        }
        ll d=0,q=p[i],f=1;
        while (f<=z){
            d+=c[q];
            q=p[q];
            v[i]=max(v[i],d);
            f++;
        }
        d=0;
        q=p[i];
        f=1;
        while (f<=lc[i]){
            d+=c[q];
            q=p[q];
            v2[i]=max(v2[i],d);
            f++;
        }
    }
    ll ans[n];
    fill(ans,ans+n,-INF);
    for (ll i=0;i<n;i++){
        if (point[i]>0){
            ans[i]=(point[i]*(kc[i]/lc[i]));
            ans[i]=max(max(ans[i],ans[i]-point[i]+v2[i]),ans[i]+v[i]);
        }else ans[i]=max(v[i],v2[i]);
    }
    sort(ans,ans+n);
    cout << ans[n-1] << endl;
    return 0;
}


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

int main() {
    int x;
    cin >> x;
    if (360 % x == 0) cout << 360 / x << endl;
    else {
        rep(i, x) {
            if (360 * (i+1) % x == 0) {
                cout << 360 * (i+1) / x << endl;
                break;
            }
        }
    }
}

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

class Main{
    public static void main(String args[])throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringBuilder sb = new StringBuilder();
        String s = br.readLine();	//?????????????????????????????????
        String p = br.readLine();	//?????????????????????????????????
        sb.append(s);				//sb?????????????????¨??????????????????????????¨??????????????????
        sb.append(s);
        if(sb.indexOf(p) != -1){
        	//??????????????????????±??????????????????????????????????????????????indexOf??§??????
        	//????±?????????????????????£?????´?????????-1??????????????§!=?????¶?????????
        	System.out.println("Yes");
        	//-1??\????????£??????Yes??????????????????
        }else{
        	System.out.println("No");
        	//-1?????£??????No??????????????????
        }
     }
}

Measured memory_bytes: 17048
#include <iostream>

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

   if((S[0]==S[1] && S[2]==S[3] && S[0]!=S[2]) ||
      (S[0]==S[2] && S[1]==S[3] && S[0]!=S[1]) ||
      (S[0]==S[3] && S[1]==S[2] && S[0]!=S[1]))
      std::cout << "Yes" << std::endl;
   else std::cout << "No" << std::endl;
   return 0;
}


Measured memory_bytes: 256
n, m, l = map(int, input().split())
a, b = [], []

for _ in range(n):
    a.append(list(map(int, input().split())))

for _ in range(m):
    b.append(list(map(int, input().split())))

for row in a:
    row_total = [0]*l
    for i, j in zip(row, b):
        row_total = list(map(lambda z: sum(z), zip(row_total, [i*k for k in j])))
    print(' '.join(map(str, row_total)))



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

int main() {
  int N;
  cin >> N;
  
  int D,U;
  D = N%1000;
  U = N/10;

  if (D%111 == 0 || U%111 == 0){
  cout << "Yes" << endl;
  }    
  else {
  cout << "No" << endl;
  }
} 

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

using namespace std;

template <class TH> void _dbg(const char *sdbg, TH h){cerr<<sdbg<<"="<<h<<"\n";}
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')
    cerr<<*sdbg++;
  cerr<<"="<<h<<","; 
  _dbg(sdbg+1, a...);
}

template<class T> ostream & operator<<(ostream & os, vector<T> V){
  os<<"[";
  for(auto vv: V) os << vv <<",";
  return os << "]";
}
template<class L, class R> ostream & operator <<(ostream & os, pair<L,R> P){
  return os <<"("<<P.first <<","<<P.second <<")";
}

#ifdef DEBUG
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

int main() {
    
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    swap(a, b);
    swap(a, c);
    printf("%d %d %d\n", a, b, c);
    return 0;
}


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

using namespace std;
typedef int64_t ll;
typedef uint64_t ull;
typedef long double ld;

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

	ll a, b;
	cin >> a >> b;
	cout << a*b/__gcd(a, b);

	cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << " ms.\n";
}

// g++ o .cpp -O2 -std=c++11 -D cute -Wall -Wno-unused-result



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <array>
#include <math.h>
#include <set>
#include <stdlib.h>
#include <string>
#include <vector>

#define INT_MAX 2000000000
#define MOD 1000000007
#define ll long long
#define rep(i,a,b) for(i = (a); i < (b); i++)
#define bitget(a,b) (((a) >> (b)) & 1)
#define vint vector<int>
#define vsort(x) sort(x.begin(),x.end())

using namespace std;

int main() {

	int i, j, k;
	int n;
	cin >> n;
	cout << "ABC" << n << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>

#ifdef WIN32
	#define LL "%I64d"
#else
	#define LL "%lld"
#endif

#ifdef CT
	#define debug(...) printf(__VA_ARGS__)
	#define setfile() 
#else
	#define debug(...)
	#define filename ""
	#define setfile() freopen(filename".in", "r", stdin); freopen(filename".out", "w", stdout)
#endif

#define R register
#define getc() (_S == _T && (_T = (_S = _B) + fread(_B, 1, 1 << 15, stdin), _S == _T) ? EOF : *_S++)
#define dmax(_a, _b) ((_a) > (_b) ? (_a) : (_b))
#define dmin(_a, _b) ((_a) < (_b) ? (_a) : (_b))
#define cmax(_a, _b) (_a < (_b) ? _a = (_b) : 0)
#define cmin(_a, _b) (_a > (_b) ? _a = (_b) : 0)
#define cabs(_x) ((_x) < 0 ? (- (_x)) : (_x))
char _B[1 << 15], *_S = _B, *_T = _B;
inline int F()
{
	R char ch; R int cnt = 0; R bool minus = 0;
	while (ch = getc(), (ch < '0' || ch > '9') && ch != '-') ;
	ch == '-' ? minus = 1 : cnt = ch - '0';
	while (ch = getc(), ch >= '0' && ch <= '9') cnt = cnt * 10 + ch - '0';
	return minus ? -cnt : cnt;
}
inline int qpow(R int base, R int power)
{
	R int ret = 1;
	for (R int i = 1; i <= power; ++i) ret = ret * base;
	return ret;
}
int main()
{
//	setfile();
	int n, k;
	scanf("%d%d", &n, &k);
	printf("%d\n", k * qpow(k - 1, n - 1) );
	return 0;
}


Measured memory_bytes: 128
package main

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

func main() {
	log.SetFlags(log.Lshortfile)
	nextReader = NewScanner()
	line1 := nextInt()
	A := line1[0]
	B := line1[1]

	if B%A == 0 {
		fmt.Println(A + B)
	} else {
		fmt.Println(B - A)
	}

}

// ------ Mathライブラリ ---------------------------------//
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}

func maxIdx(a ...int) int {
	r := a[0]
	index := 0
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
			index = i
		}
	}
	return index
}

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

func minIdx(a ...int) int {
	r := a[0]
	index := 0
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
			index = i
		}
	}
	return index
}

func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

// ------ Mathライブラリ ---------------------------------//

// ----- 標準入力用の関数 ----------------------------------//
var nextReader func() []string

func NewScanner() func() []string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	return func() []string {
		r.Scan()
		return strings.Fields(r.Text())
	}
}

func nextString() []string {
	return nextReader()
}

func nextInt() []int {
	var intArray []int
	strArray := nextReader()
	for _, v := range strArray {
		i, _ := strconv.Atoi(v)
		intArray = append(intArray, i)
	}
	return intArray
}

func nextFloat64() []float64 {
	var floatArray []float64
	strArray := nextReader()
	for _, v := range strArray {
		f, _ := strconv.ParseFloat(v, 64)
		floatArray = append(floatArray, f)
	}
	return floatArray
}

// ------ 標準入力用の関数 ---------------------------------//

// ------ あまり使わない -----------------------------------//
func nextInt64() []int64 {
	var int64Array []int64
	strArray := nextReader()
	for _, v := range strArray {
		i, _ := strconv.ParseInt(v, 10, 64)
		int64Array = append(int64Array, i)
	}
	return int64Array
}

// ------ あまり使わない -----------------------------------//


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <sstream>
#include <cstdlib>
#include <cmath>
 
using namespace std;

int main(){
    string str = "";
    cin >> str;
    reverse(str.begin(), str.end());
    cout << str << endl;
    return 0;
}

Measured memory_bytes: 1180
n=int(input())
a=list(map(int,input().split()))
dic={}
for i in range(len(a)):
    if a[i] not in dic:
        dic[a[i]]=1
    else:
        dic[a[i]]+=1

s=0
for t in dic.values():
    s+=t*(t-1)//2

for i in range(len(a)):
    p=dic[a[i]]
    print(s-p*(p-1)//2+(p-1)*(p-2)//2)

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

using ll = long long;

int N, Q;
vector<int> a(200000);
vector<int> b(200000);
vector<int> p(200001);
vector<int> x(200001);
vector<ll> ans(200001, 0);
vector<vector<int>> mt(200001);

void dfs(int idx = 1, int pidx = 0){
    ans[idx] += ans[pidx];
    for(int j = 0; j < mt[idx].size(); ++j){
        if(mt[idx][j] != pidx) dfs(mt[idx][j], idx);
    }
}

void solve(){
    for(int i = 1; i <= N - 1; ++i){
        mt[a[i]].push_back(b[i]);
        mt[b[i]].push_back(a[i]);
    }
    for(int i = 1; i <= Q; ++i){
        ans[p[i]] += x[i];
    }
    dfs();
    for(int i = 1; i <= N; ++i){
        cout << ans[i] << " ";
    }
}
int main(){
    cin >> N >> Q;
    for(int i = 1; i <= N - 1; ++i){
        cin >> a[i] >> b[i];
    }
    for(int i = 1; i <= Q; ++i){
        cin >> p[i] >> x[i];
    }
    solve();
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef double dd;
const int maxn=1;
ll n;
int ans=0x3f3f3f3f;

int work(int a,int b){
	int sum=0;
	while(a||b)
		sum+=a%10,sum+=b%10,a/=10,b/=10;
	return sum; 	
}
 
int main(){
	scanf("%lld",&n);
	for(int i=1;i<n;i++){
		int tt=n-i;
		ans=min(ans,work(i,tt));	
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using P = pair<int, int>;

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

  const int MAX = 1e5;
  vector<P> p1(MAX + 1, {0, 0});
  vector<P> p2(MAX + 1, {0, 0});
  for (int i = 0; i < n; i++) {
    if (i % 2) {
      p1[v[i]] = {p1[v[i]].first + 1, v[i]};
    } else {
      p2[v[i]] = {p2[v[i]].first + 1, v[i]};
    }
  }
  sort(begin(p1), end(p1), greater<P>());
  sort(begin(p2), end(p2), greater<P>());

  int ans;
  bool ok = (p1[0].second == p2[0].second);
  if (ok) {
    int d1 = p1[0].first + p2[1].first;
    int d2 = p2[0].first + p1[1].first;
    ans = n - max(d1, d2);
  } else {
    ans = n - p1[0].first - p2[0].first;
  }
  cout << ans << endl;

  return 0;
}


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

long long N, A[309][309];

int main() {
	cin >> N;
	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= N; j++) cin >> A[i][j];
	}
	long long sum = 0;
	for (int i = 1; i <= N; i++) {
		for (int j = i + 1; j <= N; j++) {
			int cnt = 0;
			for (int k = 1; k <= N; k++) {
				if (i == k || j == k) continue;
				if (A[i][k] + A[k][j] < A[i][j]) { cout << "-1" << endl; return 0; }
				if (A[i][k] + A[k][j] == A[i][j]) cnt++;
			}
			if (cnt == 0) sum += A[i][j];
		}
	}
	cout << sum << endl;
	return 0;
}

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

using namespace std;
typedef long long ll;
int main()
{
    ll q, h, s, d, a[4], minn, sum = 0;
    ll n;
    cin >> q >> h >> s >> d;
    cin >> n;
    int ok = 0;
    a[0] = 8 * q;
    a[1] = h * 4;
    a[2] = s * 2;
    a[3] = d;
    sort(a, a + 4);
    if (a[0] == d && (n & 1)) {
        sum = (n / 2) * a[0] + a[1] / 2;
    }
    else if (a[0] == d && !(n & 1))
        sum = (n / 2) * a[0];
    else
        sum = n * a[0] / 2;
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
S = list(input())
N = len(S)

def calc(T):
    N = len(T)
    t = 0
    ans = 0
    tmp = 0
    while T[t]!="=":
        if T[t]=="+":
            ans += tmp
            tmp = 0
            t+=1
            continue
        else:
            tmp = 10*tmp+int(T[t])
            t+=1
    ans += tmp
    return ans

from itertools import product
LS = list(product([0,1], repeat=N-1))
out = 0
for L in LS:
    T = S[0]
    for i in range(N-1):
        if L[i]==1:
            T += "+"+S[i+1]
        else:
            T += S[i+1]
    T += "="
    out += calc(T)
print(out)

Measured memory_bytes: 68260
n = int(input())
a = 0
w = 0
t = 0
r = 0
for i in range(n):
    s = input()
    if s == "AC":
        a+=1
    elif s == "WA":
        w+=1
    elif s == "TLE":
        t+=1
    elif s == "RE":
        r+=1
print("AC x " + str(a))
print("WA x " + str(w))
print("TLE x " + str(t))
print("RE x " + str(r))

Measured memory_bytes: 9208
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

int main(void){
    ll n, a, b, c, d;
    string s;
    cin >> n >> a >> b >> c >> d;
    cin >> s;
    a--;
    b--;
    c--;
    d--;

    rep(i, min(a, b), max(c, d) - 1){
        if(s[i] == '#' && s[i + 1] == '#'){
            cout <<  "No" << endl;
            return 0;
        }
    }

    if(c < d){
        cout << "Yes" << endl;
        return 0;
    }else{
        rep(i, b - 1, d){
            if(s[i] == '.' && s[i + 1] == '.' && s[i + 2] == '.'){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }

    cout << "No" << endl;

}


Measured memory_bytes: 640
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastScanner in = new FastScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int n = in.nextInt();
            int lastX = 0, lastY = 0, lastT = 0;
            for (int i = 0; i < n; i++) {
                int t = in.nextInt(), x = in.nextInt(), y = in.nextInt();
                int dist = Math.abs(x - lastX) + Math.abs(y - lastY);
                if (dist > t - lastT || dist % 2 != (t - lastT) % 2) {
                    out.println("No");
                    return;
                }
                lastX = x;
                lastY = y;
                lastT = t;
            }
            out.println("Yes");
        }

    }

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(InputStream in) {
            br = new BufferedReader(new InputStreamReader(in));
        }

        public String next() {
            while (st == null || !st.hasMoreElements()) {
                String line = null;
                try {
                    line = br.readLine();
                } catch (IOException e) {
                }
                st = new StringTokenizer(line);
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 41480
#include <bits/stdc++.h>
#define endl '\n'
#define fast ios::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define zy -2147382637
#define bql 2147483647
#define ll long long
#define ull unsigned long long
#define ld long double
#define il inline
#define sz(x) x.size()
#define maxn 100010
#define rp(i, l, r) for (int i = l; i <= r; i++)
#define rb(i, r, l) for (int i = r; i >= l; i--)
#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;
ll max(ll a,ll b){if(a>b)return a;else return b;}
ll min(ll a,ll b){if(a<b)return a;else return b;}
ll lowbit(ll x){return x&(-x);}
ll prime(ll x){
   if(x<=1)return false;
   for(int i=2;i<=int(sqrt(x));i++){
	   if(x%i==0)return false;
   }return true;
}
bool cmp(ll a,ll b){return a>b;}
ll gcd(ll a,ll b){ll r;while(b>0){r=a%b;a=b;b=r;}return a;}
ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
inline ll read() {
	char c = getchar(); ll w = 1; ll x = 0;
	while (!isdigit(c))
		(c == '-') && (w = -w), c = getchar();
	while (isdigit(c))
		x = (x << 1) + (x << 3) + (c ^ '0'), c = getchar();
	x *= w;
}
void fl(string name){
	freopen((name+".in").c_str(),"r",stdin);
	freopen((name+".out").c_str(),"w",stdout);
}
const int dx[8] = {-1, 1, 0, 0, -1, 1, -1, 1},
		dy[8] = {0, 0, -1, 1, -1, -1, 1, 1};
#define N 100010
ll f[N],w[N],v[N];
int main(){
	ll n,m;
	cin>>n>>m;
	for(int i=1;i<=n;i++)cin>>w[i]>>v[i];
	memset(f,bql,sizeof(f));
	f[0]=0;
	for(int i=1;i<=n;i++){
		for(int j=m;j>=w[i];j--){
			f[j]=max(f[j-w[i]]+v[i],f[j]);
		}
	}ll maxv=0;
	for(int i=0;i<=m;i++)maxv=max(maxv,f[i]);
	cout<<maxv<<endl;
	return 0;
}


Measured memory_bytes: 1024
local DBG = false
local function dbgpr(...)
    if DBG then
        io.write("[dbg]")
        print(...)
    end
end

local floor = math.floor

local function solve(M, K)
    local lim = floor(2^M) - 1
    if K > lim then
        print(-1)
        return
    end
    if K == 0 then
        local sb = {}
        for i=0,lim do
            table.insert(sb, i)
            table.insert(sb, i)
        end
        print(table.concat(sb, ' '))
        return
    end
    local len = floor(2^M) + 1
    local ans = {}
    table.insert(ans, K)
    local sum = K
    for i=lim,0,-1 do
        if i ~= K then
            table.insert(ans, i)
            sum = sum ~ i
        end
    end
    table.insert(ans, K)
    sum = sum ~ K
    if sum == K then
        dbgpr("OK")
    else
        dbgpr("NG")
        print(-1)
        return
    end
    for i=0,lim do
        if i ~= K then
            table.insert(ans, i)
        end
    end
    print(table.concat(ans, ' '))
end

local M,K = io.read("n", "n")
solve(M,K)


Measured memory_bytes: 15736
#include <cstdio>
#include <iostream>
#include <vector>
#include <list>
#include <cmath>
#include <fstream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <complex>
#include <iterator>
#include <cstdlib>
#include <cstring>
#include <sstream>

using namespace std;

#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) (EQ((a).real(),(b).real()) && EQ((a).imag(),(b).imag()))

typedef complex<double> P;
typedef pair<P,P> Edge;
typedef long long ll;

const double PI=4*atan(1.0);

//#define RED_FILE

#ifdef RED_FILE
ifstream ifs("input.txt");
ofstream ofs("output.txt");
#define cin ifs
#define cout ofs
#endif

map<char,map<int,int> > mcmii;
map<char,int> arraySize;

bool ok;

int rvalAnalysis(string s){
    bool isNum=true;
    for(int i = 0; i < s.size(); i++){
        if(!(s[i]>='0'&&s[i]<='9')){
            isNum=false;
            break;
        }
    }
    if(isNum){
        int num=atoi(s.c_str());
        return num;
    }
    char head=s[0];
    int idx=rvalAnalysis(s.substr(2,s.size()-3));
    if(arraySize.find(head)==arraySize.end()){
        ok=false;
        return 0;
    }
    if(mcmii.find(head)==mcmii.end()){
        ok=false;
        return 0;
    }
    if(mcmii[head].find(idx)==mcmii[head].end()){
        ok=false;
        return 0;
    }
    return mcmii[head][idx];
}

pair<char,int> lvalAnalysis(string s){
    // ツ参ツ湘嘉督渉環づーツパツーツズ
    char head=s[0];
    int idx=rvalAnalysis(s.substr(2,s.size()-3));
    return pair<char,int>(head,idx);
}


bool analysis(string s){
    for(int i = 0; i < s.size(); i++){
        // ツ妥」ツ禿シツ閉カ
        if(s[i]=='='){
            pair<char,int> l=lvalAnalysis(s.substr(0,i));
            int r=rvalAnalysis(s.substr(i+1));
            if(!ok)return false;
            if(arraySize.find(l.first)==arraySize.end())
                return false;
            else if(arraySize[l.first]<=l.second)
                return false;
            else{
                // ツ妥」ツ禿シ
                mcmii[l.first][l.second]=r;
                return true;
            }
        }
    }
    // ツ妥」ツ禿シツ閉カツづづ按つ「ツ湘ェツ債づ債、ツ静ゥツ個セ
    pair<char,int> info=lvalAnalysis(s);
    if(!ok)return false;
    if(arraySize.find(info.first)!=arraySize.end())return false;
    arraySize[info.first]=info.second;
    return true;
}

int main(){
    string first;
    while(cin>>first&&!(first==".")){
        vector<string> vs;
        vs.push_back(first);
        ok=true;
        mcmii.clear();
        arraySize.clear();
        string str;
        while(cin>>str&&!(str=="."))
            vs.push_back(str);
        for(int i = 0; i < vs.size(); i++){
            bool res=analysis(vs[i]);
            if(!res||!ok){
                cout<<i+1<<endl;
                ok=false;
                break;
            }
        }
        if(ok)cout<<0<<endl;
    }

    return 0;
}

Measured memory_bytes: 0
s = gets.chomp.split("")

n = s.size
sum = Array.new(n,0)

# 今の矢印を偶数ステップと奇数ステップで移動する子供の数
child = [1,0]
# 今見ている矢印の向き
tar = s[0]
# 同じ矢印が何個連続するか
cnt = 0
# 最後にRからLへ変化した位置
lastL = 0

for i in 2..n do
    if s[i-1] == tar
        cnt += 1
        child[cnt%2] += 1
    else
        if tar == "R"
            last = i-1
            sum[i-2] += child[0]
            sum[i-1] += child[1]
        else
            sum[last-1] += child[1]        
            sum[last] += child[0]
        end
        tar = s[i-1]
        cnt = 0
        child[0] = 1
        child[1] = 0
    end
end

sum[last] += child[0]
sum[last-1] += child[1]            

for i in 1..n do
    print sum[i-1]," "
end


Measured memory_bytes: 10492
from _collections import deque
from _ast import Num


def parser():
    while 1:
        data = list(input().split(' '))
        for number in data:
            if len(number) > 0:
                yield (number)


input_parser = parser()


def gw():
    global input_parser
    return next(input_parser)


def gi():
    data = gw()
    return int(data)


MOD = int(1e9 + 7)

import numpy
from collections import deque
from math import sqrt
from math import floor
# https://atcoder.jp/contests/abc114/tasks/abc114_c
# C - 755
"""
need to consider the case that ticket is not enough to lower everything
"""

S = gw()
T = gw()

lt = len(T)
ls = len(S)

found = 0
ans = S
for i in range(ls - lt, -1, -1):
    good = True
    for j in range(i, i + lt):
        good = S[j] == T[j - i] or S[j] == "?"
        if not good:
            break
    if good:
        found = 1
        ans = S[0:i] + T + S[i + lt:]
        break

if found:
    print(ans.replace("?", "a"))
else:
    print("UNRESTORABLE")


Measured memory_bytes: 13192
#include<iostream>

using namespace std;

typedef long long ll;

ll N, K;

int main() {
	cin >> N >> K;
	if (K % 2 == 0) {
		ll ans = 0;
		ans += (N / K)*(N / K)*(N / K);
		if (N % K >= K / 2) {
			ans += (N / K + 1)*(N / K + 1)*(N / K + 1);
		}
		else ans *= 2;
		cout << ans << endl;
	}
	else {
		ll ans = 0;
		ans += (N / K)*(N / K)*(N / K);
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 256
### SNIPPET
  # n = gets.split.map(&:to_i)
  # array = n.times.map { gets.split.map(&:to_i) }
  # [].all?(&:even?)
  # a = [*1..m].repeated_combination(n).to_a
  # [1,2,3,4,5].select { |num| num.even? }  # => [2, 4]
  # ["a","a","b"].group_by(&:itself).map{|k,v| [k, v.count]}.to_h #=> {"a"=>2, "b"=>1}
  # 切り捨て: .floor(2).to_f ,切り上げ： .ceil(2).to_f,四捨五入: round(2)
  # 3.upto(6) do |i|, 6.downto(3) do |i|
  # 公約数125.gcd(100)、公倍数125.lcm(100)
  # PI = Math::PI
  # 高さ = a * Math.sin(w / 180.0 * Math::PI), 底辺 = a * Math.cos(w / 180.0 * Math::PI)
  # def chmax(a, b) a > b ? a : b end
  # INF = Float::INFINITY
  # def chmin(a, b) a < b ? a : b end

n = gets.to_i
array = n.times.map { gets.chomp }

res = array.group_by(&:itself).map{|k,v| [k, v.count]}.to_h

res['AC'] = 0 if res['AC'] == nil
res['WA'] = 0 if res['WA'] == nil
res['TLE'] = 0 if res['TLE'] == nil
res['RE'] = 0 if res['RE'] == nil

puts "AC x #{res['AC']}"
puts "WA x #{res['WA']}"
puts "TLE x #{res['TLE']}"
puts "RE x #{res['RE']}"


Measured memory_bytes: 21684
#include <bits/stdc++.h>
#define LL long long
using namespace std;
const int N=2e6+1000;
const LL P=998244353;
int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
void print(int x){
    if(x>9) print(x/10);
    putchar(x%10+'0');
}
char s[1005],t[1005];
int main(){
	scanf("%s",s+1);int ls=strlen(s+1);
	scanf("%s",t+1);int lt=strlen(t+1);
	int ans=2000,now;
	for(int i=1;i<=ls;++i){
		if(i+lt-1<=ls) {
			now=0;
			for(int j=1;j<=lt;++j){
				if(s[i+j-1]!=t[j])++now;
			}
			ans=min(ans,now);
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3760