akhauriyash/Code-Regression huggingface dataset:
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) throws ClassNotFoundException, IOException {
		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		System.out.println(180 * (N - 2));
	}
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}


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

if N == 0:
  print(X)
  exit()

P = list(map(int, input().split()))

for i in range(101):
  if X-i not in P:
    print(X-i)
    exit()
  elif X+i not in P:
    print(X+i)
    exit()

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

int main(){
  int n, ans=1;
  cin >> n;
  vector<string> s(n), t(200000, "aaaaaaaaaaa");
  rep(i, n){
    cin >> s[i];
  }
  sort(s.begin(), s.end());
  rep(i, n-1){
    if(s[i]!=s[i+1]){
      ans++;
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 15676
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        Integer[] lArr = new Integer[n];

        for (int i = 0; i < n; i++) {
            lArr[i] = sc.nextInt();
        }

        Arrays.sort(lArr, Collections.reverseOrder());
        int sum = 0;
        for (int i = 0; i < k; i++) {
            sum += lArr[i];
        }

        System.out.println(sum);
    }
}


Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	ll a,b,c,k,ans,x=0;
	cin>>a>>b>>c>>k;
	if(k>=a)
	ans=a;
	else
	{
		ans=k;
		goto here;
	}
	k=k-a;
	k=k-b;
	k=max(k,x);
	if(k>=c)
	ans=ans-c;
	else
	{
		ans=ans-k;
	}
	here:
		cout<<ans<<endl;
}


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

int main() {
  string s;
  cin >> s;

  if (s == "ABC") {
    cout << "ARC" << endl;
  } else {
    cout << "ABC" << endl;
  }

  return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long max=0;
  vector<long long>sintyo(200000);
  long long N;
  cin>>N;
  
  long long total=0;
  
  cin>>sintyo.at(0);
  max=sintyo.at(0);
  for(long long k=1;k<N;k++){
    cin>>sintyo.at(k);
    if(max<=sintyo.at(k)){
      max=sintyo.at(k);
    }
    else{
      total+=max-sintyo.at(k);
    }
  }
  cout<<total;
}
    
    

Measured memory_bytes: 4604
#include<stdio.h>
int main (){
  int a;
  int b;
  scanf("%d%d",&a,&b);
  if (a > b){
    printf("a > b\n");
  }
  else if (a < b){
    printf("a < b\n");
  }
  else{
    printf("a == b\n");
      }
  return 0;
}



Measured memory_bytes: 2044
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!coution!!!! you must use Fprint(out, ) not Print()
	/* --- code ---*/
	n := nextInt()
	nums := nextInts(n)
	ans := 9999999999999999
	for _, v := range nums {
		c := 0
		// fmt.Printf("v:%d\n", v)
		for ; v%2 == 0; v /= 2 {
			c++
			// fmt.Printf("    v=%d\n", v)
		}
		if c == 0 {
			ans = 0
			break
		}
		if c < ans {
			ans = c
		}
	}
	if ans == 9999999999999999 {
		ans = 0
	}
	fmt.Println(ans)
}

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

// Genericsがないので筋肉で...
// interfaceでの取扱がようわからんし
func containStr(arr []string, target string) bool {
	for _, v := range arr {
		if v == target {
			return true
		}
	}
	return false
}

func PrintOut(src interface{}, joinner string) {
	switch reflect.TypeOf(src).Kind() {
	case reflect.Slice:
		s := reflect.ValueOf(src)
		for idx := 0; idx < s.Len(); idx++ {
			fmt.Fprintf(out, "%v", s.Index(idx))
			if idx < s.Len()-1 {
				fmt.Fprintf(out, "%s", joinner)
			} else {
				fmt.Fprintln(out)
			}
		}
	default:
		fmt.Fprintln(out, "fuck")
	}
}

// mapからkeysとvaluesを返す感じのやつ
// なんかしらんけどmap[interface{}]interface{}しか受け付けない。なんのためのinterface{}やねん
// なので呼ぶときのmapはmap[int]stringとかじゃダメ
func splitKeyValue(m map[interface{}]interface{}) (keys, values []interface{}) {
	switch reflect.TypeOf(m).Kind() {
	case reflect.Map:
		s := reflect.ValueOf(m)
		for _, v := range s.MapKeys() {
			keys = append(keys, v)
			values = append(values, s.MapIndex(v))
		}
	default:
		fmt.Fprintln(out, "fuck")
	}
	return
}


Measured memory_bytes: 640
#include <iostream>
#include <set>
#define REP(i, a, n) for(int i = a; i <= n; i++)
using namespace std;


const int SIZE = 200001;
int N, a[SIZE], pos[SIZE];
long ans;
set<int> s;

