akhauriyash/Code-Regression huggingface dataset:
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
# 一次元累積和
from itertools import accumulate
from bisect import bisect_left, bisect_right

import re
# import numpy as np
# from scipy.misc import comb

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
def line_inpl(x): return [i_inpl() for _ in range(x)]

INF = int(1e18)
MOD = int(1e9)+7 # 10^9 + 7

# W行H列, x[W][H]
def create_grid(W, H, value = 0):
    return [[ value for _ in range(H)] for _ in range(W)]

########

N = i_inpl()
A = l_inpl()
B = l_inpl()

ans = 0

for i in range(N):
    if B[i] >= A[i]:
        ans += A[i]
        diff = B[i] - A[i]
        if diff >= A[i+1]:
            ans += A[i+1]
            A[i+1] = 0
        else:
            ans += diff
            A[i+1] -= diff
    else:
        ans += B[i]

print(ans)
# N = i_inpl()
# p = l_inpl()

# l = list(range(1, N+1))

# cnt = 0
# for pi, li in zip(p, l):
#     if pi != li:
#         cnt += 1

# if cnt == 2 or cnt == 0:
#     print("YES")
# else:
#     print("NO")

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

int S[505][505];

int main() {
    int N, M, Q, l, r;
    scanf("%d %d %d", &N, &M, &Q);
    for (int i = 0; i < M; i++) {
        scanf("%d %d", &l, &r);
        S[l][r]++;
    }
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= N; j++) {
            S[i][j] += S[i-1][j] + S[i][j-1] - S[i-1][j-1];
        }
    }
    for (int i = 0; i < Q; i++) {
        scanf("%d %d", &l, &r);
        int ans = S[r][r] - S[l-1][r] - S[r][l-1] + S[l-1][l-1];
        printf("%d\n", ans);
    }
    return 0;
}

Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
int64_t MOD=1000000007;

int main() {
  int64_t A;
  string S;
  cin>>A>>S;
  int64_t B;
  if(S.size()==4)B=(S.at(0)- '0')*100+(S.at(2)- '0')*10+(S.at(3)- '0');
  if(S.size()==5)B=(S.at(0)- '0')*1000+(S.at(1)- '0')*100+(S.at(3)- '0')*10+(S.at(4)- '0');
  cout<<A*B/100;
}


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

cnt1 = 0
cnt2 = 0
cnt4 = 0

for i in range(n):
    if a[i]%2==1:
        cnt1 +=1
    elif a[i]%4==0:
        cnt4 +=1
    else:
        cnt2 +=1

if cnt2==0:
    if cnt4+1>=cnt1:
        print("Yes")
    else:
        print("No")
else:
    if cnt4>=cnt1:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 63472
from math import ceil


def enough(x):
    total = 0
    for hi in h:
        total += max(0, ceil((hi - B * x) / (A - B)))
        if total > x:
            return False
    return True

N, A, B = map(int, input().split())
h = [int(input()) for _ in range(N)]
h.sort()

l, r = (h[0] // A), (h[-1] // B + 1)
while l + 1 < r:
    m = (l + r) // 2
    if enough(m):
        r = m
    else:
        l = m

print(l if enough(l) else r)


Measured memory_bytes: 51288
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int W, H, x, y, r;
    cin >> W >> H >> x >> y >> r;
    if (x >= r && x + r <= W && y >= r && y + r <= H ) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}



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

struct edge {
  int from, to, cost;
};

