akhauriyash/Code-Regression huggingface dataset:
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let n: usize = iterator.next().unwrap().parse().unwrap();

    let mut vec: Vec<usize> = Vec::with_capacity(n);
    for _i in 0..n {
        vec.push(iterator.next().unwrap().parse().unwrap());
    }

    let mut ans = String::new();
    ans = format!("{}\n{}", ans, format(&vec));

    for i in 1..n {
        let v = vec[i];
        for j in (0..i).rev() {
            if vec[j] > v {
                vec[j + 1] = vec[j];
                vec[j] = v;
            } else {
                break;
            }
        }
        ans = format!("{}\n{}", ans, format(&vec));
    }

    return ans.trim().to_string();
}

fn format(vec: &Vec<usize>) -> String {
    let mut result = String::new();
    for v in vec {
        result = format!("{} {}", result, *v);
    }
    return result.trim().to_string();
}



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

int main(){
   char s[11];
 
   scanf("%s",s);
   if (strcmp(s,"hi")==0 || strcmp(s,"hihi")==0 || strcmp(s,"hihihi")==0 ||
       strcmp(s,"hihihihi")==0 || strcmp(s,"hihihihihi")==0) puts("Yes");
   else  puts("No");
   return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  long n;
  cin >> n;
  if(n % 11 > 6){
    cout << (n / 11) * 2 + 2 << endl;
  }
  else if(n % 11 > 0 && n % 11 <= 6){
    cout << (n / 11) * 2 + 1 << endl;
  }
  else{
    cout << (n / 11) * 2 << endl;
  }
}

Measured memory_bytes: 256
def fn(n):
  if n % 2 == 0:
    return n/2
  else:
    return 3*n + 1

s = int(input())
  
al = []
al.append(s)
cnum = s
for i in range(2,1000000):
  cnum = fn(cnum)
  if cnum in al[:-1]:
    print(i)
    exit()
  else:
    al.append(cnum)



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

typedef long long ll;

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

    int N, Q;
    string S;

    cin >> N >> Q >> S;

    int count = 0;

    vector<int> X(N);

    for(int i = 1; i < N; i++) {
        if(S[i] == 'C') {
            if(S[i - 1] == 'A') {
                count++;
            }
        }
        X[i] = count;
    }

    vector<int> l(Q);
    vector<int> r(Q);

    for(int i = 0; i < Q; i++) {
        cin >> l[i] >> r[i];
        l[i]--;
        r[i]--;
    }

    for(int i = 0; i < Q; i++) {
        cout << X[r[i]] - X[l[i]] << endl;
    }
}

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

ll f(ll b,ll n){
	if(n<b) return n;
	else return f(b,n/b)+n%b;
}

ll solve(ll n,ll s){
	if(n==s)return n+1;
	if(n<s)return -1;

	ll i=2;
	for(;i*i<=n;i++){
		if(f(i,n)==s)return i;
	}

	for(;i>0;i--){
		if((n-s)%i==0 && f((n-s)/i+1,n)==s){
			return (n-s)/i+1;
		}
	}

	return -1;
}

int main(void){
	ll n,s;
	cin>>n>>s;
	cout<<solve(n,s)<<endl;
	return 0;
}


Measured memory_bytes: 256
from math import factorial
N,M=map(int,input().split())
P=10**9+7

if N==M:
    print((2*((factorial(N))%P)*((factorial(M))%P))%P)
elif min(N,M)+1==max(N,M):
    print((((factorial(N))%P)*((factorial(M))%P))%P)
else:
    print("0")

Measured memory_bytes: 46960
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) x.begin(),x.end()
#define pll  pair <long long,long long>
#define ss second
#define ff first
#define inf 9223372036854775807
#define maa 1000000007
#define ld long double
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define bug(x) cout << #x <<": " << x << '\n';
const ll N=200001 ;
int main()
{
   fast ;
   ll n,m ; cin>>n>>m ;
   vector<ll>v[n+1] ;
   ll c[n+1] ;
   for(ll i=1;i<=n;i++) cin>>c[i] ;


   for(ll i=0;i<m;i++){
    ll x,y ; cin>>x>>y ;
    v[x].pb(y) ;
    v[y].pb(x) ;
   }

   ll ans=0 ;
   for(ll i=1;i<=n;i++)
   {
       ll mx=INT_MIN ;
       for(ll j:v[i]) mx=max(mx,c[j]) ;

       if(c[i]>mx) ans++ ;
   }
   cout<<ans ;



}



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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  int H, W;
  cin >> H >> W;
  vector<vector<char>> S(H);
  char s;
  REP(i, H) {
    REP(j, W) {
      cin >> s;
      S.at(i).push_back(s);
    }
  }

  vector<int> K = {-1, 0, 0, 1};
  vector<int> L = {0, -1, 1, 0};

  bool ok = true;
  REP(i, H) {
    REP(j, W) {
      if (S.at(i).at(j) == '#') {
        int found_black = false;
        for (int k = 0; k < 4; ++k) {
          int ny = i + K.at(k);
          int nx = j + L.at(k);
          if ((0 <= ny && ny < H) && (0 <= nx && nx < W)) {
            if (S.at(ny).at(nx) == '#') {
              // cout << i << "/" << j << "|" << ny << ":" << nx << endl;
              found_black = true;
              break;
            }
          }
        }

        if (!found_black) {
          ok = false;
          break;
        }
      }
    }

    if (!ok) {
      break;
    }
  }

  if (ok) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int gcd(int x, int y)
{
	int r;
	
	while (y>0){
		r=x%y;
		x=y;
		y=r;
	}
	return x;
}

int main(void)
{
	int a,x, y, d;
	scanf("%d %d", &x, &y);
	if(x<y){
		a=x;
		x=y;
		y=a;
	}
	
	d=gcd(x, y);
	printf("%d\n", d);
	
	return 0;
}