int main(void) {
  cin >> N;
  REP(i, 1, N) {
    cin >> a[i];
    pos[a[i]] = i;
  }

  s.insert(0);
  s.insert(N + 1);
  ans = 0;

  REP(i, 1, N) {
    set<int>::iterator itr = s.lower_bound(pos[i]);
    int r = *itr - pos[i];
    int l = pos[i] - *(--itr);
    ans += (long) i * r * l;
    s.insert(pos[i]);
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 11136
/////////////////////////////
//* Code By: SANSKAR SETH *//
/////////////////////////////


/*----------HEADER FILES AND TEMPLATES----------*/
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define pob pop_back
#define pf pop_front()
#define puf push_front()
#define mp make_pair
#define loop(i,a,b) for(int i=a ; i<b ; ++i)
#define rloop(i,a,b) for(int i=a ; i>=b ; --i)
#define ip(a) int a; cin>>a
#define ip2(a,b) int a,b; cin>>a>>b
#define ip3(a,b,c) int a,b,c; cin>>a>>b>>c
#define ipv(v,n) vi v(n); loop(i,0,n) cin>>v[i]
#define pv(v) loop(i,0,v.size()) cout<<v[i]<<" "
#define ips(s) string s; cin>>s
#define F first
#define S second
#define si(x) scanf("%lld",&x)
#define ss(s) scanf("%s",s)
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define coutfl(l,p) fixed << setprecision(p) << l

typedef pair<int, int> pii;
typedef unordered_set<int> usi;
typedef set<int> si;
typedef map<int, int>   mii;
typedef map<char, int>  mci;
typedef vector<int>    vi;
typedef vector<char>   vc;
typedef vector<pii>    vpii;
typedef vector<vi>     vvi;

const int mod = 1000000007;
const int N = 5e5;

/*----------SOLUTION----------*/

void solve()
{
	ip(n);
	int flag = 0, c = 0;

	loop(i, 0, n)
	{
		ip2(x, y);
		if (x == y) c++;
		else
		{
			if (c >= 3)
			{
				flag = 1;
				break;
			}
			c = 0;
		}
	}

	if (c >= 3 || flag == 1) cout << "Yes" << endl;
	else cout << "No" << endl;

}

/*----------MAIN FUNCTION----------*/
int32_t main()
{
	fastIO;

#ifndef ONLINE_JUDGE
	freopen("input.txt" , "r" , stdin);
	freopen("output.txt" , "w" , stdout);
#endif
	/*----MAIN PART----*/

	int t;
	// cin >> t;
	t = 1;
	while (t--)
	{
		solve();
	}
	return 0;
}

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

#define FOR(i, j, k) for(int i = j; i < k; i++)
#define REP(i, j) FOR(i, 0, j)
#define fst first
#define snd second
#define pb push_back
#define eb emplace_back
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

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

template <typename T> istream &operator>>(istream &is, vector<T> &vec) {
    for(T &x : vec) {
        is >> x;
    }
    return is;
}

int main() {

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

    int n;
    cin >> n;

    vi a(n);
    cin >> a;

    multiset<int> s;
    int ans = 0;
    for(int x : a) {

        // for(int ss : s) {
        //     cout << ss << " ";
        // }
        // cout << endl;

        auto it = s.upper_bound(-x);
        if(it == s.end()) {
            s.insert(-x);
            ans++;
        } else {
            int n = *it;
            int num = s.erase(*it);
            REP(i, num - 1) { s.insert(n); }
            s.insert(-x);
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 5376
import java.io.*;
public class Main 
{
	public static void main(String[] args) throws IOException 
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
		while(n-- != 0)
		{         
			int score = 0;         
			int[] runner = new int[3];         
			int outCount = 0;         
			while(outCount < 3)         
			{             
				String str = br.readLine();
				if(str.equals("HIT"))             
				{                 
					if(runner[2] == 1)                 
					{                     
						++score;                 
					}                 
				runner[2] = runner[1];                 
				runner[1] = runner[0];                 
				runner[0] = 1;             
				}             
				else if(str.equals("HOMERUN"))             
				{                 
					for(int i = 0; i < 3; ++i)                 
					{                     
						if(runner[i] == 1)                     
						{                         
							++score;                     
						}                     
						runner[i] = 0;                 
					}                 
					++score;             
				}             
				else if(str.equals("OUT"))             
				{                 
					++outCount;             
				}         
			}  
			System.out.println(score); 
		} 
	}
}

Measured memory_bytes: 9344
fun main(args: Array<String>) {
    // Your code here!
    var n = readLine()!!.toDouble()
    var list = readLine()!!.split(" ").map{it.toDouble()}
    
    
    if(n == 2.0 || list.filter{it == list[0]}.count().toDouble() == n){
        println(list.sum() / n)
    }else{
        val answer = list.sorted().reduce { acc, i -> (acc + i) / 2 }
        println(answer)
    }
}


Measured memory_bytes: 36156
#include <bits/stdc++.h>
#include <unistd.h>
 
using namespace std;
 
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P, ll> T;
 
long long int INF = 1e17;
const ll fact_table = 800008;
double Pi = 3.1415926535897932384626;

priority_queue <ll> pql;
priority_queue <P> pqp;
//big priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
// priority_queue <P,vector<P>,greater<P> > pqps;
//small priority queue
//top pop
 
ll dx[8]={1,0,-1,0,1,1,-1,-1};
ll dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "DRUL";
//↓,→,↑,←
 
 
#define p(x) cout<<x<<"\n";
#define el cout<<endl;
#define pe(x) cout<<(x)<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<(x);
#define pb push_back
// #define lb lower_bound
#define ub upper_bound
#define CLEAR(a) a = decltype(a)(); 
#define pc(x) cout << x << ",";
 
 
//ll mod = 998244353;
ll mod = 1000000007;
 
ll rui(ll number1,ll number2){
 
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){
 
    if(number1 > number2){
        swap(number1,number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1,number1);
    }
}
void YES(bool condition){
 
    if(condition){
        p("YES");
    }else{
        p("NO");
    }
    return;
}
void Yes(bool condition){
 
    if(condition){
        p("Yes");
    }else{
        p("No");
    }
    return;
}
 
/*
ll fact[fact_table + 5],rfact[fact_table + 5];
 
void c3_init(){
    fact[0] = rfact[0] = 1;
    for(ll i=1; i<=fact_table; i++){
        fact[i] = (fact[i-1]*i) % mod;
    }
    rfact[fact_table] = rui(fact[fact_table],mod - 2);
    for(ll i=fact_table; i>=1; i--){
       rfact[i-1] = rfact[i] * i;
       rfact[i-1] %= mod;
    }
    return;}
ll c3(ll n,ll r){
    return (((fact[n] * rfact[r]) % mod ) * rfact[n-r]) % mod;}
*/
 
ll n,m,num,sum,ans,a,b,c,d,e,h,r,l,q;
ll k;
ll x[500005], y[500005], z[500005];
char s[500005], t[500005];

ll dfs(ll n){
    if(n == 1){
        return 1ll;
    }else{
        return 1 + 2 * dfs(n / 2);
    }
    return 0;
}

int main(){
    cin >> n;
    p(dfs(n));
    return 0;
}


















Measured memory_bytes: 256
from collections import Counter

n = int(input())
A = list(map(int, input().split()))

count = Counter(A)
sort_count = sorted(count.items())
sort_count.append((0, 0))

best_ans = 0

counter_minus2 = (0, 0)
counter_minus1 = (0, 0)

for i, counter in enumerate(sort_count):
    ans = counter_minus1[1]

    if counter_minus1[0] - counter_minus2[0] == 1:
        ans += counter_minus2[1]

    if counter[0] - counter_minus1[0] == 1:
        ans += counter[1]

    best_ans = max(best_ans, ans)

    counter_minus2 = counter_minus1
    counter_minus1 = counter

print(best_ans)


Measured memory_bytes: 16096
import itertools
N,M = map(int,input().split())
edges = set()
for _ in range(M):
  a,b = map(int,input().split())
  edges.add((a,b))
  edges.add((b,a))

answer = 0

for p in itertools.permutations(range(1,N+1)):
  if p[0] != 1:
    continue
  bl = True
  for i in range(N-1):
    if (p[i], p[i+1]) not in edges:
      bl = False
      break
  if bl:
    answer += 1

print(answer)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int main() {
	int a, b, c, n;

	while(cin >> a >> b >> c) {
		if(a == 0 && b == 0 && c == 0) break;

		cin >> n;

		vector<int> A(n), B(n), C(n), D(n);
		rep(i, n) cin >> A[i] >> B[i] >> C[i] >> D[i];

		bool used[500];
		memset(used, 0, sizeof(used));

		rep(i, n) {
			if(D[i] == 1) {
				used[A[i]] = true;
				used[B[i]] = true;
				used[C[i]] = true;
			}
		}

		set<int> st;
		rep(i, n) {
			if(D[i] == 0) {
				if(used[A[i]] && used[B[i]]) {
					st.insert(C[i]);
				} else if(used[A[i]] && used[C[i]]) {
					st.insert(B[i]);
				} else if(used[B[i]] && used[C[i]]) {
					st.insert(A[i]);
				}
			}
		}

		REP(i, 1, a + b + c + 1) {
			if(used[i]) cout << 1 << endl;
			else if(st.find(i) != st.end()) cout << 0 << endl;
			else cout << 2 << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1216
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;
import java.util.TreeMap;

class Main{
	static int G;
	static int D;
	static int[] p;
	static int[] c;
	static boolean[] used;
	static long ans = 1000000000;


	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);			//文字の入力
		int n = sc.nextInt();
		long[] a = new long[n];
		for(int i = 0;i < n;i++){
			a[i] = sc.nextLong()-(i+1);
		}
		Arrays.sort(a);

		TreeMap<Long, Long> syutugen = new TreeMap<Long, Long>();
		for(int i = 0;i < n;i++){
			syutugen.put(a[i], 1l);
		}
		ArrayList<Long> list = new ArrayList<Long>();
		for(long i:syutugen.keySet()){
			list.add(i);
		}

		long min = a[0];
		long max = a[n-1];

		long ans = 0;
		for(int i = 0;i < n;i++){
			ans += Math.abs(a[i] - min);
		}

//		System.out.println("ans "+ans);
		int p = 0;
		int plus = 0;
		int minus = n;
		while(a[0] == a[p]){
			plus++;
			minus--;
			p++;
			if(p >= n){
				break;
			}
		}
		
		

		for(long i = min+1;i <= max;i++){
//			System.out.println("plus "+plus);
//			System.out.println("minus "+minus);

			long sum = ans;
			sum = sum + (plus -minus);
			if(ans <= sum){
				System.out.println(ans);
				return;
			}


			if(i == a[p]){
				while(i == a[p]){
					plus++;
					minus--;
					p++;
					if(p >= n){
						break;
					}
				}
			}
			ans = sum;
//			System.out.println("sum "+sum);
		}

		System.out.println(ans);




	}


}

class Pair implements Comparable{
	int from;		//p
	int end;		//y
	int num;
	int bango;
	@Override
	public int compareTo(Object other) {
		Pair otherpair = (Pair)other;

		return from - otherpair.from;
	}
}



Measured memory_bytes: 90840
import math
 
def koch(n, x1, y1, x2, y2):
    if n == 0:
        return
   
    angle = math.radians(60)
   
    sx = (2*x1 + x2)/3
    sy = (2*y1 + y2)/3
    tx = (2*x2 + x1)/3
    ty = (2*y2 + y1)/3
    ux = (tx - sx)*math.cos(angle) - (ty - sy)*math.sin(angle) + sx
    uy = (tx - sx)*math.sin(angle) + (ty - sy)*math.cos(angle) + sy
   
    koch(n-1, x1, y1, sx, sy)
    print sx, sy
    koch(n-1, sx, sy, ux, uy)
    print ux, uy
    koch(n-1, ux, uy, tx, ty)
    print tx, ty
    koch(n-1, tx, ty, x2, y2)
   
n = input()
   
p1x = 0.0
p1y = 0.0
p2x = 100.0
p2y = 0.0
   
print p1x, p1y
koch(n, p1x, p1y, p2x, p2y)
print p2x, p2y

Measured memory_bytes: 6656
#include<stdio.h>
int main(){
 int N,K,i,j,n;
 scanf("%d %d",&N,&K);
 int D[K]; 
 for(i=0;i<K;i++)scanf("%d",&D[i]);
 for(i=N;1;i++){
   j=i;
   while(j!=0){
   for(n=0;n<K;n++){
     if(j%10==D[n])break;
   }
   if(j%10==D[n])break;
   j/=10;
   }
 if(j==0)break;
 }
 printf("%d",i);
 return 0;
}

Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]C - Rectangle Cutting
            var line = ReadLine();
            var W = (double)line[0];
            var H = (double)line[1];
            int x = line[2];
            int y = line[3];

            int multi = 0;

            if (x * 2 == W && y * 2 == H)
            {
                multi = 1;
            }

            Console.WriteLine("{0} {1}", W * H / 2, multi);
        }

        static List<int> ReadLine()
        {
            var line = Console.ReadLine();
            var arr = line.Split(' ');

            return arr.Select(x => int.Parse(x)).ToList();
        }
    }
}

Measured memory_bytes: 13396
n=int(input())
p=list(map(int,input().split()))
c=0
for i in range(1,n-1):
    if (p[i-1]<p[i] and p[i]<p[i+1]) or (p[i+1]<p[i] and p[i]<p[i-1]):
        c+=1
print(c)

Measured memory_bytes: 3060
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define NAMELENGTH 11
//#define MAXSIZE 100001

struct ALDS1_3_C{
	
	char name[NAMELENGTH];
	int time;
	
};
typedef struct ALDS1_3_C ALDS;

int front = 0, rear = 0;

void enqueue(ALDS queue[], ALDS data, int n);
ALDS dequeue(ALDS queue[], int idx, int n);

void display(ALDS data[], int from, int to);

int main(void){
	
	int n, q;
	int i;
	int size;
	int doneTime = 0;
	char dummy;
	ALDS temp;
	ALDS *queue = NULL;
	
	//プロセス数nとクオンタムqを入力
	scanf("%d %d", &n, &q);
	
	//初期サイズはn, rearもn
	size = n;
	rear = n;
	
	//nに応じた大きさをqueueに取得
	queue = (ALDS*)malloc((sizeof(ALDS)*n*2)+1);
	
	
	//入力開始
	for(i=0; i<n; i++){
		
		scanf("%s%c%d%c", queue[i].name, &dummy, &queue[i].time, &dummy);
		
	}
	
	
	//ラウンドロビンスケジューリングを開始。 sizeが0になるまで続ける。
	while(size > 0){
		
		//display(queue, front, rear);
		
		//先頭のプロセスの残りtimeがこのクオンタム内で終了する::
		if(queue[front].time <= q){
			
			//doneTimeを先頭プロセスの残りtimeだけ進める
			doneTime += queue[front].time;
			
			//終了したプロセスの名前と終了時刻（doneTime）を出力し、このプロセスを削除
			printf("%s %d\n", queue[front].name, doneTime);
			
			dequeue(queue, front, n);
			
			size--;
			
		}
		
		//先頭のプロセスの残りtimeがこのクオンタム内で終了しない::
		else{
			
			//doneTimeをクオンタムだけ進める
			doneTime += q;
			
			//先頭プロセスの残りtimeをクオンタム分減らす
			queue[front].time -= q;
			
			//先頭プロセスはキューの末尾へと移動する
			temp = dequeue(queue, front, n);
			
			enqueue(queue, temp, n);
			
		}
		
	}
	
	free(queue);
	
	return 0;
	
}



void enqueue(ALDS queue[], ALDS data, int n){
	
	queue[rear] = data;
	rear++;
	
	if(rear >= 2*n){
		
		rear = 0;
		
	}
	
	return;
	
}



ALDS dequeue(ALDS queue[], int idx, int n){
	
	ALDS ret = queue[idx];
	front++;
	
	if(front >= 2*n){
		
		front = 0;
		
	}
	
	return ret;
	
}


void display(ALDS data[], int from, int to){
	
	int i;
	
	printf("front::%d, rear::%d\n", from, to);
	
	printf("-----------------------------------------\n");
	
	for(i=from; i<to; i++){
		
		printf("%s %d\n", data[i].name, data[i].time);
		
	}
	
	printf("-----------------------------------------\n");
	
}

Measured memory_bytes: 1944
import sys
import re
import math
import collections
import decimal
import bisect
import itertools
import fractions

import copy

# import heapq
# from collections import deque
# import decimal

sys.setrecursionlimit(10000001)
INF = sys.maxsize
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===

def main():
    n, y = ns()

    tmp = y // 1000 - n
    calc = lambda x, y: 9 * x + 4 * y

    for x in range(2000 + 1):
        for y in range(2000 + 1):
            if calc(x, y) == tmp:
                if n - x - y > -1:
                    print(x, y, n - x - y)
                    exit(0)

    print(-1,-1,-1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 61932
nums = map(int, list(raw_input()))
ans = None
for op1 in ("+", "-"):
  for op2 in ("+", "-"):
    for op3 in ("+", "-"):
      x = nums[0]
      x += nums[1] * (1 if op1 == "+" else -1)
      x += nums[2] * (1 if op2 == "+" else -1)
      x += nums[3] * (1 if op3 == "+" else -1)
      if x == 7:
        ans = str(nums[0])+op1+str(nums[1])+op2+str(nums[2])+op3+str(nums[3])+"=7"
    if ans:
      break
  if ans:
    break
print ans


Measured memory_bytes: 2568
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
//#include <functional> // for less
//using namespace __gnu_pbds;
using namespace std;
typedef long long  L;

#define max_(x, y) (((x) > (y)) ? (x) : (y))
#define min_(x, y) (((x) < (y)) ? (x) : (y))
#define ___ ios_base::sync_with_stdio(false);cin.tie(NULL);
#define Mx 200001
#define inf 1e15
const L MOD = 1e9+7;
const double pi = 2 * acos (0.0);

/*------------------------------Graph Moves----------------------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*---------------------------------------------------------------------*/


//typedef tree<L,null_type,less<L>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

L a1,a2,a3,b1,b2,b3,c,c1,c2,c3,d,d1,d2,d3,d4,d5,e1,e2,e3,f,h,k,l,m,n,m1,m2,n1,n2,o,p,p1,p2,p3,p4,q,q1,q2,q3,q4,r,s,t,
u,v,x,y,z,sum,mx=-inf,mn=inf,flg,flg1,flg2,id1,id2,id3,id4,lim;

//double rat;
L A[Mx+5],B[Mx+5];

char str[Mx];

vector<L>V,V1;
set<L>S;
map<L,L>Mp;
priority_queue<L>Pq;

int main()
{
    L id=0;
    for(int i=0;i<5;i++){
        scanf("%d",&n);
        if(n==0)id=i+1;
    }
    printf("%lld\n", id);
    return 0;
}
/// empty() lld I64d push_back() top() pop() insert() upper_bound() lower_bound() memset() max() min() scanf continue


Measured memory_bytes: 3720
using System;
using System.Collections.Generic;
using System.Linq;

namespace ABC176
{
    class Program
    {
        private static int[] hw;
        private static char[,] map;
        private static long[,] ans;
        private static Queue<(int y, int x, int num)> que;

        static void Main()
        {
            hw = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var start = Console.ReadLine().Split(' ').Select(v => int.Parse(v) - 1).ToArray();
            var goal = Console.ReadLine().Split(' ').Select(v => int.Parse(v) - 1).ToArray();
            map = new char[hw[0], hw[1]];
            for (var i = 0; i < hw[0]; i++)
            {
                var tmp = Console.ReadLine();
                for (var j = 0; j < hw[1]; j++)
                {
                    map[i, j] = tmp[j];
                }
            }

            ans = new long[hw[0], hw[1]];

            que = new Queue<(int y, int x, int num)>();
            Dfs(start[0], start[1], 1);

            while (que.Count > 0)
            {
                var q = que.Dequeue();
                for (var i = -2; i <= 2; i++)
                {
                    for (var j = -2; j <= 2; j++)
                    {
                        if (0 <= q.y + i && q.y + i < hw[0] && 0 <= q.x + j && q.x + j < hw[1] && (ans[q.y + i, q.x + j] == 0 || ans[q.y + i, q.x + j] > q.num + 1) && map[q.y + i, q.x + j] == '.')
                        {
                            Dfs(q.y + i, q.x + j, q.num + 1);
                        }
                    }
                }
            }

            Console.WriteLine(ans[goal[0], goal[1]] - 1);
        }

        static void Dfs(int y, int x, int num)
        {
            if (ans[y, x] != 0 && ans[y, x] <= num) return;

            ans[y, x] = num;
            que.Enqueue((y, x, num));

            if (y + 1 < hw[0] && ans[y + 1, x] == 0 && map[y + 1, x] == '.')
                Dfs(y + 1, x, num);
            if (x + 1 < hw[1] && ans[y, x + 1] == 0 && map[y, x + 1] == '.')
                Dfs(y, x + 1, num);
            if (0 <= y - 1 && ans[y - 1, x] == 0 && map[y - 1, x] == '.')
                Dfs(y - 1, x, num);
            if (0 <= x - 1 && ans[y, x - 1] == 0 && map[y, x - 1] == '.')
                Dfs(y, x - 1, num);
        }
    }
}

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

int main() {
  int n;
  string s;
  cin >> n >> s;
  for (int i = 0; i < s.size(); i++) {
    int x = (s.at(i) - 'A' + n) % 26;
    char c = 'A' + x;
    cout << c;
  }
  cout << endl;
}

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

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

	int t;
	cin >> t;
	string sh; cin >> sh;
	if (t % 2 != 0)
	{
		cout << "No" << endl;
	}
	else
	{
		for (int i = 0, j = t / 2; i < t / 2; ++i, j++)
		{
			if (sh[i] != sh[j])
			{
				cout << "No" << endl;
				return 0;
			}
		}
		cout << "Yes" << endl;
	}
	return 0;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint ungigned
#define db double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pli pair<ll,int>
#define vi vector<int>
#define vpi vector<pii >
#define IT iterator

#define PB push_back
#define MK make_pair
#define LB lower_bound
#define UB upper_bound
#define BG begin
#define ED end

#define For(i,j,k) for (int i=(j);i<=(int)k;i++)
#define Rep(i,j,k) for (int i=(j);i>=(int)k;i++)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));

#define LS3 k*2,l,mid
#define RS3 k*2+1,mid+1,r
#define LS5 k*2,l,mid,x,y
#define RS5 k*2+1,mid+1,r,x,y
#define GET pushdown(k);int mid=(l+r)/2
using namespace std;
/*int k;

int main(){
	scanf("%d",&k);
	ll ans=1,t=1,v=1;
	while (k--){
		printf("%lld\n",ans);
		if ((++t)==10) v=v*10,t=1;
		ans+=v; 
	}
}*/
int n,k;
int main(){
	scanf("%d%d",&n,&k);
	printf("%d\n",(n-1)/(k-1)+((n-1)%(k-1)!=0));
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#define flush fflush(stdout)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pl;
const int mod = (int)1e9 + 7, INF = (int)1e9;
const int di[4] = { 1,0,-1,0 }, dj[4] = { 0,1,0,-1 };


int main(void) {
    ll x, ans;

    scanf("%lld", &x);

    ans = x / 11 * 2;
    if (x % 11 > 0)
    {
        if (x % 11 > 6)
            ans += 2;
        else
            ans++;
    }

    printf("%lld\n", ans);

    return 0;
}

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

int main(void){
     int n[100];
     int i=0;
     int d;
     while(cin >> d,!cin.eof()){
	  
	  if(d == 0){
	       cout << n[i-1] << endl;
	       i = i-1;
	  }else{
	       n[i] = d;
	       i = i+1;
	  }
//	  cout << endl;
//	  for(int i=0;i<10;i++){
//	       cout << n[i-1] << endl;
//	  }
//	  cout << endl;
     }

     return 0;
}

Measured memory_bytes: 0
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <iostream>
#include <set>
#include <map>
#include <string>
#include <algorithm>

using namespace std;

typedef long long int ll;
typedef pair<int, int> Pii;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<double, double> Pdd;
typedef pair<ll, ll> P;
typedef pair<P, ll> PP;

const ll mod = 1e9+7;
const int INF = 2e9;
const double epsilon = 1e-7;
const double PI = 3.1415926535;

ll mi(ll x, ll y){
    if(x<y)return x;
    return y;
}

int a[] = {1, 6, 9, 36, 81, 216, 729, 1296, 6561, 7776, 46656, 59049};
int dp[100001];
int main(void){
    int n; cin >> n; dp[0] = 0;
    for(int i = 1;i <= n;i++){
        int d = dp[i-1]+1;
        for(int j = 1;j < 12;j++){
            if(i < a[j])break;
            d = mi(d, dp[i-a[j]]+1);
        }
        dp[i] = d;
    }
    cout << dp[n] << endl;
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define all(v) v.begin(),v.end()

using namespace std;
typedef long long ll;




int main()
{
    
    int N;
    cin >> N;
    string S;
    cin >> S;
    
    int ans = 1;
    
    for (int i = 1; i < N; i++) {
        if(S[i] == S[i-1]) continue;
        else ans += 1;
    }
    
    cout << ans << endl;
    
    
    
    
    return 0;
}


Measured memory_bytes: 512
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int old ;
		boolean ans = false;
		int count = 0;
		for(int i = 0;i < n;++i){
			int d_1 = scan.nextInt();
			int d_2 = scan.nextInt();

			if (d_1 == d_2){
				count++;
				if(count == 3) ans = true;
			}else{
				count = 0;
			}
		}
		System.out.print(ans?"Yes":"No");

	}
}


Measured memory_bytes: 36040
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		  String[] ar = a.split("");
		for (String s : ar) {
			if(s.equals("1")) {
				System.out.print(9);
			}else {
				System.out.print(1);
			}
		}
	}

}