int main(){
  int l;
  cin >> l;
  if(l == 2) {
    cout << 2 << " " << 2 << endl;
    cout << 1 << " " << 2 << " " << 0 << endl;
    cout << 1 << " " << 2 << " " << 1 << endl;
    return 0; 
  }
  int n = l -1;
  vector<int> a;
  while(n > 1) {
    a.push_back(n%2);
    n /= 2;
  }
  reverse(a.begin(),a.end());
  int s = a.size();
  vector<edge> v;
  rep(i,s) {
    v.push_back(edge{i,i+1,1<<(s-1-i)});
    v.push_back(edge{i,i+1,0});
  }
  int b = 1<<s;
  rep(i,s) {
    if(a[i] == 1) {
      v.push_back(edge{0,i+1,b});
      b += 1<<(s-i-1);
    }
  }
  v.push_back(edge{0,s,b});
  cout << s+1 << " " << v.size() << endl;
  for(auto k : v) {
    cout << k.from+1 << " " << k.to+1 << " " << k.cost << endl;
  } 
  return 0;
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.TreeSet;
import java.util.Iterator;
import java.util.Comparator;


public class Main{

    static int NN;
    static int MM;

    static TreeSet<Num> solution;
    static List<TreeSet<Num>> kk;
    public static void main(String args[]) {
       
        Scanner sc = new Scanner(System.in);
        NN= sc.nextInt();
        MM= sc.nextInt();
        solution = new TreeSet<>(new sortIndex());
        kk = new ArrayList<>();
        for (int i = 0; i < NN; i++) {
            kk.add(new TreeSet<>(new sortNum()));
        }
        for (int i = 0; i < MM; i++) {
            int n =sc.nextInt();
            kk.get(n-1).add(new Num(n,sc.nextInt(),i,null));
        }
        for (int i = 0; i < NN; i++) {
            format(kk.get(i));
        }
        Iterator it = solution.iterator();
        while (it.hasNext()) {
            Num n = (Num)it.next();
            System.out.println(n.getStr());
        }
    }
    static void format(TreeSet<Num> list){
        Iterator it = list.iterator();
        int i = 0;
        while (it.hasNext()){
            Num n = (Num)it.next();
            n.setStr(String.format("%06d", n.N) + String.format("%06d", (++i)));
            solution.add(n);
        }
    }
    static class Num{
        public int N;
        public int M;
        public int oldIndex;
        public String str;
        public String getStr() {
            return str;
        }
        public void setStr(String str) {
            this.str = str;
        }
        public Num(int n, int m, int oldIndex, String str) {
            N = n;
            M = m;
            this.oldIndex = oldIndex;
            this.str = str;
        }
    }
    static class sortNum implements Comparator<Num>{
        @Override
        public int compare(Num o1, Num o2) {
            return o1.M-o2.M;
        }
    }
    static class sortIndex implements Comparator<Num>{
        @Override
        public int compare(Num o1, Num o2) {
            return o1.oldIndex-o2.oldIndex;
        }
    }

}

Measured memory_bytes: 184860
import sys
from collections import deque
sys.setrecursionlimit(1000000007)
input = sys.stdin.readline

MOD = 1000000007

class Node:
    def __init__(self):
        self.check = False
        self.link = []

    def color(self, K):
        self.check = True
        ret = 1
        # 子の塗り分け方を計算
        for i in range(len(self.link)-1):
            ret *= (K - 2) - i
            ret %= MOD
        # 子の子の塗り分け方を掛ける
        for node in self.link:
            if not node.check:
                ret *= node.color(K)
                ret %= MOD
        return ret

def main():
    N, K = map(int, input().split())
    if N == 1:
        print(K)
    else:
        nodes = [Node() for i in range(N+1)]
        for i in range(N-1):
            a, b = map(int, input().split())
            a -= 1; b -= 1;
            nodes[a].link.append(nodes[b])
            nodes[b].link.append(nodes[a])
        root = nodes[0]
        root.check = True
        ans = K
        for i in range(1, len(root.link)+1):
            ans *= (K-i)
            ans %= MOD
        for node in root.link:
            ans *= node.color(K)
            ans %= MOD
        print(ans)

if __name__ == "__main__":
    main()


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

#define mp make_pair
#define fst first
#define snd second

using namespace std;

typedef int32_t i32;
typedef uint32_t u32;
typedef int64_t i64;
typedef uint64_t u64;
typedef pair<int,int> pii;
typedef pair<i64,int> pli;
typedef pair<int,i64> pil;
typedef pair<i64,i64> pll;
typedef vector<int> vi;
typedef vector<i64> vl;

template <typename T>
T id(T b) {return b;};
template <class It>
bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It>
bool any(It f,It l){return std::any_of(f,l,id<bool>);}

int n,k;

int main()
{
  cin >> n >> k;
  if (1+2*(k-1) <= n)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#define MAX 40

struct node
{
	int p;
	int l, r;
} typedef node;

int CreateTree(int, int, int, int);
int Position(int, int, int[], int);
void Postorder(int, int);

int P[MAX];
int I[MAX];
node N[MAX];

int main()
{
	int i;
	int n;
	int root;
	
	scanf("%d", &n);
	for(i = 0; i < n; i++)
	{
		scanf("%d", &P[i]);
	}
	for(i = 0; i < n; i++)
	{
		scanf("%d", &I[i]);
	}
	
	root = CreateTree(-1, n, 0, 0);
	
	Postorder(root, n);
	
	return 0;
}

int CreateTree(int parent, int n, int head_P, int head_I)
{
	int root;
	int root_P, root_I;
	int n_l, n_r;
	
	root = P[head_P];
	
	if(n == 0) return -1;

	root_P = head_P;
	root_I = Position(n, head_I, I, root);
	
	n_l = root_I - head_I;
	n_r = n - n_l - 1;
	
	N[root].p = parent;
	N[root].l = CreateTree(root, n_l, root_P + 1, head_I);
	N[root].r = CreateTree(root, n_r, root_P + 1 + n_l, root_I + 1);
	
	return root;
}

int Position(int n, int h, int A[], int s)
{
	int i;
	
	for(i = h; i < h + n; i++)
	{
		if(A[i] == s) return i;
	}
	return -1;
}

void Postorder(int id, int n)
{
	static int count = 0;
	
	if(id == -1) return;
	
	Postorder(N[id].l, n);
	Postorder(N[id].r, n);
	
	count++;
	if(count != n) printf("%d ", id);
	else printf("%d\n", id);
}

Measured memory_bytes: 596
#include <iostream>
#include <iterator>
#include <map>
#include <bits/stdc++.h>

using namespace std;

int main()
{
    map<string, int> mp;

    vector<int> v;
    int num, num1, num2, vec;
    string str;
    scanf("%d", &num);

    for(int i = 0; i < num; i++){
        scanf("%d", &num1);
        if(num1 == 0){
            cin >> str >> num2;
            mp[str] = num2;
        }
        else if(num1 == 1){
            cin >> str;
            if(mp.find(str) == mp.end()){
                v.push_back(0);
            }
            else{
                vec = mp[str];
                v.push_back(vec);
            }

        }
//        else if(num1 == 2){
//            cin >> str;
//            mp.erase(str);
//        }
    }

    for (auto val : v){
            if(!v.empty()){
                cout << val<< "\n";
            }

    }

    return 0;
}


Measured memory_bytes: 27832
import sys
sys.setrecursionlimit(10 ** 8)

N = int(input())
        
G = [[] for i in range(N)]
for _ in range(N - 1):
    a, b, c = map(int, input().split())
    G[a - 1].append([b - 1, c])
    G[b - 1].append([a - 1, c])
    
color = [0] * N

def dfs(v, c):
    if color[v] == 0:
        color[v] = c
    for i in range(len(G[v])):
        if color[G[v][i][0]] == 0:
            if G[v][i][1] % 2 == 0:
                dfs(G[v][i][0], color[v])
            else:
                dfs(G[v][i][0] , -color[v])
                
for i in range(N):
    dfs(i, 1)
    # print(color)
    
for i in range(N):
    if color[i] == 1:
        print(0)
    else:
        print(1)

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

#define ll long long
#define MOD 1000000007


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

    vector<ll> h(n);
    vector<ll> j(n,1);
    for(int i=0;i<n;i++)cin>>h.at(i);

    int a,b;
    for(int i=0;i<m;i++){
        cin>>a>>b;
        if(h.at(a-1)>h.at(b-1)){
            j.at(b-1)=0;
        }else if(h.at(a-1)<h.at(b-1)){
            j.at(a-1)=0;
        }else{
            j.at(a-1)=0;
            j.at(b-1)=0;
        }
    }

    int co=0;
    for(int i=0;i<n;i++){
        if(j.at(i)==1)co++;
    }

    cout<<co<<endl;


}



Measured memory_bytes: 4820
import java.io.IOException;
import java.text.DecimalFormat;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Scanner;

public class Main {

	@SuppressWarnings("unused")
	public static void main(String[] args) throws IOException {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt(); // 県の個数
		int m = in.nextInt(); // 市の個数

		int city[][] = new int[m + 1][4]; // id, pref, year, number in pref

		// 県、年でソート
		for ( int id = 1; id <= m; id++ ) {
			city[id][0] = id;
			city[id][1] = in.nextInt();
			city[id][2] = in.nextInt();
		}
		Arrays.sort(city, new Comparator<int[]>() {

			@Override
			public int compare(int[] o1, int[] o2) {
				if ( o1[1] != o2[1] ) {
					return o1[1] - o2[1];	// １．prefでソート
				} else {
					return o1[2] - o2[2];	// ２．yearでソート
				}
			}
		});

		DecimalFormat df = new DecimalFormat("000000");
		String result[] = new String[m];
		int pref = 0;
		int num = 0;
		for ( int i = 1; i <= m; i++ ) {
			int p = city[i][1];
			if ( pref != p ) {
				pref = p;
				num = 1;
			} else {
				num++;
			}
			result[city[i][0] -1] = df.format(pref) + df.format(num);
		}
		
		// PrintWriter pw = new PrintWriter(System.out);
		StringBuilder sb = new StringBuilder();
		for ( String s : result ) {			
			sb.append(s).append("\n");
			// pw.println(s);
		}
		System.out.println(sb.toString());
		// pw.flush();
		in.close();
	}
}


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

#define REP(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define REPS(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define RREP(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define RREPS(i, n) for (int i = ((int)(n)); i > 0; i--)
#define IREP(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define IREPS(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define FOR(e, c) for (auto &e : c)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RVISORT(v) sort(v.begin(), v.end(), greater<int>());
#define ALL(v) v.begin(), v.end()

using VI = vector<int>;
using VVI = vector<VI>;
using PII = pair<int, int>;
using ll = long long;

typedef long long ll;

template<class T, class C> void chmax(T& a, C b){ a>b?:a=b; }
template<class T, class C> void chmin(T& a, C b){ a<b?:a=b; }

const ll mod=1e9+7;
int main()
{
    cin.tie( 0 );
    ios::sync_with_stdio( false );
	
	int n,l;
	cin>>n>>l;

	int s=10000;
	int index=0;
	int all=0;
	REP(i,n){
		int tmp=abs(l+i);
		if(s>tmp){
			index=i;
			s=tmp;
		}
		all+=l+i;
	}
	int ans=all-(l+index);
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
from collections import defaultdict, deque

n,q = map(int, input().split())
child = defaultdict(list)
parent = defaultdict(int)
query = defaultdict(int)
for _ in range(n - 1):
	a, b = map(int, input().split())
	child[a].append(b)
	parent[b] = a
for _ in range(q):
	a, b = map(int, input().split())
	query[a] += b
ans = [-1 for _ in range(n)]
for i in range(1, n + 1):
	if parent[i] == 0:
		break
l = deque([i])
while l != deque([]):
	i = l[0]
	ans[i - 1] = query[i]
	if child[i] != []:
 		for x in child[i]:
 			query[x] += query[i]
 			l.append(x)
	l.popleft()
print(*ans)

Measured memory_bytes: 123452
export class Main {
  static main(input: string): string {
    const tmp: string[] = input.split("\n");
    const [k]: number[] = tmp.shift().split(" ").map(int => parseInt(int));
    if (k < 10) {
      return `${k}`;
    }
    const cache = {
      1: [1, 1, 1, 1, 1, 1, 1, 1, 1, 1],
      2: []
    };
    let count = 9;
    let keta = 2;
    let startNum = 1;
    while (true) {
      let count2 = count;
      if (startNum == 9) {
        cache[keta][0] = cache[keta - 1][0] + cache[keta - 1][1];
        cache[keta][9] = cache[keta - 1][8] + cache[keta - 1][9];
      } else {
        cache[keta][startNum] = cache[keta - 1][startNum - 1] + cache[keta - 1][startNum] + cache[keta - 1][startNum + 1];
      }
      count2 += cache[keta][startNum];
      if (count2 >= k) {
        break;
      }
      if (startNum == 9) {
        keta++;
        cache[keta] = [];
        startNum = 1;
      } else {
        startNum++;
      }
      count = count2;
    }
    let startNum2 = startNum;
    keta--;
    let result = `${startNum2}`;
    while (keta > 0) {
      let count2 = count;
      if (startNum2 == 0) {
        count2 += cache[keta][startNum2];
        if (count2 >= k) {
          result += `${startNum2}`;
          keta--;
          continue;
        }
        count = count2;
        startNum2  = startNum2 + 1;
        count2 += cache[keta][startNum2];
        result += `${startNum2}`;
        keta--;
      } else if (startNum2 == 9) {
        count2 += cache[keta][startNum2 - 1];
        if (count2 >= k) {
          startNum2  = startNum2 - 1;
          result += `${startNum2}`;
          keta--;
          continue;
        }
        count = count2;
        count2 += cache[keta][startNum2];
        result += `${startNum2}`;
        keta--;
      } else {
        count2 += cache[keta][startNum2 - 1];
        if (count2 >= k) {
          startNum2 = startNum2 - 1;
          result += `${startNum2}`;
          keta--;
          continue;
        }
        count = count2;
        count2 += cache[keta][startNum2];
        if (count2 >= k) {
          result += `${startNum2}`;
          keta--;
          continue;
        }
        count = count2;
        startNum2  = startNum2 + 1;
        count2 += cache[keta][startNum2];
        result += `${startNum2}`;
        keta--;
      }
    }
    return result;
  }
}
console.log(Main.main(require("fs").readFileSync("/dev/stdin", "utf8")));


Measured memory_bytes: 9420
N,M = map(int,input().split())

min = 0
max = 1000000

for i in range(M):
    L, M = map(int,input().split())
    if min < L:
        min = L
    if max > M:
        max  = M

if min <= max:
    print(max - min + 1)
else:
    print(0)


Measured memory_bytes: 3060
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#include <algorithm>
#include <iostream>
#include <string>

using namespace std;

const int MAX_N = 10000;
const int MAX_K = 10;

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

    string s;

    cin >> s;

    long long sum = 0;

    for (int i = 0; i < (1 << (s.size() - 1)); i++) {
        string snum = "";
        for (int j = 0; j < s.size(); j++) {
            snum += s[j];
            if ((i >> j) & 1) {
                sum += stoll(snum);
                snum = "";
            }
        }
        sum += stoll(snum);
    }

    cout << sum << "\n";

    return 0;
}

Measured memory_bytes: 3660
//include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
//conversion
//------------------------------------------
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
// chmax chmin
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int main(void){

    int W, H, N;
    cin >> W >> H >> N;
    int x[N], y[N], a[N];
    REP(i,N) cin >> x[i] >> y[i] >> a[i];

    int d[W][H];
    REP(i,W)REP(j,H) d[i][j] = 0;

    REP(i,N){
        if(a[i] == 1){
            REP(j,x[i])REP(k,H) d[j][k] = 1;
        }
        else if(a[i] == 2){
            FOR(j,x[i],W)REP(k,H) d[j][k] = 1;
        }
        else if(a[i] == 3){
            REP(j,W)REP(k,y[i]) d[j][k] = 1;
        }
        else{
            REP(j,W)FOR(k,y[i],H) d[j][k] = 1;
        }
    }

    int ans = 0;
    REP(i,W)REP(j,H) if(d[i][j] == 0) ans++;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
program redistribution
  implicit none
  integer(8), parameter :: modu = 1000000007_8
  integer :: s
  integer(8) :: m(3, 3) = 0
  read(*,*) s
  if (s < 6) then
    write(*,'(i0)') s / 3
    stop
  end if
  m(1, 1) = 1
  m(2, 1) = 1
  m(3, 2) = 1
  m(1, 3) = 1
  m = modmatpow(m, s - 6)
  write(*,'(i0)') mod(m(1, 1) + m(1, 1) + m(1, 2) + m(1, 3), modu)
contains
  function modmatmul(x, y) result(res)
    integer(8), parameter :: modu = 1000000007_8
    integer(8), intent(in) :: x(3, 3), y(3, 3)
    integer(8) :: tmp, res(3, 3)
    integer :: i, j, k
    do j = 1, 3
      do i = 1, 3
        res(i, j) = 0
      end do
      do k = 1, 3
        tmp = y(k, j)
        do i = 1, 3
          res(i, j) = mod(res(i, j) + x(i, k) * tmp, modu)
        end do
      end do
    end do
  end
  function modmatpow(x, n) result(res)
    integer(8), intent(in) :: x(3, 3)
    integer, intent(in) :: n
    integer(8) :: res(3, 3), tmp(3, 3)
    integer :: m
    res(1, 1) = 1
    res(2, 1) = 0
    res(3, 1) = 0
    res(1, 2) = 0
    res(2, 2) = 1
    res(3, 2) = 0
    res(1, 3) = 0
    res(2, 3) = 0
    res(3, 3) = 1
    tmp = x
    m = n
    do while (m > 0)
      if (btest(m, 0)) res = modmatmul(res, tmp)
      tmp = modmatmul(tmp, tmp)
      m = rshift(m, 1)
    end do
  end
end program redistribution

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

int main(){
	int n, y;
	cin >> n >> y;
	int res1 = -1, res2 = -1, res3 = -1;
	for(int i=0; i<=n; i++){
		for(int j=0; i+j<=n; j++){
			int k=n-i-j;
			int total = 10000*i+5000*j+1000*k;
			if(total==y){
				res1 = i;
				res2 = j;
				res3 = k;
			}
		}
	}
	cout << res1 << " " << res2 << " " << res3 << endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <utility>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define LL long long
#define INF 1000000001
#define mod 1000000007
using namespace std;
int keta(int n,int k){return (n/int(pow(10,double(k-1)))) % 10;} //nの下からk桁目
ll gcd(ll n,ll m){
	if(n<m){ll a=m;m=n;n=a;}
	ll r=n%m;
	while(r!=0){
		n=m;
		m=r;
		r=n%m;
	}
	return m;
}
ll lcm(ll n,ll m){
	return n*m/gcd(n,m);
}

int main(){
	
	ll N;
	cin>>N;
	ll a,b;
	rep(h,3501){
		rep(n,3501){
			a=4*h*n-N*h-N*n;
			if(a==0){
				continue;
			}
			b=N*h*n;
			if(b%a==0){
				if(b/a>0){
					cout<<h<<" "<<n<<" "<<b/a<<endl;
					return 0;
				}
			}
		}
	}
	
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars, Usize1};
use proconio::{fastout, input};
#[fastout]
fn main() {
    input! {
        s: Chars,
    }
    let mut ans = 0;
    for i in 0..3 {
        if s[i] == 'R' {
            ans += 1;
        }
    }
    if ans == 2 && s[1] == 'S' {
        ans = 1;
    }
    println!("{}", ans);
}


Measured memory_bytes: 2140
/*
 * AOJ 0558: Cheese
 * ?¢???????m*n???????????????????????????1???N??¨???N?????\??????????¢??????????????±????????????????1???N???????????????
 * ?±???????BFS???Queue??????Dijkstra???
 * ????????????S????????????1???N????????????????????\??¨BFS?±?N?¬???????????????´??????????????????
 */

#include <cstdio>
#include <iostream>
#include <queue>
#include <cstring>

using namespace std;

typedef pair<int, int> pii;

int m, n, N;
char mat[1002][1002];
int d[1002][1002];
int sx[10], sy[10];
int dx[4] = {-1, 0, 1, 0};
int dy[4] = {0, 1, 0, -1};
int ans;

int bfs(int sx, int sy, int tx, int ty) {
  memset(d, -1, sizeof(d));
  d[sx][sy] = 0;
  queue<pii> q;
  q.push(make_pair(sx, sy));
  int x, y, xx, yy;
  while (!q.empty()) {
    pii cur = q.front();
    q.pop();
    x = cur.first;
    y = cur.second;
    for (int i = 0; i < 4; ++i) {
      xx = x + dx[i];
      yy = y + dy[i];
      if (xx >= 0 && xx < m && yy >= 0 && yy < n && mat[xx][yy] != 'X' && d[xx][yy] == -1) {
        d[xx][yy] = d[x][y] + 1;
        if (xx == tx && yy == ty) {
          return d[xx][yy];
        }
        q.push(make_pair(xx, yy));
      }
    }
  }

}

void solve() {
  ans = 0;
  for (int i = 0; i < m; ++i) {
    cin >> mat[i];
    for (int j = 0; j < n; ++j) {
      if (mat[i][j] == 'S') {
        sx[0] = i;
        sy[0] = j;
      } else if (mat[i][j] >= '1' && mat[i][j] <= '9') {
        int t = mat[i][j] - '0';
        sx[t] = i;
        sy[t] = j;
      }
    }
  }
  for (int i = 1; i <= N; ++i) {
    int tmp = bfs(sx[i - 1], sy[i - 1], sx[i], sy[i]);
    ans += tmp;
  }
}

int main() {
  cin >> m >> n >> N;
  solve();
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 7932
#include<iostream>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<limits>
#include<algorithm>
using namespace std;

 
template<typename T>
void p(vector<T> a) {
	for (auto i : a) {
		cout << i << ' ';
	}
	cout << '\n';
}
template<typename T>
void pp(vector<vector<T>> a) {
	for (auto i : a) {
		for (auto j : i) {
			cout << j << ' ';
		}
		cout << '\n';
	}
	cout << '\n';
}

void pb(vector<bool>a){
		for(int j=0;j<a.size();j++){
			cout<<a[j];
		}
	
}
	
int n = 0, m = 0, src=0;
vector<vector<int>> g;
vector<int> dist;

void input() {
	cin >> n>>m>>src;
	int N = m;
	g = vector<vector<int>>(0);
	dist = vector<int> (n,INT32_MAX);
	while (N--) {
		int u= 0;
		int v =0;
		int w=0;
		cin >> u >>v>>w;
		g.push_back({u,v,w});
	}
}

void relax(int u,int v,int w){
	if(dist[u]!=INT32_MAX and dist[v]>dist[u]+w){
		dist[v] = dist[u]+w;
	}
}

void compute() {
	dist[src]= 0;
	for(int i = 0;i< n-1;i++){
		for(auto e : g){
			relax(e[0],e[1],e[2]);
		}
	}	
	for(auto e:g){
		int u = e[0];
		int v = e[1];
		int w = e[2];
		if(dist[v]!=INT32_MAX and dist[u]!=INT32_MAX and dist[v]>dist[u]+w){
			cout<<"NEGATIVE CYCLE"<<endl;
			return;
		}
	}
	for(auto d:dist){
		if(d==INT32_MAX){
			cout<<"INF"<<endl;
		}
		else
			cout<<d<<endl;
	}
}



int main() {
	// int t=1;
	// while (t--)
	// {
		input();
		compute();
	// }	
	return 0;
}


Measured memory_bytes: 3172
import sys


class SegmentTree():
    """
    update, get を提供するSegmentTree

    Attributes
    ----------
    __n : int
        葉の数。2 ^ i - 1
    __dot :
        Segment function
    __e: int
        単位元
    __node: list
        Segment Tree
    """
    def __init__(self, A, dot, e):
        """
        Parameters
        ----------
        A : list
            対象の配列
        dot :
            Segment function
        e : int
            単位元
        """
        n = 2 ** (len(A) - 1).bit_length()
        self.__n = n
        self.__dot = dot
        self.__e = e
        self.__node = [e] * (2 * n)
        for i in range(len(A)):
            self.__node[i + n] = A[i]
        for i in range(n - 1, 0, -1):
            self.__node[i] = self.__dot(self.__node[2 * i], self.__node[2 * i + 1])
    
    def update(self, i, c):
        i += self.__n
        node = self.__node
        node[i] = self.__dot(node[i], c)
        while i > 1:
            i //= 2
            node[i] = self.__dot(node[2 * i], node[2 * i + 1])

    def get(self, l, r):
        vl, vr = self.__e, self.__e
        l += self.__n
        r += self.__n
        while (l < r):
            if l & 1:
                vl = self.__dot(vl, self.__node[l])
                l += 1
            l //= 2
            if r & 1:
                r -= 1
                vr = self.__dot(vr, self.__node[r])
            r //= 2
        return self.__dot(vl, vr)


N, Q = map(int, input().split())
query = [tuple(map(int, sys.stdin.readline().split())) for _ in range(Q)]

# H = [N - 2] * N
# W = [N - 2] * N
# H[0] = H[-1] = W[0] = W[-1] = 0

flagH = [N - 1] * N
flagW = [N - 1] * N

stH = SegmentTree([N - 1] * N, min, N - 1)
stW = SegmentTree([N - 1] * N, min, N - 1)

cnt = 0
for t, x in query:
    if t == 1:
        # for i in range(1, flagW[x - 1]):
        #     H[i] -= 1
        cnt += max(0, min(stW.get(x - 1, N), flagW[x - 1]) - 1)
        # #不要 W[x - 1] -= flagW[x - 1] - 1
        
        # for i in range(1, flagW[x - 1]):
        #     flagH[i] = min(flagH[i], x - 1)
        flagW[x - 1] = 0
        stH.update(stW.get(x - 1, N), x - 1)

    else:
        # for i in range(1, flagH[x - 1]):
        #     W[i] -= 1
        cnt += max(0, min(stH.get(x - 1, N), flagH[x - 1]) - 1)
        # #不要　H[x - 1] -= flagH[x - 1] - 1
        
        # for i in range(1, flagH[x - 1]):
        #     flagW[i] = min(flagW[i], x - 1)
        flagH[x - 1] = 0
        stW.update(stH.get(x - 1, N), x - 1)

print(pow(N - 2, 2) - cnt)


Measured memory_bytes: 122744
#include <bits/stdc++.h>
 using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
 int main(){
   int a,b;
   cin>>a>>b;
   if(a>=13)
     cout<<b<<endl;
   else if(a<=5)
     cout<<0<<endl;
   else
     cout<<b/2<<endl;

}

Measured memory_bytes: 256
N = int(input())
T, A = map(int, input().split())
H = [[i, int(h)] for i, h in enumerate(input().split())]
for h in H:
    h[1] = ((T - h[1] * 0.006) - A) ** 2
H.sort(key=lambda x: x[1])
ans = H[0][0]
ans += 1
print(ans)

Measured memory_bytes: 3188
#include <iostream>
using namespace std;
int main() {
	char S[52][52];
	bool flg = true;
	int H, W;

	cin >> H >> W;


	for (int i = 0; i < 52; i++)
	{
		for (int j = 0; j < 52; j++)
		{
			S[i][j] = '.';
		}
	}

	for (int i = 0; i < H; i++)
	{
		for (int j = 0; j < W; j++)
		{
			cin >> S[i][j];
		}
	}

	for (int i = 0; i < H; i++)
	{
		for (int j = 0; j < W; j++)
		{
			if (S[i][j] == '#') {
				if (!(S[i - 1][j] == '#' || S[i + 1][j] == '#' || S[i][j + 1] == '#' || S[i][j - 1] == '#')) {
					flg = false;
					break;
				}
			}
		}
	}

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

	return 0;
}

Measured memory_bytes: 384
// Problem : B - Making Triangle
// Contest : AtCoder - AtCoder Beginner Contest 175
// URL : https://atcoder.jp/contests/abc175/tasks/abc175_b
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

//Macros

#define ll long long
#define db long double
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int,int>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define inf 1e10
#define PI acos(-1.0)
#define int long long
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define N 100005

//Solution

bool triangle(int a, int b, int c){
    return (a+b > c) && (b+c > a) && (c+a > b);
}

void solve(){
    int n;
    cin>>n;
    vi a(n);
    int ans = 0;
    for(int &i : a) cin>>i;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            for(int k=j+1;k<n;k++){
                set<int> tmp;
                tmp.insert(a[i]); tmp.insert(a[j]); tmp.insert(a[k]);
                if(sz(tmp) < 3) continue;
                if(triangle(a[i],a[j],a[k])) ans++;
            }
        }
    }
    cout<<ans;
}

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    int tests;
    //cin>>tests;
    tests = 1;
    while(tests--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3648
#include<cstdio>
#include<iostream>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
#include<iterator>
#include<cstdlib>
#include<queue>
#include<vector>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef ostream_iterator<int> os_iter_int;

ll A,B,C,ans;

template<typename inp_t>
void readx(inp_t& x)
{
	x=0; int k=1; char ch=0;
	while (ch<'0' || ch>'9') { ch=getchar(); if (ch=='-') k=-1; }
	while (ch>='0' && ch<='9') { x=x*10+ch-'0'; ch=getchar(); }
	x*=k;
}



int main()
{
	readx(A); readx(B); readx(C);
	ans+=2*min(B,C);
	B-=ans/2; C-=ans/2;
	if (!C) { ans+=B; printf("%lld\n",ans); return 0; }
	int tmp=min(A,C);
	ans+=tmp; A-=tmp; C-=tmp;
	// if (A) ans+=A;
	if (C) ans++;
	printf("%lld\n",ans);
	
	
}

Measured memory_bytes: 256
import           Control.Applicative
import           Control.Monad
import           Data.List

rotate:: [Int] -> Char -> [Int]
rotate [u,f,r,l,b,d] 'E' = [l,f,u,d,b,r]
rotate [u,f,r,l,b,d] 'N' = [f,d,r,l,u,b]
rotate [u,f,r,l,b,d] 'S' = [b,u,r,l,d,f]
rotate [u,f,r,l,b,d] 'W' = [r,f,d,u,b,l]
rotate xs _              = xs

main :: IO ()
main = do
  dice <- map read . words <$> getLine
  opts <- getLine
  print (head $ foldl rotate dice opts)


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

int main() {
  int n, k, x, y;
  cin >> n >> k;
  for (int i = 0; i < n; i++){
    cin >> x;
    if (x <= k / 2)
      y += x * 2;
    else
      y += (k - x) * 2;
  }
  cout << y << endl;
}

Measured memory_bytes: 256
x = 1
i = 0
j = 0
card = [[0 for a in range (13)]  for b in range (4)]
checknum = int(input())
while x <= checknum: #????????????????????\???
	picture, num = input().split()
	num = int(num)
	if picture == 'S':
		card[0][num - 1] = num
	if picture == 'H':
		card[1][num - 1] = num
	if picture == 'C':
		card[2][num - 1] = num
	if picture == 'D':
		card[3][num - 1] = num
	x += 1
# index = [(i, j)for i, mini_card in enumerate(card) for j, elem in enumerate(mini_card) if elem == 0]
for i, mini_card in enumerate(card):
	for j, elem in enumerate(mini_card):
		if elem == 0:
			if i == 0:
				i = str('S')
			elif i == 1:
				i = str('H')
			elif i == 2:
				i = str('C')
			elif i == 3:
				i = str('D')
			j += 1
			print(i, j)
# print (card)

Measured memory_bytes: 7768
import scala.io.StdIn

object Main extends App {

  val s = StdIn.readLine()

  def conv(t: StringBuilder, i: Int): StringBuilder = {
    if (s.length < i) {
      t
    }else if (i % 2 == 1) {
      t.append(s(i - 1))
      conv(t, i + 1)
    } else {
      conv(t, i + 1)
    }
  }

  println(conv(new StringBuilder, 1))

}

Measured memory_bytes: 29252
#include <stdio.h>
#include <string.h>
#define LEN 100005

typedef struct{
  char name[100];
  int t;
}Process;

Process Q[LEN];
int head,tail,n;

void enqueue(Process x){
  Q[tail]=x;
  tail=(tail+1)%LEN;
}


Process dequeue(){
  Process x=Q[head];
  head=(head+1)%LEN;
  return x;
}

int min(int a,int b){
  if(a<b){
    return a;
  }
  else{
    return b;
  }
}

int main(void){
  int q,i,c,elaps=0;
  Process u;
  scanf("%d %d",&n,&q);

  for(i=1;i<=n;i++){
    scanf("%s %d",Q[i].name,&Q[i].t);
  }

  head=1; tail=n+1;

  while(head!=tail){
    u=dequeue();
    c=min(q,u.t);
    u.t-=c;
    elaps+=c;
    if(u.t>0) enqueue(u);
    else{
      printf("%s %d\n",u.name,elaps);
    }
  }
  return 0;
}

Measured memory_bytes: 10756
#include <stdio.h>
int main(void) {
	int leap_year[3001] = {0};
	int i, a, b;
	const char *result, *separator = "";

	for (i = 0; i < 3001; i++) {
		leap_year[i] = (i % 4 == 0 && i % 100) || (i % 400 == 0);
	}

	while (1) {
		scanf("%d %d", &a, &b);
		if (!a && !b)
			break;

		printf("%s", separator);

		result = "NA\n";
		for (i = a; i < b+1; i++) {
			if (leap_year[i]) {
				printf("%d\n", i);
				result = "";
			}
		}
		printf("%s", result);
		separator = "\n";
	}
	return 0;
}

Measured memory_bytes: 616
#include<stdio.h>
#include<stack>
#include<stdlib.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
using namespace std;

int main(){
	stack<int> S1;
	stack<pair<int,int> > S2;
	char slope;
	int i = 0;
	int sum = 0;
	while (cin >> slope){
		if (slope == '\\'){
			S1.push(i);
		}
		else if (slope == '/' &&S1.size() > 0){
			int j = S1.top(); S1.pop();
			sum += i - j;
			int a = i - j;
			while (S2.size() > 0 && S2.top().first > j){
				a += S2.top().second; S2.pop();
			}
			S2.push(make_pair(j, a));
		}
		i++;
	}
	vector<int> ans;
	int t = 0;
	while (S2.size() > 0){
		ans.push_back(S2.top().second); S2.pop();
	}
	reverse(ans.begin(), ans.end());
	cout << sum << endl;
	cout << ans.size();
	for (int i = 0; i < ans.size(); i++){
		cout << " ";
		t += ans[i];
		cout << ans[i];
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 3224
#![allow(non_snake_case,unused_imports,dead_code)]
use std::io::Read;
use std::cmp::max;
use std::cmp::min;
use std::str::FromStr;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::BinaryHeap;
use std::cmp::Ordering;

use proconio::input;
use proconio::marker::{Chars,Usize1,Isize1};

fn comp_f64(a: &f64, b: &f64) -> Ordering {
    if a < b {
        return Ordering::Less;
    } else if a > b {
        return Ordering::Greater;
    }
    Ordering::Equal
}

fn main() {

    input!{
        N:usize,
        M:usize,
        XY:[(Usize1,Usize1);M]
    }

    let mut R = vec![false;N];
    R[0] = true;
    let mut B = vec![1;N];

    for &(x,y) in &XY{
        R[y] |= R[x];
        if B[x]==1{R[x] = false;}
        B[x] -= 1;
        B[y] += 1;
    }
    let ans = R.iter().filter(|&&b| b).count();
    println!("{}",ans);
}

Measured memory_bytes: 5200
#include<bits/stdc++.h>
using namespace std;
#define itn int
#define int int64_t
#define fi first
#define se second
signed main(){
  int n;
  double sum;
  int x,y,b,p;
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>x>>y>>b>>p;
    sum=x*b+y*p;
    if(b<5) b=5;
    if(p<2) p=2;
    if(sum>(0.8*x)*b+(0.8*y)*p){
      sum=(0.8*x)*b+(0.8*y)*p;
    }
    cout<<sum<<"\n";
  }
}


Measured memory_bytes: 3264
#include <cassert>
#include <cctype>
#include <cmath>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <deque>
#include <functional>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#include <fstream>
#include <iostream>
#include <sstream>

#include <iomanip>

using namespace std;

typedef pair<int, int> pint;
typedef vector<int> vint;
typedef long long ll;

#define ALL(c) (c).begin(),(c).end()
#define RALL(c) (c).rbegin(),(c).rend()
#define SORT(c) sort(ALL(c))

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

#define NEXTP(c) next_permutation(ALL(c))
#define SUM(c) accumulate(ALL(c),0)
#define MP( a, b ) make_pair( ( a ), ( b ) )

#define ANS(x)  cout << (x) << endl;
#define DUMP(x)  cerr << #x << " = " << (x) << endl;

#define INF 1000000000 // 10^9
const double EPS = 1e-10;

//Template End
class dat{
public:
    int x;
    int y;
    int t;
};

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

int main(){
    int H,W,N;
    cin>>H>>W>>N;
    vector<string> board(H);
    REP(i, H)cin>>board[i];
    
    int time = 0;
    
    dat start;
    
    REP(i, H){
        REP(j, W){
            if(board[i][j]=='S'){
                start.x=i;
                start.y=j;
                start.t=0;
            }
        }
    }
    
    REP(i,N){
        queue<dat> que;
        que.push(start);
        
        bool visited[1000][1000]={};
        visited[start.x][start.y]=true;
        
        while (que.size()) {
            dat now = que.front();
            que.pop();
            if (board[now.x][now.y]=='1'+i) {
                
                time+=now.t;
                start = now;
                start.t=0;
                break;
            }
            
            REP(j, 4){
                int nx = now.x+dx[j];
                int ny = now.y+dy[j];
                
                if (0<=nx&&nx<H&&
                    0<=ny&&ny<W&&
                    board[nx][ny]!='X'&&
                    !visited[nx][ny]) {
                    visited[nx][ny]=true;
                    dat next;
                    next.x=nx;
                    next.y=ny;
                    next.t=now.t+1;
                    que.push(next);
                }
            }
            
        }
    }
    cout<<time<<endl;
    return 0;
}

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

int main(){
    ll N;
    cin >> N;
    bool f = true;
    rep(i, 0, N){
        ll a; cin >> a;
        if(a % 2 == 1) f = false; 
    }
    if(!f) cout << "first" << endl;
    else cout << "second" << endl;
    return 0;
}

Measured memory_bytes: 256
import Data.List
main = do
    s <- map (\g -> (head g, length g)) . group <$> getLine
    print . snd $ foldl' solve (0,0) s

solve (b,s) (c,l) | c == 'B' = (b+l,s)
                  | c == 'W' = (b,s+b*l)

Measured memory_bytes: 19196
import java.util.Scanner;

public class Main {
  public static void main(String args[]) {
    final Scanner scanner = new Scanner(System.in);
    int N = scanner.nextInt();
    int count = 1;
    int maxH = scanner.nextInt();
    int H = 0;

    for (int i = 0; i < N-1; i++) {
      H = scanner.nextInt();
      if (H >= maxH) {
        count++;
        maxH = H;
      }
    }
    System.out.println(count);
  }
}

Measured memory_bytes: 22996
a,b,h,m = map(int, input().split())

import math


if h >= 12:
    h -= 12
h_angle = 30*h + 30*(m/60)
m_angle = 6*m

angle = abs(h_angle -m_angle)
if angle > 180:
    angle = 360 -angle
cos = math.cos(math.radians(angle))
ans_sq = a**2 + b**2 - 2*a*b*cos
print(abs(math.sqrt(ans_sq)))


Measured memory_bytes: 9376
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <decimal/decimal>
using namespace std;
using namespace __gnu_pbds;

#define rep(i, s, t) for (int i = s; i < int(t); ++i)

#define sc	scanf
#define pr	printf
#define ff	first
#define ss	second
#define mp	make_pair
#define pb	push_back
#define eb	emplace_back
#define range(c)	c.begin(), c.end()
#define lowbit(x)	((x) & -(x))
#define pop_count	__builtin_popcount
#define pop_count_64	__builtin_popcountll
#define tail_count	__builtin_ctz
#define tail_count_64	__builtin_ctzll
#define lead_count	__builtin_clz
#define lead_count_64	__builtin_clzll

#define TEMP template<typename
#define CONST(type) constexpr type const

TEMP... Ts> struct is_con { static CONST(bool) value = false; };
TEMP... Ts> struct is_con<vector<Ts...>> { static CONST(bool) value = true; };
TEMP... Ts> struct is_con<list<Ts...>> { static CONST(bool) value = true; };
TEMP... Ts> struct is_con<deque<Ts...>> { static CONST(bool) value = true; };
TEMP... Ts> struct is_con<set<Ts...>> { static CONST(bool) value = true; };
TEMP... Ts> struct is_con<unordered_set<Ts...>> { static CONST(bool) value = true; };
TEMP... Ts> struct is_con<map<Ts...>> { static CONST(bool) value = true; };
TEMP... Ts> struct is_con<unordered_map<Ts...>> { static CONST(bool) value = true; };

TEMP T1, typename T2> ostream& operator<<(ostream& os, pair<T1, T2> const& p) { return os << "<" << p.ff << "," << p.ss << ">"; }
TEMP T> typename enable_if<is_con<T>::value, ostream>::type& operator<<(ostream& os, T const& c) {
	os << "{";
	bool first = true;
	for (auto const& x : c) {
		if (first) first = false;
		else os << ",";
		os << " " << x;
	}
	return os << " }";
}

TEMP T, typename... Ts> void dbg(T h, Ts... t) { cerr << " " << h; dbg<Ts...>(t...); }
template<> void dbg<int>(int x) { cerr << endl; }

#ifdef LOCAL
#define debug(...) cerr << "[ "#__VA_ARGS__" ] :", dbg(__VA_ARGS__, 0)
#else
#define debug(...) 0
#endif

TEMP T, typename U> using ordered_map = tree<T, U, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
TEMP T> using ordered_set = ordered_map<T, null_type>;

typedef long long i64;
typedef decimal::decimal128 i99;
typedef unsigned int u32;
typedef unsigned long long u64;
typedef float f32;
typedef double f64;
typedef long double f80;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<i64> vl;

TEMP T> T& minn(T& lhs, T const& rhs) { return lhs = min(lhs, rhs); }
TEMP T> T& maxx(T& lhs, T const& rhs) { return lhs = max(lhs, rhs); }

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;
	cin >> n;
	vi a(n);
	rep(i, 0, n) {
		cin >> a[i];
	}
	sort(range(a), greater<int>());
	i64 ans = a[0];
	int m = n - 2;
	rep(i, 1, n) {
		if (!m) {
			break;
		}
		if (m) {
			--m;
			ans += a[i];
		}
		if (m) {
			--m;
			ans += a[i];
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 3992
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<string>
#include<stack>
#include<cstdio>
#include<cmath>
using namespace std;

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

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i,x) for(int i=0;i<x;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define uniq(vec) vec.erase(unique(vec.begin(),vec.end()),vec.end())
#define mp1(a,b,c) P1(a,P(b,c))

const int INF=1000000000;
const int dir_4[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
const int dir_8[8][2]={{1,0},{1,1},{0,1},{-1,1},{-1,0},{-1,-1},{0,-1},{1,-1}};

const ll M = 1000000007;

int main(){
	ll x;
	cin >> x;
	ll ret = (x/11)*2;
	x %= 11;
	if(x > 0)ret ++;
	if(x > 6)ret ++;
	cout << ret << endl;
}



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

int main() {
	char a[32], b[32], c[32];
	int sa, sb, sc;

	cin >> a;
	cin >> b;
	cin >> c;

	sa = strlen(a) - 1;
	sb = strlen(b) - 1;
	
	if (a[sa] == b[0] && b[sb] == c[0])
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}

Measured memory_bytes: 256
while True: 
	a, op, b = input().split()
	a = int(a)
	b = int(b)
	if op == "?":
		break
	elif  op == "+":
		s = a+b
		print(int(s))
	elif  op == "-":
		e =  a-b
		print(int(e))
	elif  op == "*":
		x = a*b
		print(int(x))
	elif  op == "/":
		y = a/b
		print(int(y))


Measured memory_bytes: 5592