Measured memory_bytes: 2040
#include <bits/stdc++.h>
#define ll long long
#define fastIO cout << fixed << setprecision(12), ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr)
using namespace std;

int main() {
	fastIO;
#ifdef LOCAL
//	freopen("input.in", "rt", stdin);
#endif
	int n;
	cin >> n;
	string str;
	set<string> st;
	for (int i = 0; i < n; ++i) {
		cin >> str;
		st.insert(str);
	}
	cout << st.size();
	return 0;
}


Measured memory_bytes: 19248
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2

using namespace std;

int MOD = 1000000007;
string s;
int n,m;
int r[100010];
int w[100010];

signed main(){

    cin >> n >> m;
    rep(i,n){
        r[i] = 0;
        w[i] = 1;
    }
    r[0] = 1;
    w[0] = 0;

    rep(i,m){
        int x,y;
        cin >> x >> y;
        x--;
        y--;
        if(r[x] == 0) {
            w[x]--;
            w[y]++;
            if(r[y] != 0){
                r[y] += w[y];
                w[y] = 0;
            }
        }else{
            r[x]--;
            r[y] = w[y]+r[y] + 1;
            w[y] = 0;
        }
    }

    int ans = 0;
    rep(i,n){
        if(r[i] > 0)ans++;
    }
    cout << ans <<endl;
    
    
    return 0;
}
// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl 

Measured memory_bytes: 1792
s = input()
if s == "SSS":
    print("0")
elif s == "SSR":
    print("1")
elif s == "SRS":
    print("1")
elif s == "RSS":
    print("1")
elif s == "RSR":
    print("1")
elif s == "RRS":
    print("2")
elif s == "SRR":
    print("2")
elif s == "RRR":
    print("3")


Measured memory_bytes: 61604
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")



n = int(input())
ans = 0
for i in range(1, n+1):
    v = (n)//i
    ans += i*(v+1)*v//2
print(ans)

Measured memory_bytes: 63452
#include <bits/stdc++.h>
using namespace std;
template <class T> inline void read(T &x) {
	x = 0; int c = getchar(), f = 1;
	for (; !isdigit(c); c = getchar()) if (c == 45) f = -1;
	for (; isdigit(c); c = getchar()) (x *= 10) += f*(c-'0');
}
int n, m;
char s[100][100];
int main() {
	read(n), read(m), n--, m--;
	for (int i = 0; i < 100; i++)
		for (int j = 0; j < 100; j++)
			s[i][j] = i < 50 ? '#' : '.';
	for (int i = 0; n; i += 2, n -= min(n, 50))
		for (int j = 0; j < 2*min(n, 50); j += 2) s[i][j] = '.';
	for (int i = 99; m; i -= 2, m -= min(m, 50))
		for (int j = 0; j < 2*min(m, 50); j += 2) s[i][j] = '#';
	puts("100 100");
	for (int i = 0; i < 100; i++, puts(""))
		for (int j = 0; j < 100; j++) putchar(s[i][j]);
	return 0;
}

Measured memory_bytes: 256
n = int(input())
prime_lst = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31]
lst = [0 for _ in range(n)]
for i in range(1, n + 1):
    a = i
    for num in prime_lst:
        while a % num == 0:
            lst[num - 1] += 1
            a //= num
    if a != 1:
        lst[a - 1] += 1
ans = 1
MOD = 10 ** 9 + 7
for num in lst:
    ans *= (num + 1)
    ans %= MOD
print(ans)

Measured memory_bytes: 9200
import java.util.*;
import java.io.*;
public class Main {
    static int mod  = 1000000007;
    public static void main(String[] args) {
        MyScanner ms = new MyScanner();
        int H = ms.nextInt();
        int W= ms.nextInt();
        char [][] table = new char[H][W];
        int [] [] dp = new int[H][W];
        for(int i=0;i<H;i++)
        {
            String line = ms.nextLine();
            for(int j=0;j<W;j++)
            table[i][j] = line.charAt(j);
        }
        dp[0][0] = 1;
        for(int i=0;i<H;i++)
        for(int j=0;j<W;j++){
            if(table[i][j]=='#') continue;
            if(i-1>=0)dp[i][j] = (dp[i-1][j]+dp[i][j])%mod;
            if(j-1>=0)dp[i][j] = (dp[i][j-1]+dp[i][j])%mod;
        }
    System.out.println(dp[H-1][W-1]);
    }


    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;
   
        public MyScanner() {
           br = new BufferedReader(new InputStreamReader(System.in));
        }
   
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
   
        int nextInt() {
            return Integer.parseInt(next());
        }
   
        long nextLong() {
            return Long.parseLong(next());
        }
   
        double nextDouble() {
            return Double.parseDouble(next());
        }
   
        String nextLine(){
            String str = "";
        try {
           str = br.readLine();
        } catch (IOException e) {
           e.printStackTrace();
        }
        return str;
        }
  
     }
}

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

int main(){
    double x1,y1,x2,y2;
    cin >> x1 >> y1 >> x2 >> y2;
    cout << fixed << setprecision(8) << sqrt(pow((x1-x2),2)+pow((y1-y2),2)) << endl;
    return 0;
}


Measured memory_bytes: 3264
#include <iostream>

#include <limits>
#include <tuple>
#include <vector>

// left: [low, mid)  right: [mid, high)
template<typename T>
std::tuple<std::size_t, std::size_t, T> find_max_crossing_subarray
(const std::vector<T> &A, std::size_t low, std::size_t mid, std::size_t high) {
    std::size_t max_left = mid - 1;
    std::size_t max_right = mid;

    T left_sum = std::numeric_limits<T>::min();
    T sum = 0;
    for(std::size_t i = 1; i <= mid - low; ++i) {
        sum += A[mid - i];
        if(sum > left_sum) {
            left_sum = sum;
            max_left = mid - i;
        }
    }

    T right_sum = std::numeric_limits<T>::min();
    sum = 0;
    for(std::size_t j = mid; j < high; ++j) {
        sum += A[j];
        if(sum > right_sum) {
            right_sum = sum;
            max_right = j;
        }
    }

    return std::make_tuple(max_left, max_right + 1, left_sum + right_sum);
}