Measured memory_bytes: 22228
N, Y = list(map(int, input().split()))

z = Y//1000 - N
result = [-1, -1, -1]

for m in range(z//9 + 1):
    if (z - 9*m)%4 == 0:
        g = (z - 9*m)//4
        if m + g <= N:
            result = [m, g, N-m-g]
            break

print(' '.join(map(str, result)))

Measured memory_bytes: 3060
import java.math.BigDecimal

fun main(args:Array<String>) {
    val person = readLine()!!.toInt()
    var total = 0.0.toDouble()
    var totalBitcoin = BigDecimal.ZERO
    (1..person).forEach {
        val (v,u) = readLine()!!.split(" ")
        if(u == "JPY") {
            total += v.toInt()
        } else {
            totalBitcoin += BigDecimal(v.toDouble())
        }
    }
    val ans = BigDecimal(total) + (totalBitcoin * BigDecimal(380000))
    println(ans.toPlainString())
}


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

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, a, b) for (int (i) = (a); (i) <= (b); (i)++)
#define ROF(i, a, b) for (int (i) = (a); (i) >= (b); (i)--)
#define REP(i, n) FOR(i, 0, (n)-1)
#define sqr(x) ((x) * (x))
#define all(x) (x).begin(), (x).end()
#define reset(x, y) memset(x, y, sizeof(x))
#define uni(x) (x).erase(unique(all(x)), (x).end());
#define BUG(x) cerr << #x << " = " << (x) << endl
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define _1 first
#define _2 second
#define chkmin(a, b) a = min(a, b)
#define chkmax(a, b) a = max(a, b)