// [low, high)
template<typename T>
std::tuple<std::size_t, std::size_t, T> find_maximum_subarray
(const std::vector<T> &A, std::size_t low, std::size_t high) {
    if(high - low < 2) return std::make_tuple(low, high, A[low]);

    std::size_t mid = (low + high) / 2;
    auto left = find_maximum_subarray<T>(A, low, mid);
    auto right = find_maximum_subarray<T>(A, mid, high);
    auto cross = find_max_crossing_subarray<T>(A, low, mid, high);

    T left_sum = std::get<2>(left);
    T right_sum = std::get<2>(right);
    T cross_sum = std::get<2>(cross);

    if(left_sum >= right_sum && left_sum >= cross_sum) return left;
    else if(right_sum >= left_sum && right_sum >= cross_sum) return right;
    else return cross;
}

int main() {
    std::vector<int> A(5000);
    while(true) {
        std::size_t n;
        std::cin >> n;
        if(n == 0) break;

        for(std::size_t i = 0; i < n; ++i) std::cin >> A[i];
        std::cout << std::get<2>(find_maximum_subarray<int>(A, 0, n)) << std::endl;
    }
}


Measured memory_bytes: 3092
import sys
sys.setrecursionlimit(10**6)
if sys.platform in (['ios','darwin','win32']):
	sys.stdin=open('Untitled.txt')
input = sys.stdin.readline
def INT(): return int(input())
def MAP(): return [int(s) for s in input().split()]

def main():
	A = MAP()
	if A[0] % 2 or A[1] % 2 or A[2] % 2:
		print(0)
	elif A[0] == A[1] and A[0] == A[2]:
		print(-1)
	else:
		cnt = 0
		while all(a%2 == 0 for a in A):
			a = A[0]//2 + A[1]//2
			b = A[1]//2 + A[2]//2
			c = A[0]//2 + A[2]//2
			A[0] = a
			A[1] = b
			A[2] = c
			cnt += 1
			# A.sort()
			# print(A)

		print(cnt)

if __name__ == '__main__':
	main()

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<vector>
#include<map>
using namespace std;
int main() {
    long long N, M;
    cin >> N >> M;
    long long rN, rM;
    long long make = 0;
    if(N*2 <= M){
        make += N;
        rM = M - N*2;
        rN = 0;
    }
    else if(N*2 > M){
        make += M / 2;
        cout << make << endl;
        return 0;
    }
    make += rM / 4;
    cout << make << endl;
    return 0;
}

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

using namespace std;

int main() {
	int N, M;
	cin >> N >> M;
	std::vector<std::vector<int>> adj(N+1);

	int ai, bi;
	for (int i = 0; i < M; ++i) {
		cin >> ai >> bi;

		adj[ai].push_back(bi);
		adj[bi].push_back(ai);
	}

	// for (int i = 1; i <= N; ++i) {
	// 	adj[i][i] = 1;
	// }

	// for(int i = 1; i <= N; ++i) {
	// 	for (int j = 1; j <= N; ++j)
	// 		cout << adj[i][j] << " ";
	// 	cout << endl;
	// }

	int res = 0;

	bool *visited = (bool*) malloc(sizeof(bool) * (N+1));
	memset(visited, false, N+1);

	// cout << "visited: ";
	// for(int i = 1; i <= N; ++i) {
	// 	cout << visited[i] << " ";
	// }
	// cout << endl;

	for(int i = 1; i <= N; ++i) {
		if (visited[i])
			continue;
		// cout << "visiting " << i << endl;
		std::stack<int> v;
		v.push(i);

		while(!v.empty()){

			int x = v.top();
			v.pop();

			visited[x] = true;
			// cout << "visited[" << x << "] = " << visited[x] << endl;

			for(auto ip = adj[x].begin(); ip != adj[x].end(); ++ip) {
				if(!visited[*ip])
					v.push(*ip);
			}
		}
		res += 1;
	}

	// cout << "After, visited: ";
	// for(int i = 1; i <= N; ++i) {
	// 	cout << visited[i] << " ";
	// }
	// cout << endl;

	cout << res - 1 << endl;

	return 0;
}

Measured memory_bytes: 8536
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;



namespace Test1 {

    class ClassMain {





        public static void Main(String[] args) {
            string line;
            while ((line = Console.ReadLine()) != null) {
                int n = int.Parse(line);
                if (n == 0) { break; }
                int myP=0, eneP=0;
                for (int i = 0; i < n; i++) {
                    int[] scores = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
                    if (scores[0] > scores[1]) {
                        myP += (scores[0] + scores[1]);
                    }
                    else if (scores[0] < scores[1]) {
                        eneP += (scores[0] + scores[1]);
                    }
                    else { myP += scores[0]; eneP += scores[1]; }
                }
                Console.WriteLine(myP + " " + eneP);

    
            }
        }


    }

    
}

Measured memory_bytes: 6156
n,m,x = gets.split(" ").map(&:to_i)
toll = gets.split(" ").map(&:to_i)
left_cost,right_cost = 0,0

m.times do |i|
  if toll[i] < x
    left_cost += 1
  else
    right_cost += 1
  end
end

if left_cost <= right_cost
    puts(left_cost)
else
    puts(right_cost)
end

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

using namespace std;
long long int n,m[300000],a,k=0,x=0;
int main()
{
	ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
	cin >> n;
	fill(m,m+300000,0);
	for(int i=1; i<=n; i++)
	{
		cin >> a;
		m[a]++;
	}
	for(int i=1; i<=99999; i++)
        {
              	k=m[i]+m[i-1]+m[i+1];
		x=max(x,k);
        }
	cout << x;
	return 0;
}


Measured memory_bytes: 2560
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>
#include<complex>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;




const ll INF = 1e9;


/******************************************************************************************/


int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);

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

	int mini = 1;

	int now = a[0];
	for (int i = 1; i < n; i++)
	{
		if (now >= a[i]) {
			mini++;
		}
		now = a[i];
	}

	cout << mini << endl;
	cout << n << endl;
	 


	return 0;
}



Measured memory_bytes: 3368
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-

import heapq

n = int(input())

aa = []
bb = []
for i in range(n):
    a , b = list(map(int, input().split()))

    aa.append(a)
    bb.append(b)

aa.sort()
bb.sort()

if n % 2 == 0:
    m_a = (aa[n // 2 - 1] + aa[n // 2])
    m_b = (bb[n // 2 - 1] + bb[n // 2])

    print(m_b - m_a+1)
    sys.exit()

else:
    median_a = aa[n // 2]
    median_b = bb[n // 2]

    print(median_b-median_a+1)
    sys.exit()

Measured memory_bytes: 25992
package main

import (
	"fmt"
)

const (
	rock = iota
	scissors
	paper
)

func main() {
	var n, k int
	fmt.Scanf("%d %d", &n, &k)
	var r, s, p int
	fmt.Scanf("%d %d %d", &r, &s, &p)
	var t string
	fmt.Scan(&t)
	result := 0
	ans := make([]int, n)
	for i, opp := range t {
		oppChoice := convert(string(opp))
		choice := win(oppChoice)
		point := point(choice, r, s, p)
		if i < k || choice != ans[i-k] {
			result += point
			ans[i] = choice
		} else if i+k < n {
			future := convert(string(t[i+k]))
			if win(future) != oppChoice {
				ans[i] = oppChoice
			} else {
				ans[i] = 3 - oppChoice - choice
			}
		}
	}
	fmt.Println(result)
}

func win(opp int) int {
	switch opp {
	case rock:
		return paper
	case scissors:
		return rock
	case paper:
		return scissors
	default:
		return 0
	}
}

func point(choice int, r, s, p int) int {
	switch choice {
	case rock:
		return r
	case scissors:
		return s
	case paper:
		return p
	default:
		return 0
	}
}

func convert(s string) int {
	switch s {
	case "r":
		return rock
	case "s":
		return scissors
	case "p":
		return paper
	default:
		return 0
	}
}


Measured memory_bytes: 2048
a,b,c = gets.split.map(&:to_i)

i = 0
while a.even? && b.even? && c.even?
    x = a
    y = b
    a = b / 2 + c / 2
    b = x / 2 + c / 2
    c = x / 2 + y / 2
    i += 1
    if a == b && b == c
        i = -1
        break
    end
end

puts i

Measured memory_bytes: 1916
import sys

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]


class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parents = list(range(n))
        self.ranks = [0 for _ in range(n)]

    def get_root(self, x):
        if self.parents[x] == x:
            return x
        self.parents[x] = self.get_root(self.parents[x])
        return self.parents[x]

    def merge(self, x, y):
        x = self.get_root(x)
        y = self.get_root(y)
        if x != y:
            if self.ranks[x] < self.ranks[y]:
                self.parents[x] = y
            else:
                self.parents[y] = x
                if self.ranks[x] == self.ranks[y]:
                    self.ranks[x] += 1


n, m = ril()
ls = rils(m)

count = 0
for i in range(m):
    uf = UnionFind(n)
    for j in range(m):
        if j == i:
            continue
        a, b = ls[j]
        uf.merge(a - 1, b - 1)
    for i in range(n):
        uf.get_root(i)
    if len(set(uf.parents)) > 1:
        count += 1
print(count)

Measured memory_bytes: 3192
parseInt(x) = parse(Int, x)
parseBigInt(x) = parse(BigInt, x)
parseFloat(x) = parse(Float64, x)
parseBigFloat(x) = parse(BigFloat, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    n=parseInt(readline())
    a=sort(parseMap(split(readline())),rev=true)
    ans=0
    for i in 1:2n
        if i%2==0
            ans+=a[i]
        end
    end
    println(ans)
end
main()

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

class dice
{
private:
    int asp[6];
    string order;
public:
    void setdice( int* j );                         //サイコロの値を格納
    void dice_print();                              //サイコロの値を出力
    void exchange( int& x, int& y );                //サイコロの場所を交換
    void orderX( string x );                        //転がす命令を行う      
    void up_print(){ cout << asp[0] << endl; }              //上面を出力する関数
};

void dice::setdice( int* j )
{
    for( int i = 0; i < 6; i++ )
        asp[i] = j[i];
}

void dice::dice_print()
{
    for( int i = 0; i < 6; i++ )
        cout << asp[i] << " ";
    cout << endl;
}

void dice::exchange( int& x, int& y )
{
    int temp;
    temp = x;
    x = y;
    y = temp;
}

void dice::orderX( string x )
{

    for( int i = 0; i < x.size(); i++ )
    {

        if( x[i] == 'E')
        {
            exchange( asp[0], asp[2] );
            exchange( asp[0], asp[5] );
            exchange( asp[0], asp[3] );
        }
        else if( x[i] == 'N')
        {
            exchange( asp[0], asp[4] );
            exchange( asp[0], asp[5] );
            exchange( asp[0], asp[1] );
            
        }
        else if( x[i] == 'S')
        {
            exchange( asp[0], asp[1] );
            exchange( asp[0], asp[5] );
            exchange( asp[0], asp[4] );
        }
        else if( x[i] == 'W')
        {
            exchange( asp[0], asp[3] );
            exchange( asp[0], asp[5] );
            exchange( asp[0], asp[2] );
        }
        else{}
    }
}

int main()
{
    int d[6];
    string ord;
    dice dice1;

    for( int i = 0; i < 6; i++ )
        cin >> d[i];
    
    cin >> ord;

    dice1.setdice( d );                 //サイコロの面をセット
    dice1.orderX( ord );                 //命令に従って並び替え
    dice1.up_print();                   //上面出力


    return 0;
}


Measured memory_bytes: 3180
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;

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

const ll MOD = 1000000007;
const int INF = 1<<30;
//const ll INF = (ll)1e18 + 1;

int main(){
  int N; cin >> N;
  vector<int> d(N);
  rep(i, N) cin >> d[i];

  if (N % 2 != 0) {cout << 0 << endl; return 0;}
  sort(d.begin(), d.end());
  cout << d[N / 2] - d[N / 2 - 1] << endl;
}


Measured memory_bytes: 640
using System;
using System.Linq; 

namespace Sample
{
  class Sample
  {
    static void Main(string[] args)
    {
      int N=int.Parse(Console.ReadLine());
	string[] str=Console.ReadLine().Split(' ');
      int[] arr=str.Select(int.Parse).ToArray();
      int ans=0;
      for(int i=0;i<N;i++){
       if((i%2==0)&&(arr[i]%2!=0)){
         ans++;
       }
      }
        Console.WriteLine(ans);
      
    }
    
  }

}

Measured memory_bytes: 28308
from collections import deque
from functools import reduce
def f(a):
    return (a + 1) % M
def g(a, b):
    return a * b % M
init = 1

N, M = map(int, input().split())
X = [[] for i in range(N)]
for i in range(N-1):
    x, y = map(int, input().split())
    X[x-1].append(y-1)
    X[y-1].append(x-1)

P = [-1] * N
Q = deque([0])
T = []
while Q:
    i = deque.popleft(Q)
    T.append(i)
    for a in X[i]:
        if a != P[i]:
            P[a] = i
            X[a].remove(i)
            deque.append(Q, a)

BU = [0] * N # Bottom Up
TD = [1] * N # Top Down
for i in T[::-1]:
    BU[i] = reduce(g, [f(BU[j]) for j in X[i]]) if len(X[i]) else init

for i in T:
    B = [1] * (len(X[i]) + 1)
    for k, j in enumerate(X[i]):
        B[k+1] = g(B[k], f(BU[j]))
    a = init
    for k in range(len(X[i]))[::-1]:
        j = X[i][k]
        TD[j] = f(g(TD[i], g(a, B[k])))
        a = g(a, f(BU[j]))

for t in [g(a, b) for a, b in zip(BU, TD)]:
    print(t)

Measured memory_bytes: 83360
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll A,B,C,X,Y;
    cin >>A>>B>>C>>X>>Y;
    ll ans = 0;
    if(A+B>C*2){
        ans+=C*2*min(X,Y);
        if(X>Y){
            X-=Y;
            Y=0;
        }else{
            Y-=X;
            X = 0;;
        }

    }
    //cout<<ans<<endl;
    if(A<=C*2){
        ans+=X*A;
        X=0;
    }
    //cout<<ans<<endl;
    if(B<=C*2){
        ans+=Y*B;
        Y=0;
    }
    //cout<<ans<<endl;
    ans += C*2*max(X,Y);
    //cout<<ans<<endl;
    cout << ans << endl;


    return 0;
    

}

Measured memory_bytes: 3640
fun main(args: Array<String>) {
    val N = nextInt()
    val B = listOfInt()
    val A = IntArray(N)
    A[0] = B[0]
    repeat(N - 1) { A[it + 1] = B[it] }
    for (n in 0 until N - 1) {
        var max = Math.max(A[n], A[n + 1])
        var min = Math.min(B[n], max)
        A[n + 1] = min
        min = Math.min(A[n], A[n + 1])
        A[n] = min
//System.err.println(A.joinToString())
    }
    var ans = A.sum()
    println(ans)
}
fun next() = readLine()!!
fun nextInt() = Integer.parseInt(next())
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { Integer.parseInt(it) }


Measured memory_bytes: 37908
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
#include <random>
#include <cassert>
using namespace std;

#define rep(i, N) for (int i = 0; i < N; i++)
#define pb push_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<int, ll> i_ll;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
typedef vector<int> vi;
struct edge { int v; ll w; };

const int MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;
int INF = INT_MAX / 2;

struct hl_decomp {
	int N, M;
	vector<vi> G;
	vi sz, id, par, dep;
	hl_decomp(int _N, vector<vi> _G)
		: N(_N), G(_G), sz(N), id(N), par(N), dep(N) {
		dfs_sz(0, -1);
		dfs_decomp(0, -1);
		M = 1; par[0] = -1; dfs_decomp(0, -1);
		dfs_dep(0, -1);
	}
	void dfs_sz(int u, int p) {
		sz[u] = 1;
		for (int v : G[u]) if (v != p) {
			dfs_sz(v, u);
			sz[u] += sz[v];
		}
	}
	void dfs_decomp(int u, int p) {
		int v0 = -1;
		for (int v : G[u]) if (v != p)
			if (v0 == -1 || sz[v] > sz[v0]) v0 = v;
		for (int v : G[u]) if (v != p) {
			if (v == v0) {
				id[v] = id[u];
				par[v] = par[u];
			}
			else {
				id[v] = M++;
				par[v] = u;
			}
			dfs_decomp(v, u);
		}
	}
	void dfs_dep(int u, int p) {
		for (int v : G[u]) if (v != p) {
			dep[v] = dep[u] + 1;
			dfs_dep(v, u);
		}
	}
	int lca(int u, int v) {
		while (id[u] != id[v]) {
			int _u = par[u], _v = par[v];
			int du = (_u == -1 ? -1 : dep[_u]);
			int dv = (_v == -1 ? -1 : dep[_v]);
			if (du >= dv) u = _u;
			else v = _v;
		}
		return dep[u] < dep[v] ? u : v;
	}
};

int main() {
	int N; cin >> N;
	vector<vector<int> > G(N);
	rep(u, N) {
		int K; scanf("%d", &K);
		while (K--) {
			int v; scanf("%d", &v);
			G[u].pb(v);
		}
	}
	hl_decomp hl(N, G);
	int Q; cin >> Q;
	while (Q--) {
		int u, v; scanf("%d%d", &u, &v);
		int w = hl.lca(u, v);
		printf("%d\n", w);
	}
}

Measured memory_bytes: 25724
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

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

use std::collections::HashMap;
fn main() {
    input!{
        n: usize,
        s: [String; n],
        m: usize,
        t: [String; m],
    };
    let mut map = HashMap::new();
    for st in s{
        *map.entry(st).or_insert(0i32) += 1;
    }
    for st in t{
        *map.entry(st).or_insert(0) -= 1;
    }
    println!(
        "{}",
        map.values().map(|&n| if n > 0{n}else{0}).max().unwrap()
    );
}


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

int dp[101][100002];

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n,k;
	cin>>n>>k;
	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<=k;j++)
		{
			dp[i][j]=0;
		}
	}
	int arr[n];
	int sum=0;
	for(int i=0;i<n;i++)
	{
		cin>>arr[i];
		sum+=arr[i];
	}
	if(sum<k)
	{
		cout<<0;
		return 0;
	}
	for(int i=0;i<=arr[0];i++)
	{
		dp[0][i]=1;
	}
	for(int i=1;i<n;i++)
	{
		int sum=0;
		for(int j=0;j<=arr[i];j++)
		{
			sum=(dp[i-1][j]+sum)%MOD;
			dp[i][j]=sum;
		}
		for(int j=arr[i]+1;j<=k;j++)
		{
			sum=(sum-dp[i-1][j-arr[i]-1]+MOD)%MOD;
			sum=(dp[i-1][j]+sum)%MOD;
			dp[i][j]=sum;
		}
	}
	cout<<dp[n-1][k];
return 0;
}

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

int main()
{
	long x;

	cin >> x;

	cout << std::bitset<32>(x) << endl;
	cout << std::bitset<32>(~x) << endl;
	cout << std::bitset<32>(x << 1) << endl;
	cout << std::bitset<32>(x >> 1) << endl;

	return 0;
}


Measured memory_bytes: 3176
#include<iostream>
#include<stdio.h>//printf("%.*f\n",*********);
#include<vector>//s.erase(n),vector
#include<algorithm>//next_permutation
#include<set>
#include<string>//char('a'=32+'A')
                //to_string,string,substr
#include<sstream>
#include<complex>
#include<time.h>
#include<random>
#include<cmath>//min,max
#include<math.h>
#include<queue>
#include<time.h>
#include<iomanip>
#include<locale>
#include<utility>//swap

#define rt "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define rop(i,n) for(int i=1;i<=n;i++)//start==1
#define drep(i,n) for(int i=n-1;0<=i;i--)
#define drop(i,n) for(int i=n;0<i;i--)//end==1
#define yes(ans) if(ans)cout<<"yes"<<rt;else cout<<"no"<<rt;
#define Yes(ans) if(ans)cout<<"Yes"<<rt;else cout<<"No"<<rt;
#define YES(ans) if(ans)cout<<"YES"<<rt;else cout<<"NO"<<rt;
#define Yay(ans) if(ans)cout<<"Yay!"<<rt;else cout<<":("<<rt;
#define sec(a,b,ans) if(ans)cout<<a<<rt;else cout<<b<<rt;
#define vcin(a,n) rep(i,n)cin>>a[i];//vcin(配列名),(繰り返し回数)
#define sort(s) sort(s.begin(),s.end())//昇順
#define reve(s) reverse(s.begin(),s.end())//反転
#define please return
#define AC 0
#define rapid_pleaseAC_fast cin.tie(0);ios::sync_with_stdio(false)
#define pi 3.1415926535897932384626//pi
#define nine 1000000000//10^9

using namespace std;
typedef vector<int> vint;
typedef long double ldouble;
typedef vector<string> vstr;
typedef vector<char> vchar;
typedef vector<double> vdou;
typedef vector<double> vdouble;
typedef long long int llint;
typedef pair<int, int> pint;
typedef pair<llint, llint> pllint;
typedef vector<llint> vllint;
typedef vector<pint> vpint;
typedef vector<pair<llint, llint>> vpllint;
typedef vector<vector<int>> vvint;
typedef vector<vector<char>> vvchar;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<llint>> vvllint;
typedef vector<vector<string>> vvstr;
typedef vector<vector<bool>> vvbool;
typedef vector<vector<pint>> vvpint;
typedef vector<bool> vbool;

long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

long long LCM(long long a, long long b) {
	return a * b / GCD(a, b);
}

unsigned GetDigit(unsigned num) {
	return std::to_string(num).length();
}

int tow(int n) {//2のn乗
	if (n == 0)return 1;
	int x = tow(n / 2);
	x *= x;
	if (n % 2 == 1)x *= 2;
	return x;//@domino
}

int KETA(int n) { //Sum of Each Digit
	int sum = 0;
	while (n > 0) {
		sum += n % 10; n /= 10;
	}
	return sum;
}

unsigned ND(unsigned num) {//Number of Digits
	return std::to_string(num).length();//outmax=10
}

bool KIBN(string s) {
	rep(i, s.size() / 2) {
		if (s[i] != s[s.size() - 1 - i])return false;
	}
	return true;
}

/*

 (char)toupper(a[n])=文字列のn文字目を大文字で出力

  pow(a,b)=aのb乗

  */

bool ABC(int n) {
	if (0 < n && n < 13) {
		return true;
	}
	else {
		return false;
	}
}

int main(void) {
	rapid_pleaseAC_fast;

	int n;
	cin >> n;
	for (int i = n; i > 0; i--) {
		if (i == (int)sqrt(i) * (int)sqrt(i)) {
			cout << i << rt;
			return 0;
		}
	}

	please AC;
}
//参考：---

Measured memory_bytes: 256
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] a = new int[n];
		int i = 0;
		for(i = 0; i < n; i++) {
			a[i] = scan.nextInt();
		}
		int button = 0;
		Set<Integer> set = new HashSet<Integer>();
		int count = 0;
		a:for(i = 0; button != 1; i = button) {
			button = a[i] - 1;
			int before = set.size();
			set.add(button);
			int after = set.size();
			if(before == after) {
				count = -1;
				break a;
			}
			count++;
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 52428
using System;
//using System.Collections.Generic;
//using System.Linq;

namespace solution
{
  class Class1
  {
    static void Main()
    {
      string[] s = Console.ReadLine().Split();
      double a = double.Parse(s[0]);
      double b = double.Parse(s[1]);
      double C = double.Parse(s[2]) / 180.0 * Math.PI;

      double h = b * Math.Sin(C);
      double S = a * h * 0.5;
      double L = a + b + Math.Sqrt(a * a + b * b - 2 * a * b * Math.Cos(C));

      Console.WriteLine("{0:f8}\n{1:f8}\n{2:f8}", S, L, h);
    }
  }
}


Measured memory_bytes: 9288
/*
 * ID: ITP1_7_B
 * Problem: Number of combination
 */

#include <stdio.h>

int main(void)
{
    int n, sum;

    while (1) {
        scanf("%d %d", &n, &sum);
        if (n == 0 && sum == 0)
            return 0;
        int i, j, k, count = 0;
        for (i = 1; i <= n; i++) {
            for (j = i + 1; j <= n; j++) {
                k = sum - i - j;
                if (k > j && k <= n) 
                    count++;
            }
        }
        printf("%d\n", count);
    }

    return 0;
}



Measured memory_bytes: 2100
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  int c,d,ans;
  c = max(a,b);
  d = min(a,b);
  if(c-d>0){
    ans = 2*c-1;
  }
  else{
    ans = 2*c;
  }
  cout<<ans;
  return 0;
}


Measured memory_bytes: 256
L,R=map(int,input().split())
mod=2019
ans=2019
start=L//mod
goal=R//mod
if start!=goal:
  print(0)
else:
  a=L%mod
  b=R%mod
  for i in range(a,b):
    for j in range(i+1,b+1):
      if ans>(i*j)%mod:
        #print(i,j)
        ans=(i*j)%mod
  print(ans)

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <stack>
#include <set>

using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int, int> PII;
typedef long long LL;
#define ALL(a) (a).begin(),(a).end()
#define PB push_back
#define MP make_pair
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define IFOR(v,it) for(VI::iterator it=(v).begin();it!=(v).end();++it)

int N, M;
int solve(vector<vector<bool> >& edge, bool visited[9], int start) {
  visited[start] = true;
  bool allVisited = true;
  int count = 0;
  FOR(i, 1, N+1) {
    if (!visited[i]) {
      allVisited = false;
      if (edge[start][i])
        count += solve(edge, visited, i);
    }
  }
  visited[start] = false;
  if (allVisited)
    return 1;
  return count;
}

int main() {
  cin >> N >> M;

  vector<vector<bool> > edge;
  REP(i, N+1) {
    vector<bool> v(N+1, false);
    edge.PB(v);
  }
  REP(i, M) {
    int a, b;
    cin >> a >> b;
    edge[a][b] = true;
    edge[b][a] = true;
  }
  bool visited[9];
  fill(visited, visited + 9, false);
  cout << solve(edge, visited, 1) << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<limits.h>
//INT_MINはint型の最小値
//INT_MAXはint型の最大値

int L[250001];
int R[250001];

void merge(int*,int,int,int);
void mergesort(int*,int,int);

int count=0;

int main(){
  int n,i;
  int A[500000];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }
  int LEFT=0;
  int RIGHT=n;
 
  mergesort(A,LEFT,RIGHT);
  for(i=0;i<n;i++){
    if(i==n-1)
      printf("%d\n",A[i]);
    else
      printf("%d ",A[i]);
  }

  printf("%d\n",count);
  return 0;
}


void merge(int *A,int left,int mid,int right){
  int n1,n2,i,j,k;
 
  n1=mid-left;
  n2=right-mid;
  
  for(i=0;i<n1;i++)
    L[i]=A[left+i];
  for(i=0;i<n2;i++)
    R[i]=A[mid+i];
  
  L[n1]=INT_MAX;
  R[n2]=INT_MAX;
  
  i=0;
  j=0;
  for(k=left;k<=right-1;k++){
    count++;
    if(L[i]<=R[j]){
      A[k]=L[i];
      i++;
    }
    else{
      A[k]=R[j];
      j++;
    }
    // printf("merged.A[%d]:%d\n",k,A[k]);
  }
 
}

void mergesort(int *A,int left,int right){
  int mid;
  if(left+1<right){
    mid=(left+right)/2;
    mergesort(A,left,mid);
    mergesort(A,mid,right);
    merge(A,left,mid,right);
  }
}



Measured memory_bytes: 5608
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
const long long INFLL = 1LL << 60;
const int INFINT = 1 << 30;
const long long MOD = 1e9 + 7;

char winhand(char h) {
    if(h == 'r') {
        return 'p';
    } else if(h == 'p') {
        return 's';
    } else {
        return 'r';
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, K;
    int R, S, P;
    string T;
    cin >> N >> K >> R >> S >> P >> T;
    map<char, int> mp;
    mp['r'] = R;
    mp['s'] = S;
    mp['p'] = P;
    int score = 0, sc;
    char pre = 'x';

    for(int k = 0; k < K; k++) {
        sc = 0;
        pre = 'x';
        for(int n = k; n < N; n += K) {
            if(winhand(T.at(n)) != pre) {
                sc += mp.at(winhand(T.at(n)));
                pre = winhand(T.at(n));
            } else {
                if(n + K < N) {
                    pre = 'x';
                }
            }
        }
        score += sc;
    }
    cout << score << endl;
}

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

#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)
#define MOD 1000000007

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 and z<=K) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int b[50000];
int main() {
	int n, m, t; cin >> n >> m >> t;
	rep(i, n) {
		int h; cin >> h;
		b[max(0, h - m)]++;
		b[h + m]--;
	}
	int c = 0;
	rep(i, t) {
		if (i)b[i] += b[i - 1];
		if (!b[i])c++;
	}
	cout << c << endl;
}

Measured memory_bytes: 3124
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace std;
using namespace __gnu_pbds;

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

#define lsc(x)      scanf("%lld",&x)
#define sc(x)       scanf("%d",&x)
#define lpr(x)      printf("%lld ",(long long)x)
#define pr(x)       printf("%d ",x)
#define n_l         printf("\n")
#define VI          vector<int>
#define VII         vector<long long int>
#define m_p         make_pair
#define pb          push_back
#define fi           first
#define se           second
#define mset(x,y)   memset(x,y,sizeof(x))
#define sz(v)       (int)v.size()
#define all(v)      v.begin(), v.end()
#define fr(i, a, n) for(int i=a;i<=n;i++)
#define FIO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
mt19937 rng32(chrono::steady_clock::now().time_since_epoch().count());
const int N=(int)1e6+5;
const int mod = 1000000007;
typedef long long ll;
// order_of_key (val): returns the no. of values strictly less than val
// find_by_order (k): returns the kth largest element iterator.(0-based)
// vector<int>::iterator itr=lower_bound(v.begin(),v.end(),x);
// s.substr(pos[0-indexed], len(default=till end))
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

ll fmod(ll x, int mod){if (x<mod) return x;return x%mod;}
ll mul(ll a, ll b, ll c){
	ll ret=0;while(b){if (b%2) ret=(ret+a)%c;a=(a*2)%c;b>>=1;}
    return ret;
}
int modpow(ll a, ll b){
    ll ret=1;while(b){if (b%2) ret=(ret*a)%mod;a=(a*a)%mod;b>>=1;}
    return (int)ret;
}
inline int inv(int x){ return modpow(x, mod-2);}
int isprime[N];
void calc_prime(){
	isprime[1]=1;for(ll i=2;i<N;i++) if (!isprime[i]) for(ll j=i*i;j<N;j+=i) isprime[j]=1;
}
int main(){
    int k;sc(k);
    ll cur = 0;
    fr(cnt, 1, 1000000){
        cur = cur * 10LL + 7LL;
        cur = fmod(cur, k);
        if (cur == 0){
            pr(cnt);n_l;
            return 0;
        }
    }
    pr(-1);n_l;
    return 0;
}



Measured memory_bytes: 3780
# -*- coding: utf-8 -*-
 
import math
import itertools
import sys
import copy
 
# 入力
#A, B, C, D = map(int, input().split())
#L = list(map(int, input().split()))
#S = list(str(input()))
#N = int(input())
S, T = map(str, input().split())

print (T+S)


Measured memory_bytes: 38384
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <complex>

#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#define rep(i,n) for(int i=0;i<(n); ++i)
#define rep2(i,n) for(int i=1;i<=(n);++i)

using namespace std;
typedef long long ll;
typedef vector<int> vi;
const int NMAX = 100000;
const int MMAX = 100000;
const int k = 200000;
static const int INF = 1<<21;
static const int NIL = -1;
static const int mod = 1e9+7;

double dp[3000][3000]={0};
ll gcd(ll a, ll b){
if(a<b) swap(a,b);
    if(b==0) return a;
    return gcd(b, a%b);
}

vector<vi> pre(NMAX+1);
vi dist(NMAX+1);
vector<bool> visited(NMAX+1);


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



    int a,b,c,d;
    cin >> a >> b >> c;
    d = a+b+c;
    if(d>=22){
        cout << "bust" << endl;
    }else{
        cout << "win" << endl;
    }

    return 0;
}