const int maxn = 5123;

int g[2], s[2], b[2];
ll n, dp[maxn * maxn];

ll solve(int n, int now, int nxt) {
  FOR(i, 1, n) dp[i] = i;
  ll ret = n;
  FOR(i, 1, n) {
    if (i >= g[now]) chkmax(dp[i], dp[i - g[now]] + g[nxt]);
    if (i >= s[now]) chkmax(dp[i], dp[i - s[now]] + s[nxt]);
    if (i >= b[now]) chkmax(dp[i], dp[i - b[now]] + b[nxt]);
    chkmax(ret, dp[i]);
  }
  return ret;
}

int main() {
  scanf("%lld", &n);
  REP(i, 2) scanf("%d%d%d", g + i, s + i, b + i);
  n = solve(n, 0, 1);
  n = solve(n, 1, 0);
  printf("%lld", n);
}


Measured memory_bytes: 196864
#pragma region includes, macros
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <map>
#include <set>
#include <list>
#include <unordered_set>
#include <unordered_map>

using namespace std;

typedef int64_t i64;
typedef pair<i64, i64> P;

template<class T>
const T INF = numeric_limits<T>::max();
template<class T>
const T SINF = numeric_limits<T>::max() / 10;
static const i64 MOD = 1000000007;

//int dx[5] = {-1,0,0,0,1}, dy[5] = {0,-1,0,1,0};
//int dx[8] = {-1,0,1,1,1,0,-1,-1}, dy[8] = {1,1,1,0,-1,-1,-1,0};
//int dx[9] = {-1,0,1,1,1,0,-1,-1,0}, dy[9] = {1,1,1,0,-1,-1,-1,0,0};