Measured memory_bytes: 3072
n = int(input())
a = list(map(int,input().split()))

count = sum(a) - 1
tmp = 1
ans = 1

if len(a) == 1:
    if a[0] == 1:
        print(1)
        exit()
    else:
        print(-1)
        exit()
elif a[0] != 0:
    print(-1)
    exit()

for i in range(1,n+1):
    a1 = a[i]
    if count >= tmp:
        count -= tmp
        tmp *= 2
        ans += tmp
    else:
        tmp += count
        count = 0
        ans += tmp
    if tmp >= a1:
        tmp -= a1
    else:
        print(-1)
        exit()

print(ans)


Measured memory_bytes: 20136
#include<iostream>
#include<string>
using namespace std;
int main(){
    int H,W;
    cin>>H>>W;
    char S[60][60];
    for(int i=0;i<60;i++){
        for(int k=0;k<60;k++){
            S[i][k]='0';
        }
    }
    for(int i=1;i<=H;i++){
        for(int k=1;k<=W;k++){
            cin>>S[i][k];
        }
    }
    for(int i=1;i<=H;i++){
        for(int k=1;k<=W;k++){
          int sum=0;
          if(S[i][k]=='.'){
                for(int h=i-1;h<=i+1;h++){
                    for(int g=k-1;g<=k+1;g++){
                        if(S[h][g]=='#'){
                            sum++;
                        }
                    }
                }
                S[i][k]=sum+'0';
            }
        }
    }
    for(int i=1;i<=H;i++){
        for(int k=1;k<=W;k++){
            cout<<S[i][k];
           }
        cout<<endl;
     }
    return 0;



}


Measured memory_bytes: 256