struct edge {
    i64 from, to, cost;
    edge(i64 to, i64 cost) : from(-1), to(to), cost(cost) {}
    edge(i64 src, i64 to, i64 cost) : from(src), to(to), cost(cost) {}
};

// http://beet-aizu.hatenablog.com/entry/2018/04/08/145516
template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template<typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}

template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T& t, const V& v) { t = v; }

template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T& t, const V& v) {
    for (auto& e : t) fill_v(e, v);
}
//

#pragma endregion

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

int main() {
    i64 n;
    cin >> n;
    i64 ans = 0, a = 0, b = 0, x = 0;
    vector<string> s(n);
    for (int i = 0; i < n; ++i) {
        cin >> s[i];
        for (int j = 0; j < s[i].length() - 1; ++j) {
            if(s[i][j] == 'A' && s[i][j + 1] == 'B') ans++;
        }
        if(s[i][0] == 'B') ++b;
        if (s[i][s[i].length() - 1] == 'A') ++a;
        if(s[i][0] == 'B' && s[i][s[i].length() - 1] == 'A') ++x;

    }
    if(a != 0 && a == x && b == x) cout << ans + x - 1 << endl;
    else cout << ans + min(min(a, b), n - 1) << endl;
}

Measured memory_bytes: 768
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<bitset>
#include<deque>
#include<functional>
#include<iterator>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<utility>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define a first
#define b second
#define sz(x) (ll)((x).size())
#define pb push_back
#define mp make_pair
#define bg begin()
#define ed end()
#define all(x) (x).bg,(x).ed
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep1(i,n) for(ll i=1;i<=(n);i++)
#define rrep(i,n) for(ll i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(ll i=(n);i>=1;i--)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
const ll MOD=1000000007;
const ll INF=1000000000000000;
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;}
ll maxx(ll x,ll y,ll z){return max(max(x,y),z);}
ll minn(ll x,ll y,ll z){return min(min(x,y),z);}
ll gcd(ll x,ll y){if(x%y==0) return y;else return gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll digsz(ll x){if(x==0) return 1;else{ll ans=0;while(x){x/=10;ans++;}return ans;}}
ll digsum(ll x){ll sum=0;while(x){sum+=x%10;x/=10;}return sum;}
vector<ll> pw2(62,1);vector<ll> pw10(19,1);

int main(){
    {rep1(i,61) pw2[i]=2*pw2[i-1];}
    {rep1(i,18) pw10[i]=10*pw10[i-1];}
    
    ll N; cin>>N;
    vector<ll> A(N);
    rep(i,N){
        cin>>A[i];
    }
    ll ans=INF;
    FOR(i,-100,101){
        ll cost=0;
        rep(j,N){
            cost+=(A[j]-i)*(A[j]-i);
        }
        chmin(ans,cost);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
using namespace std;
typedef long long ll;

const ll INF=(ll)2e10;

int main(){
    ll a,b,q;
    cin>>a>>b>>q;
    vector<ll> s(a),t(b);
    rep(i,a) cin>>s[i];
    rep(i,b) cin>>t[i];
    rep(i,q){
        ll x;
        cin>>x;
        auto itrsl=lower_bound(rall(s),x,greater<ll>());
        auto itrsr=lower_bound(all(s),x);
        auto itrtl=lower_bound(rall(t),x,greater<ll>());
        auto itrtr=lower_bound(all(t),x);
        ll sl,sr,tl,tr;
        sl=max(x-*itrsl,(distance(s.rend(),itrsl)==0)*INF);
        sr=max(*itrsr-x,(distance(s.end(),itrsr)==0)*INF);
        tl=max(x-*itrtl,(distance(t.rend(),itrtl)==0)*INF);
        tr=max(*itrtr-x,(distance(t.end(),itrtr)==0)*INF);
        cout<<min({max(sl,tl),max(sr,tr),min(sl,sr)+min(tl,tr)+min({sl,sr,tl,tr})})<<endl;
    }
    return 0;
}

Measured memory_bytes: 4828
use std::io::Read;
 
fn main() {
    let mut buf = String::new();
 
    // 標準入力から全部bufに読み込む
    std::io::stdin().read_to_string(&mut buf).unwrap();
 
    // 読み込んだStringを空白で分解する
    let mut iter = buf.split_whitespace();
 
    let n: usize = iter.next().unwrap().parse().unwrap();
    let x: usize = iter.next().unwrap().parse().unwrap();
    let t: usize = iter.next().unwrap().parse().unwrap();
 
    println!("{}", (n + x - 1) / x * t);
 
}

Measured memory_bytes: 2128
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 2e5 + 7;
int a[MAXN], b[MAXN];
int main() {
    int n, k; scanf("%d %d", &n, &k);
    for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
    for (int step = 1, ok = 0; step <= k && !ok; step++) {
        for (int i = 1; i <= n; i++) b[i] = 0;
        for (int i = 1; i <= n; i++) {
            int l = max(1, i - a[i]), r = min(n, i + a[i]);
            b[l]++; b[r + 1]--;
        }
        int cnt = 0;
        for (int i = 1; i <= n; i++) {
            b[i] += b[i - 1], a[i] = b[i];
            if (a[i] == n) cnt++;  
        }
        if (cnt == n) ok = 1;
    }
    for (int i = 1; i <= n; i++) printf("%d%c", a[i], " \n"[i == n]);
    return 0;
}

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

#define endl "\n"
#define all(V) V.begin(),V.end()
#define see(x) cerr << #x << " = " << x << "\n";
#define Unique(V) sort(all(V)),V.erase(unique(all(V)),V.end())
typedef long long int LL;
typedef pair <int,int> pii;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const double PI = acos(-1.0);
const long long INF = 1e18;
const int N = 1e5 + 5;

int n , k , a[ N ];
int dp[ N ];

int main( ) {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
        cin >> n >> k;
        for( int i = 1; i <= n; i++ ) cin >> a[i];
        for( int i = 1; i <= n; i++ ) dp[i] = inf;
        dp[n] = 0;
        for( int i = n; i >= 1; i-- ) {
                for( int j = 1; j <= k; j++ ) {
                        if( i + j <= n ) {
                                dp[i] = min( dp[i] , dp[i+j] + abs(a[i+j] - a[i]) );
                        }
                }
        }
        cout << dp[1] << endl;
        return 0;
}









Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main(void){
    int N,M; cin>>N>>M;
    const int nmmax=50;
    char A[nmmax][nmmax],B[nmmax][nmmax];
    for(int y=0;y<N;++y){
        for(int x=0;x<N;++x){
            cin >> A[y][x];
        }
}
    for(int y=0;y<M;++y){
        for(int x=0;x<M;++x){
            cin >> B[y][x];
        }
}
    bool exist=false;
    for(int ly=0;ly<N;++ly){
        for(int lx=0;lx<N;++lx){
            if(ly+M-1>=N or lx+M-1>=N) continue;
            bool match=true;
            for(int y=0;y<M;++y){
                for(int x=0;x<M;++x){
                    if(A[ly+y][lx+x]!=B[y][x]) match=false;
} }
            if(match) exist=true;
        }
}
    if(exist)
        cout << "Yes" << endl;
else
        cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
using namespace std;
namespace adaptor = boost::adaptors;

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
typedef long long ll;

void Main()
{
	string w;
  	cin >> w;
  
  	int count = 0;
  	int wsz = w.size();
	int rem = wsz;
  
  	if (wsz % 2 == 1){
    	cout << "No" << endl;
      	return;
    }
  	else {
  		rep(j,26){
          	count = 0;
          	rep(i,wsz){
				if (w[i] == 'a' + j){
                	count++;
            	}
            }
          	if(count%2 == 1){
              	cout << "No" << endl;
                return;
            }
          	rem -= count;
          	if(rem == 0){break;}
        }
    	cout << "Yes" << endl;
    }
	return;
}

int main()
{
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	Main();
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <queue>
#include <cmath>

using namespace std;
using ll = long long;
using ull = unsigned long long;

void ABC100C()
{
	int N;
	cin >> N;
	ll ct = 0;
	for (int i = 0; i < N; ++i)
	{
		ll x;
		cin >> x;
		while ((x & 1) == 0)
		{
			++ct;
			x = x >> 1;
		}
	}
	cout << ct << endl;
}
int main()
{
	ABC100C();
	return 0;
}


Measured memory_bytes: 384
A, B, K = map(int, input().split())

N = A if (A > B) else B

D = []
for n in range(1, N+1):
  if (A % n != 0):
    continue
  else:
    if (B % n != 0):
      continue
    else:
      D.append(n)

D.sort(reverse=True)
print(D[K - 1])

Measured memory_bytes: 3060
import java.util.Scanner;

class Dice {
	private int up;
	private int front;
	private int right;
	private int left;
	private int back;
	private int down;
	
	Dice(int up,int front,int right,int left,int back,int down){
		this.up=up;	this.front=front; this.right=right;
		this.left=left; this.back=back; this.down=down;
	}
	
	void printRight(){	System.out.println(right); }
	
	void rotate(char c){
		int temp;
		if(c=='E'){
			temp=up; up=left; left=down; down=right; right=temp;
		}
		
		if(c=='N'){
			temp=up; up=front; front=down; down=back; back=temp;
		}
		
		if(c=='S'){
			temp=up; up=back; back=down; down=front; front=temp;
		}
		
		if(c=='W'){
			temp=up; up=right; right=down; down=left; left=temp;
		}
	}
	
	void all_rotate(int u,int f){
		for(int i=0;i<4;i++){
			rotate('E');
			for(int j=0;j<4;j++){
				rotate('N');
				for(int k=0;k<4;k++){
					rotate('E');
					if(up==u && front==f){
						printRight();
						return;
					}
				}
			}
		}
	}
			
}


class Main {
	public static void main(String[] args){
		Scanner scan=new Scanner(System.in);
		
		Dice d=new Dice(scan.nextInt(),scan.nextInt(),scan.nextInt(),scan.nextInt(),scan.nextInt(),scan.nextInt());
		
		int n=scan.nextInt();
		for(int i=0;i<n;i++){
			int up=scan.nextInt();
			int front=scan.nextInt();
			d.all_rotate(up,front);
		}
	}
}


Measured memory_bytes: 26076
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Scanner;

public class Main {


	static class Edge{
		int to;
		int dist;
		public Edge(int to, int dist) {
			this.to = to;
			this.dist = dist;
		}
	}

	static void dfs(List<Edge>[] g, int[] color, int dist_from_0, int start) {
		color[start] = dist_from_0 % 2;
		for(Edge next : g[start]) {
			if(color[next.to] != -1) continue;
			dfs(g, color, (dist_from_0 + next.dist) % 2, next.to);
		}
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] color = new int[n];
		Arrays.fill(color, -1);
		List<Edge>[] g = new ArrayList[n + 1];
		for(int i = 0; i < n; i++) {
			g[i] = new ArrayList<>();
		}

		for(int i = 0; i < n - 1; i++) {
			int u = sc.nextInt() - 1;
			int v = sc.nextInt() - 1;
			int w = sc.nextInt();
			g[u].add(new Edge(v, w));
			g[v].add(new Edge(u, w));
		}

		dfs(g, color, 0, 0);
		for(int value : color) {
			System.out.println(value);
		}
		sc.close();
	}
}

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

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

	vector<vector<double>> x(n, vector<double>(d));

	for (int i = 0; i < n; i++) {
		for (int k = 0; k < d; k++) {
			cin >> x[i][k];
		}
	}

	int ans = 0;
	for (int i = 0; i < n - 1; i++) {
			
		for (int j = i + 1; j < n; j++) {
			
			double tmp = 0;
			for (int k = 0; k < d; k++) {

				tmp += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
			}
			tmp = sqrt(tmp);
			if (tmp == floor(tmp)) ans++;

		}
	
	}
	
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256