akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;

int main() {
// 	cout<<"GfG!";
int n;
cin >> n;
int ar[n];
int flag=1;
for(int i =0 ; i<n ;i++){
    cin >> ar[i];
    if(flag){
        if(ar[i]%2==0 && (ar[i]%3!=0 && ar[i]%5!=0))
        {
            flag=0;
        }
    }
    
}
if(flag){
    cout <<"APPROVED";
}
else
cout<<"DENIED";

	return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val roadMap = mutableMapOf<Int, Int>()
    repeat(3) {
        val (a, b) = readIntegerList()
        roadMap[a] = if (roadMap[a] == null) 1 else roadMap[a]!! + 1
        roadMap[b] = if (roadMap[b] == null) 1 else roadMap[b]!! + 1
    }
    
    for (i in roadMap.values) {
        if (i == 3) {
            println("NO")
            return
        }
    }
    println("YES")
}

fun readInteger() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntegerList() = readStringList().map(String::toInt)
fun readLongList() = readStringList().map(String::toLong)


Measured memory_bytes: 36012
N = int(input())
F = [list(map(int,input().split())) for i in range(N)]
P = [list(map(int,input().split())) for i in range(N)]

ans = -float('inf')
for k in range(1,1<<10):
    tmp = 0
    for fs,ps in zip(F,P):
        cnt = 0
        for b in range(10):
            if (k>>b)&1 and fs[b]:
                cnt += 1
        tmp += ps[cnt]
    ans = max(ans, tmp)
print(ans)


Measured memory_bytes: 3064
test = False

from time import time
start = time()

import sys
import random


def solve(c_list, days, now):
    r = sum(c_list[i]*(now-days[i]) for i in range(26))
    return r


if test == True:
    #seed = 94
    #random.seed(seed)
    d = 365
    c = [random.randrange(0, 101) for _ in range(26)]
    s = [[random.randrange(0, 20001) for _ in range(26)] for _ in range(d)]
    c_ = ' '.join(map(str, c))
    s_ = '\n'.join([' '.join(map(str, i)) for i in s])
    with open('./input.txt', 'w') as f:
        f.write('\n'.join([str(d), c_, s_]))
else:
    d = int(input())
    c = list(map(int, input().split()))
    s = [list(map(int, input().split())) for _i in range(d)]


last_days = [-1 for _i in range(26)]
result = []
score = 0
for today in range(d):
    checker = [c[j]*(today-last_days[j]) for j in range(26)]
    y = sum(checker)

    finder = [s[today][j]-(y-checker[j]) for j in range(26)]
    x = finder.index(max(finder))

    if today < d-1:
        second_checker = [c[j]*(today+1-last_days[j]) for j in range(26)]
        second_finder = [s[today+1][j]-(y-checker[j]) for j in range(26)]
        second_x = second_finder.index(max(second_finder))
        if x == second_finder:
            x = finder.index(sorted(finder)[-2])
    

    last_days[x] = today
    result.append(x+1)
    score += s[today][x] - solve(c, last_days, today)
if test:
    print(score)

def change(problems, days):
    last_days = [-1 for _i in range(26)]
    score = 0
    for i in range(d):
        score += s[i][problems[i]-1]
        last_days[problems[i]-1] = i
        score -= sum([c[j]*(i-last_days[j]) for j in range(26)])
    return score

change_list = result.copy()
while time()-start < 1.9:
    if random.randrange(2)<1:
        x, y = random.randrange(0, d), random.randrange(0, d)
        while x == y:
            y = random.randrange(0, d)
        change_list[x], change_list[y] = change_list[y], change_list[x]
        next_score = change(change_list, d)
        if next_score >= score:
            if test:print(score, next_score, abs(next_score-score), 'two')
            score = next_score
            result[x], result[y] = result[y], result[x]
        
        else:
            change_list[x], change_list[y] = change_list[y], change_list[x]
    else:
        x = random.randrange(0, d)
        y = random.randrange(1, 27)
        while change_list[x] == y:
            x = random.randrange(0, d)
            y = random.randrange(1, 27)    
        change_list[x], z = y, change_list[x]
        next_score = change(change_list, d)
        if next_score >= score:
            if test:print(score, next_score, abs(next_score-score), 'one')
            score = next_score
            result[x] = y
        else:
            change_list[x] = z

if test == True:
    with open('./output.txt', 'w') as f:
        f.write('\n'.join(map(str, result)))
else:
    for i in result:
        print(i)

if test:
    elapsed_time = time() - start
    print ("elapsed_time:{0}".format(elapsed_time) + "[sec]")

Measured memory_bytes: 94100
main = do
 getLine
 pList <- map read . words <$> getLine :: IO[Int]
 print $ sum $ map (\(a,b,c) -> if (((a < b) && (b < c)) || ((c < b) && (b < a))) then 1 else 0) $ zip3 pList (drop 1 pList) (drop 2 pList)

Measured memory_bytes: 4012
// IN THE NAME OF RIGHT
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,k;
int main(){
	cin>>n>>k;
	if(n%k==0){
		cout<<0<<endl;
	}else{
		if(n%k<=(k/2)){
		cout<<(n%k)<<endl;
		}else{
		cout<<k-(n%k)<<endl;	
		}
	}
}


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

int main(){
  int n; cin >> n; vector<long long> v(n+1, 0);
  for (int i = 0; i < n; i++) {
    cin >> v[i+1]; v[i+1] += v[i];
  }
  long long ans = 1e18;
  for (int k = 2; k < n-1; k++) {
    long long p, q, r, s;
    int a = lower_bound(v.begin(), v.end(), v[k]/2) - v.begin();
    if (abs((v[k]-v[a])-(v[a]-v[0])) < abs((v[k]-v[a-1])-(v[a-1]-v[0]))) {
      p = v[k]-v[a]; q = v[a]-v[0];
    } else {
      p = v[k]-v[a-1]; q = v[a-1]-v[0];
    }
    int b = lower_bound(v.begin(), v.end(), v[k] + ((v[n]-v[k]) / 2)) - v.begin();
    if (abs((v[n]-v[b])-(v[b]-v[k])) < abs((v[n]-v[b-1])-(v[b-1]-v[k]))) {
      r = v[n]-v[b]; s = v[b]-v[k];
    } else {
      r = v[n]-v[b-1]; s = v[b-1]-v[k];
    }
    ans = min(max({p, q, r, s})-min({p, q, r, s}), ans);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
n = int(input())
a = list(map(int, input().split()))
dp = [[0] * n for _ in range(n)]

# dp[i][j] stores max value of (x-y) in segment from index i to j

for i in range(n):
    dp[i][i] = a[i]
 
for i in range(n - 2, -1, -1):
    for j in range(i + 1, n):
        dp[i][j] = max(a[i] - dp[i + 1][j], a[j] - dp[i][j - 1])
 
print(dp[0][n - 1])

Measured memory_bytes: 111836
n = int(input())
a = list(map(int, input().split()))
s, mod = sum(a)-a[0], 1000000007
ans = a[0]*s
for i in range(1, n):
    s -= a[i]
    ans = (ans % mod + ((s % mod) * a[i]) % mod) % mod

print(ans % mod)


Measured memory_bytes: 31344
N = int(input())
s_list = []
for i in range(N):
    s = input()
    sorted_s = sorted(s)
    s_list.append(sorted_s)
s_list = sorted(s_list)

res = []
ans = 0
res.append(s_list[0])
for j in range(N-1):
    if s_list[j] == s_list[j+1]:
        res.append(s_list[j+1])
    else:
        if len(res) >=2:
            ans += (len(res) * (len(res)-1)) //2
        res = []
        res.append(s_list[j+1])

if len(res) >=2:
    ans += (len(res) * (len(res)-1)) //2

print(ans)


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

using namespace std;

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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 (a>b) { a = b; return 1; } return 0; }
#define UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = 1e18;
const ll MOD = 1000000007;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0, -1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
//#define mp make_pair


int main() {
  int n;
  cin >> n;
  vi a(n);
  rep (i, n) {
    cin >> a[i];
  }
  vector<pii> num1(100001), num2(100001);
  rep (i, 100001) {
    num1[i].second = num2[i].second = i;
  }
  rep (i, n) {
    if (i % 2 == 0) {
      num1[a[i]].first++;
    }
    else {
      num2[a[i]].first++;
    }
  }
  sort(all(num1)); sort(all(num2));
  reverse(all(num1)); reverse(all(num2));
  int n2 = n / 2;
  int n1 = n - n2;
  if (num1[0].second != num2[0].second) {
    cout << n - num1[0].first - num2[0].first << endl;
  }
  else {
    cout << min(n - num1[0].first - num2[1].first, n - num1[1].first - num2[0].first) << endl;
  }
}


Measured memory_bytes: 2304
#include<map>
#include<cmath>
#include<stack>
#include<cstdio>
#include<queue>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int d[10][10]={{0,1},{0,-1},{1,0},{-1,0},{-1,1},{1,-1},{-1,-1},{1,1}};
int n,m,a[100][100];
char s[100][100];
int main(){
	scanf("%d%d\n",&n,&m);
	for(int i=1;i<=n;i++)scanf("%s",s[i]+1);
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			for(int k=0;k<8;k++){
				int dx=i+d[k][0],dy=j+d[k][1];
				if(s[dx][dy]=='#')a[i][j]++;
			}
		}
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=m;j++){
			if(s[i][j]=='.')printf("%d",a[i][j]);
			else putchar('#');
		}
		puts("");
	}
	return 0;
}

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

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

    int c = 0;
    while(cin >> s, s != "END_OF_TEXT"){
        std::transform(s.begin(), s.end(), s.begin(), ::tolower);
        if(s.length() == w.length() && s.find(w) == 0) c++;
    }
    printf("%d\n", c);
    return 0;
}


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

char c[100][100];

int rowFilled[100];
int colFilled[100];

int main(){
  int H,W;
  cin >> H >> W;

  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      cin >>c[i][j];
      if(c[i][j]=='#'){
        rowFilled[j] = 1;
        colFilled[i] = 1;
      }
    }
  }


  for (int i = 0; i < H; ++i) {
    if(colFilled[i]==0) {
      continue;
    }

    for (int j = 0; j < W; ++j) {
      if(rowFilled[j]==1) {
        cout << c[i][j];
      }
    }
    puts("");

  }

  return 0;
}

Measured memory_bytes: 888
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <cstring>
#include <math.h>
#include <bitset>
#include <queue>
#include <set>
#include <iomanip>
#include <math.h>
#include <assert.h>
// #include<bits/stdc++.h>
using namespace std;
typedef long long ll;
constexpr long long int INFLL = 1001001001001001LL;
constexpr int INF = 1000000007;
const int mod = 1000000007;

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

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

int main()
{
    int n, q;
    cin >> n >> q;
    string s;
    cin >> s;
    bitset<100010> a(0);
    for (int i = 0; i < n - 1; i++)
    {
        if (s.substr(i, 2) == "AC")
        {
            a.set(i + 1);
        }
    }
    vector<int> ruiseki(100011);
    for (int i = 0; i < n; i++)
    {
        ruiseki[i + 1] = ruiseki[i] + a[i];
    }
    int l, r;
    for (int i = 0; i < q; i++)
    {
        cin >> l >> r;
        cout << ruiseki[r] - ruiseki[l] << endl;
    }
}

Measured memory_bytes: 1408
import math
[A,B,H,M] = input().split()
A = int(A)
B = int(B)
H = int(H)
M = int(M)
H_theta = H / 6 * math.pi
M_theta = M / 30 * math.pi
H_theta += M_theta / 12
ans = math.sqrt(A**2 + B**2 - 2*A*B*math.cos(abs(H_theta-M_theta)))
print(ans)

Measured memory_bytes: 9512
import sys
input = sys.stdin.buffer.readline
from collections import defaultdict
import heapq

def main():
    N,M = map(int,input().split())
    a = list(map(int,input().split()))
    d = defaultdict(list)
        
    I = [i for i in range(N)]
    rank = [1 for _ in range(N)]
    def root(a):
        if I[a] == a:
            return a
        else:
            I[a] = root(I[a])
            return I[a]
            
    def unite(a,b):
        pa,pb = root(a),root(b)
        ra,rb = rank[a],rank[b]
        if ra > rb:
            I[pb] = pa
        else:
            I[pa] = pb
            if ra == rb:
                rank[pb] += 1
    
    for _ in range(M):
        x,y = map(int,input().split())
        unite(x,y)
        parent = root(x)
    
    for i,num in enumerate(I):
        parent = root(num)
        heapq.heappush(d[parent],a[i])
        
    if M == N-1:
        print(0)
        exit()
    elif N < 2*(N-M-1):
        print("Impossible")
        exit()

    l = len(d.keys())
    ans = 0
    rest = []
    for use in d.values():
        ans += heapq.heappop(use)
        rest.extend(use)

    remain = 2*(N-M-1)-l
    rest.sort()
    ans += sum(rest[:remain])
    
    print(ans)
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 30896
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;
 
int main() {
  vector<int> vi(5);
  cin >> vi[0] >> vi[1] >> vi[2] >> vi[3] >> vi[4];
 
  int sum=0;
  vector<int> v(5);
  int flag = 0;
  for (int i=0;i<5;i++) {
    int a = vi[i] / 10;
    if (vi[i]%10 == 0) {
      v[i]=9;
      sum += a*10;
    } else {
      flag = 1;
      v[i] = vi[i]%10;
      sum += a*10+10;
    }
  }
  
  if (flag == 0){
    std::cout << sum << std::endl;
    return 0; 
  }
  
  int b = 10 - *std::min_element(v.begin(), v.end());
  std::cout << sum - b << std::endl;
  return 0;
}

Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.ascii;
import std.bigint;
import std.complex;
import std.container;
import std.conv;
import std.functional;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

auto readInts() {
	return array(map!(to!int)(readln().strip().split()));
}
auto readInt() {
	return readInts()[0];
}
auto readLongs() {
	return array(map!(to!long)(readln().strip().split()));
}
auto readLong() {
	return readLongs()[0];
}

void readlnTo(T...)(ref T t) {
    auto s = readln().split();
    assert(s.length == t.length);
    foreach(ref ti; t) {
        ti = s[0].to!(typeof(ti));
        s = s[1..$];
    }
}

const real eps = 1e-10;

const long p = 1_000_000_000 + 7;

int diff(in int[] a, in int[] b) {
    return reduce!((a, b) => a + pow(b[1]-b[0], 2))(0, zip(a, b));
}

string calc(string l) {
    auto color = [
        "black": [0, 0, 0],
        "blue": [0, 0, 0xff],
        "lime": [0, 0xff, 0],
        "aqua": [0, 0xff, 0xff],
        "red": [0xff, 0, 0],
        "fuchsia": [0xff, 0, 0xff],
        "yellow": [0xff, 0xff, 0],
        "white": [0xff, 0xff, 0xff]
    ];

        auto r = to!int(l[1..3], 16);
        auto g = to!int(l[3..5], 16);
        auto b = to!int(l[5..7], 16);
        string ans = "black";
        foreach(name, value; color) {
            if(diff(value, [r, g, b]) < diff(color[ans], [r, g, b])) {
                ans = name;
            }
        }
        return ans;
}

void main(){
    while(true) {
        auto l = readln().chomp();
        if(l == "0") {
            return;
        }
        writeln(calc(l));
    }
}

Measured memory_bytes: 3244
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int k = sc.nextInt();
        if (k<=a+b){
            System.out.println(Math.min(a,k));
        }else {
            k-=a+b;
            System.out.println(a-k);
        }
    }
}


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

typedef pair<int, int> P;
vector<P> ps;


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
#ifdef LOCAL
	std::ifstream in("in");
	std::cin.rdbuf(in.rdbuf());
#endif

	int N;
	cin >> N;
	map<int, int> p;
	for(int i = 2; i <= N; i++){
		int k = i;
		for(int j = 2; j <= i; j++){
			while(k % j == 0){
				p[j]++;
				k /= j;
			}
		}
		if(k != 1) p[k]++;
	}

	for(auto v : p){
		if(v.first != 1 && v.second >= 2) ps.push_back(v);
	}

	int ans = 0;
	for(int i = 0; i < ps.size(); i++){
		if(ps[i].second >= 74){
			ans++;
		}
	}
	for(int i = 0; i < ps.size(); i++){
		for(int j = 0; j < ps.size(); j++){
			if(i == j) continue;
			if(ps[i].second >= 14 && ps[j].second >= 4){
				ans++;
			}
			if(ps[i].second >= 24 && ps[j].second >= 2){
				ans++;
			}
		}
	}
	for(int i = 0; i < ps.size(); i++){
		for(int j = i + 1; j < ps.size(); j++){
			for(int k = 0; k < ps.size(); k++){
				if(i == j || j == k || k == i) continue;
				if(ps[i].second >= 4 && ps[j].second >= 4 && ps[k].second >= 2){
					ans++;
				}
			}
		}
	}


	cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.Set;

public class Main{

	public static void main(String[] args) {

		Scanner scanner = new Scanner(System.in);

		String[] tmp = scanner.nextLine().split(" ");
		int n  = Integer.parseInt(tmp[0]);
		int k  = Integer.parseInt(tmp[1]);
		Long a = Long.MAX_VALUE;
		int[] lst = new int[n];
		String[] tmp2 = scanner.nextLine().split(" ");

		for(int i = 0; i < n; i++) {

			lst[i] = Integer.parseInt(tmp2[i]);
		}

		for(int i = 0; i < (n - k + 1); i++) {

			int r = i + k - 1;

			long temp = Math.min(Math.abs(lst[i]) + Math.abs(lst[i] - lst[r]),Math.abs(lst[r]) + Math.abs(lst[i] - lst[r]));
			a = Math.min(temp, a);

		}
		System.out.println(a);
	}
}


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

int main(){
  string s;
  cin>>s;
  int sum=0;
  if(s[0]=='o')sum+=1;
  if(s[1]=='o')sum+=1;
  if(s[2]=='o')sum+=1;
  cout<<700+sum*100<<endl;

  return 0;
}

Measured memory_bytes: 256
import math

x = 0
y = 0
theta = math.radians(90)

while True:
    a, b = map(float, raw_input().split(','))
    if a==0 and b==0: break
    x += a * math.cos(theta)
    y += a * math.sin(theta)
    theta += math.radians(-b)

print int(x)
print int(y)

Measured memory_bytes: 4436
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ll long long 
#define REP(i, a, b) for (ll i = a; i < b; i++)
#define REPI(i, a, b) for (ll i = b - 1; i >= a; i--)
#define i_os ios::sync_with_stdio(0);  cin.tie(0);  cout.tie(0);
#define INF (ll)1e18 + 100
#define endl "\n"
#define p0(a) cout << a << " "
#define p1(a) cout << a << endl
#define p2(a, b) cout << a << " " << b << endl
#define p3(a, b, c) cout << a << " " << b << " " << c << endl
#define p4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << endl
#define MAX 1e6
/*SOME BITMASK KNOWLEDGE
1)x & (x - 1):sets the last one bit of x to zero
power of two exactly when x & (x − 1) = 0.
2)x & -x:sets all the one bits to zero, except last one bit
3)x | (x - 1):inverts all the bits after the last one bit*/
#define o_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define o_setll tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
typedef tree<pair<ll, ll>,null_type,less<pair<ll, ll>>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set

int main() 
{
	ll n,a,b;
	cin>>n>>a>>b;
	ll v = n/(a+b);
	ll v1 = n % (a+b);
	if(v1 > a) v1 = a;
	cout<<v*a + v1<<endl;
	return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#define MAX 100000
#define NIL -1

typedef struct{
  int p;
  int l;
  int r;
}Node;
Node T[MAX];
int n,D[MAX],H[MAX];

void setDepth(int u,int d){
  if(u==NIL)return;
  D[u]=d;
  setDepth(T[u].l,d+1);
  setDepth(T[u].r,d+1);
}
int setHeight(int u){
  int h1=0,h2=0;
  if(T[u].l!=NIL)h1=setHeight(T[u].l)+1;
  if(T[u].r!=NIL)h2=setHeight(T[u].r)+1;
  return H[u]=(h1>h2?h1:h2);
}

int getSibling(int u){
  if(T[u].p==NIL)return NIL;
  if(T[T[u].p].l!=u&&T[T[u].p].l!=NIL)return T[T[u].p].l;
  if(T[T[u].p].r!=u&&T[T[u].p].r!=NIL)return T[T[u].p].r;
  return NIL;
}
void print(int u){
  printf("node %d: ",u);
  printf("parent = %d, ",T[u].p);
  printf("sibling = %d, ",getSibling(u));
  int deg = 0;
  if(T[u].l!=NIL)deg++;
  if(T[u].r!=NIL)deg++;
  printf("degree = %d, ",deg);
  printf("depth = %d, ",D[u]);
  printf("height = %d, ",H[u]);

  if(T[u].p==NIL){
    printf("root\n");
  }else if(T[u].l==NIL&&T[u].r==NIL){
    printf("leaf\n");
  }else {
    printf("internal node\n");
  }
}

int main(){
  int v,l,r,root=0,i;
  scanf("%d",&n);

  for(i=0;i<n;i++){
    T[i].p=NIL;
  }
  for(i=0;i<n;i++){
    scanf("%d %d %d",&v,&l,&r);
    T[v].l=l;
    T[v].r=r;
    if(l!=NIL)T[l].p=v;
    if(r!=NIL)T[r].p=v;
  }
  for(i=0;i<n;i++){
    if(T[i].p==NIL)root=i;
  }
  setDepth(root,0);
  setHeight(root);
  for(i=0;i<n;i++){
    print(i);
  }
  return 0;
}



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


Measured memory_bytes: 256
import java.util.Scanner;
class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
        int h = sc.nextInt();
        int w = sc.nextInt();
        if(h == 0 && w ==0) break;
            for(int i=0; i<h; i++){
                for(int j=0; j<w; j++){
                    if((i+j)%2 == 0) System.out.print("#");
                    else System.out.print(".");
                }
                System.out.println();
            }
        System.out.println();
        }
    }
}


Measured memory_bytes: 35568
def add_edge(node, adj_lst, adj_rev, s1, s2):
  ind = 0
  max_len = min(len(s1), len(s2))
  while ind < max_len and s1[ind] == s2[ind]:
    ind += 1
  if ind == max_len:
    if max_len < len(s1):
      return True
    return False
  c1 = ord(s1[ind]) - ord("a")
  c2 = ord(s2[ind]) - ord("a")
  adj_lst[c1].add(c2)
  adj_rev[c2].add(c1)
  node.add(c1)
  node.add(c2)
  return False
"""
def dfs(x, visited, adj_lst, order):
  visited[x] = True
  for to in adj_lst[x]:
    if not visited[to]:
      dfs(to, visited, adj_lst, order)
  order.append(x)

def dfs_rev(x, used, adj_rev):
  used.append(x)
  for to in adj_rev[x]:
    if not to in used:
      dfs_rev(x, used, adj_rev)
"""
while True:
  n = int(input())
  if n == 0:
    break
  
  lst = [input() for _ in range(n)]
  node = set()
  adj_lst = [set() for _ in range(26)]
  adj_rev = [set() for _ in range(26)]
  brunk_flag = False
  for i in range(n):
    for j in range(i + 1, n):
      brunk_flag = brunk_flag or add_edge(node, adj_lst, adj_rev, lst[i], lst[j])
  
  L = []
  visited = [False] * 26
  cycle_flag = False
  def visit(n):
    global cycle_flag
    if cycle_flag: return
    if visited[n] == 2:
      cycle_flag = True
    elif visited[n] == 0:
      visited[n] = 2
      for to in adj_lst[n]:
        visit(to)
      visited[n] = 1
      L.append(n)
  
  L = []
  for n in node:
    visit(n)
  if cycle_flag or brunk_flag:
    print("no")
  else:
    print("yes")


Measured memory_bytes: 5656
let quick_sort (a : (int * char * int) array) cmp =
  let swap i j = let tmp = a.(i) in a.(i) <- a.(j); a.(j) <- tmp in
  let partition p r =
    let rec exchange = function
      | (i, j) when j = r -> swap i r; i
      | (i, j) when cmp a.(j) a.(r) <= 0 -> swap i j; exchange (i + 1, j + 1)
      | (i, j) -> exchange (i, j + 1) in
    exchange (p, p) in
  let rec doit p r =
    if p < r then begin
      let q = partition p r in
      doit p (q - 1);
      doit q r
    end in
  doit 0 (Array.length a - 1)

let stable_p (a : (int * char * int) array) n =
  let rec doit i =
    if i = n then true
    else if (fun (xi, _, xd) (yi, _, yd) -> xd = yd && xi > yi) a.(i-1) a.(i) then false
    else doit (i + 1) in
  doit 1

let split str delim =
  let open String in
  let rec doit s acc =
    match
      try Some (rindex s delim) with _ -> None
    with
    | None -> s :: acc
    | Some i -> doit (sub s 0 i) (sub s (i + 1) (length s - i - 1) :: acc) in
  doit str []

let () =
  let n = read_int () in
  let read i =
    match split (read_line ()) ' ' with
    | [c; d] -> (i, c.[0], int_of_string d)
    | _ -> exit 1 in
  let a = Array.init n read in
  quick_sort a (fun (_, _, x) (_, _, y) -> compare x y);
  print_endline (if stable_p a n then "Stable" else "Not stable");
  Array.iter (fun (_, c, d) -> Printf.printf "%c %d\n" c d) a

Measured memory_bytes: 8900
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

def main():
    N,K = map(int, readline().split())

    MOD = 10**9 + 7

    ans = 0
    for i in range(K,N+2):
        n_max = N * (N+1) // 2 - (N-i) * (N-i+1) // 2
        n_min = i * (i-1) // 2
        ans += n_max - n_min + 1
        ans %= MOD

    print(ans)


if __name__ == "__main__":
    main()


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

typedef long long ll;
const int INF = 1e9;
const ll LINF = 1e18;
const int mod = 1e9+7;

#define pi pair<int,int>
#define pl pair<lld,lld>

#define dump(x) cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define mem0(x) memset(x,0,sizeof(x))
#define fillnum(x,n) fill(begin(x),end(x),n)
#define asort(x) sort(x.begin(),x.end())
#define dsort(x,t) sort(x.begin(),x.end(),greater<t>())
#define vuniq(x) x.erase(unique(x.begin(), x.end()), x.end())

#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)

int main() {
    string S,T;
    cin >> S >> T;
    ll cnt = 0;
    for (int i = 0; i < 3; i++) {
        if(S[i] == T[i]){
            cnt++;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
#define Sheryang main
typedef long long ll;
#pragma GCC optimize(3)
#define HEAP(...) priority_queue<__VA_ARGS__ >
#define heap(...) priority_queue<__VA_ARGS__,vector<__VA_ARGS__ >,greater<__VA_ARGS__ > >
template<class T> inline T min(T &x,const T &y){return x>y?y:x;}
template<class T> inline T max(T &x,const T &y){return x<y?y:x;}
struct ios
{
    inline char gc()
    {
        static const int IN_LEN=1<<18|1;
        static char buf[IN_LEN],*s,*t;
        return (s==t)&&(t=(s=buf)+fread(buf,1,IN_LEN,stdin)),s==t?-1:*s++;
    }
    template <typename _Tp> inline ios & operator >> (_Tp&x)
    {
        static char ch,sgn; ch = gc(), sgn = 0;
        for(;!isdigit(ch);ch=gc())
        {   
            if(ch==-1)return *this;sgn|=ch=='-';
        }
        for(x=0;isdigit(ch);ch=gc())x=(((x<<2)+x)<<1)+(ch^'0');
        sgn&&(x=-x); return *this;
    }
}io;
const int maxn = 1e5 + 7;
const int mod = 1e9 + 7;
/** keep hungry and keep calm! **/
 
int n,k,cnt;
int R,S,P;
string t;
ll ans;
int vis[100005];
int main()
{
    cin >> n >> k;
    cin >> R >> S >> P;
    cin >> t;
    memset(vis,0,sizeof(vis));//数组清零 
    for(int i=0;i<n;i++)
    {
    	if(i-k >= 0 && vis[i-k] == 1 && t[i] == t[i-k])	continue;
        if(t[i] == 'r')	ans += P;
        if(t[i] == 's')	ans += R;
        if(t[i] == 'p')	ans += S;
        vis[i] = 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 896
a=int(input())
moji=input()
r=[]
g=[]
b=[]
for i in range(a):
    if moji[i]=="R":
        r.append(i)
    elif moji[i]=="G":
        g.append(i)
    else:
        b.append(i)
res=len(r)*len(g)*len(b)
if len(r)==0 or len(g)==0 or len(b)==0:
    print(0)
else:
    for i in range(0,a-2):
      for j in range(i+1,a-1):
        if 2*j-i<a and moji[i]!=moji[j] and moji[j]!=moji[2*j-i] and moji[2*j-i]!=moji[i]:
          res-=1
    print(res)


Measured memory_bytes: 68232
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<iomanip>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1e9+7
#define LINF (long long)4e18


int main(){
    long long N,M;
    cin >> N >> M;
    long long ans = 0;
    if(N >= 2 && M >= 2)ans = (N-2)*(M-2);
    else if(N == 1 && M >= 2)ans = M-2;
    else if(N >= 2 && M == 1)ans = N-2;
    else ans = 1;
    cout << ans << endl;
}

Measured memory_bytes: 256
function main(input) {
    var data = input.split(' ');
    var a = parseInt(data[0]);
    var b = parseInt(data[1]);
    var d = Math.floor(a / b);
    var r = a % b;
    var f = (a / b).toFixed(5);
    var output = [d, r, ,f].join(' ');
    console.log(output);
}

process.stdin.resume();
var input = '';  
process.stdin.setEncoding('utf-8');
process.stdin.on('data', function(chunk) {
  input += chunk;
});
process.stdin.on('end', function() {
  main(input);
});

Measured memory_bytes: 15736
#include<iostream>
#include<iomanip>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<functional>
#include<map>
#include<cstdlib>
#include<complex>
#include<numeric>
#include<set>
#include<deque>
#include<queue>

using namespace std;
using Int = long long;
Int INF = 1LL << 60;
const Int MOD = 1000000000 + 7;

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	Int K;
	cin >> K;

	Int even, odd;
	even = K / 2;
	odd = K - even;

	cout << even*odd << "\n";

}


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

bool vis[100001];
map<int,int> mp;
int n,m;
vector<pair<int,int> > v[100001];

void dfs(int now,int shen){
	//cout<<now<<endl;
	if(vis[now]){
		if(mp[now]!=shen){
			cout<<"No";
			exit(0);
		}
		else
			return;
	}
	
	vis[now]=true;
	mp[now]=shen;
	
	for(int i=0;i<v[now].size();i++){
		int c=v[now][i].first;
		dfs(c,shen+v[now][i].second);
	}
}


int main(){
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		int l,r,d;
		cin>>l>>r>>d;
		v[l].push_back(make_pair(r,d));
		v[r].push_back(make_pair(l,-d));
	}
	
	for(int i=1;i<=n;i++)
		if(!vis[i])
			dfs(i,0);
	
	
	cout<<"Yes";
	return 0;
}


Measured memory_bytes: 18048
# include <iostream>
# include <algorithm>
#include <array>
# include <cassert>
#include <cctype>
#include <climits>
#include <numeric>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <tuple>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
# include <chrono>
# include <random>
# include <limits.h>
# include <unordered_map>
# include <unordered_set>
# include <deque>
# include <cstdio>
# include <cstring>
#include <stdio.h>
#include<time.h>
#include <stdlib.h>
#include <cstdint>
#include <cfenv>
#include<fstream>
//#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
long long MOD = 1000000000 + 7; //924844033 1000000000 + 7;
constexpr long long INF = numeric_limits<LL>::max();
const double PI = acos(-1);
#define fir first
#define sec second
#define thi third
#define debug(x) cerr<<#x<<": "<<x<<'\n'
typedef pair<LL, LL> Pll;
typedef pair<double, double> Dll;
typedef pair<LL, pair<LL, LL>> Ppll;
typedef pair<LL, pair<LL, bitset<100001>>> Pbll;
typedef pair<LL, pair<LL, vector<LL>>> Pvll;
typedef pair<LL, LL> Vec2;
struct Tll { LL first, second, third; };
struct Fll { LL first, second, third, fourth; };
typedef pair<LL, Tll> Ptll;
#define rep(i,rept) for(LL i=0;i<rept;i++)
#define Rrep(i,mf) for(LL i=mf-1;i>=0;i--)
LL h, w, n, m, k, t, s, p, q, last, first, cnt, sum, ans, dp[40000],a[200000],b[200000];
string str, ss;
bool f;
char c;
int di[4][2] = { { 0,1 },{ 1,0 },{ 0,-1 },{ -1,0 } };
struct Edge { LL to, cost; };
struct edge { LL from, to, cost; };
vector<LL>vec;
vector<edge>ed;
vector<Pll>v;
map<LL,LL>ma;
set<LL>st;
void YN(bool f) {
	if (f)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
}
void yn(bool f) {
	if (f)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

int main() {
	cin >> n;
	rep(i, n) {
		cin >> a[i];
		sum += a[i];
	}
	rep(i, n) {
		if ((sum - a[i]) % 2 == 0) {
			ans = max(ans, (sum - a[i]) / 2);
		}
	}
	if (sum % 2 == 0)
		ans = max(ans,sum/2);
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 3128
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define reps(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++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 rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define reps2(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define inf 2e9
#define linf 9000000000000000000ll
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

struct edge {
    ll to, len, cost;
    edge(ll to, ll len, ll cost) : to(to), len(len), cost(cost) {}
};

#define MAX_N 50
#define MAX_M 100
#define MAX_A 2500
int A[MAX_M], B[MAX_M], C[MAX_N], D[MAX_N];
int n, m, sil;
vector<edge> G[51];
vector<ll> _time[MAX_A + 1], min_time;
vector<int> prev[MAX_A + 1];

void dijkstra(int s) {
    rep(i, MAX_A + 1) { _time[i].resize(n, linf); }
    min_time.resize(n, linf);
    _time[sil][s] = 0;
    min_time[s] = 0;
    using P = pair<ll, pair<int, int>>;  // time, (pos, sil)
    priority_queue<P, vector<P>, greater<P>> Q;
    Q.push(make_pair(0, make_pair(s, sil)));

    while (!Q.empty()) {
        ll cur_time = Q.top().first;
        int cur_pos = Q.top().second.first;
        int cur_sil = Q.top().second.second;
        Q.pop();
        if (_time[cur_sil][cur_pos] < cur_time) continue;
        if (cur_sil != MAX_A) {
            int nx_sil = min(MAX_A, cur_sil + C[cur_pos]);
            ll nx_time = cur_time + D[cur_pos];
            if (_time[nx_sil][cur_pos] > nx_time) {
                _time[nx_sil][cur_pos] = nx_time;
                Q.push(make_pair(nx_time, make_pair(cur_pos, nx_sil)));
            }
        }
        for (edge e : G[cur_pos]) {
            ll nx_time = cur_time + e.len;
            int nx_pos = e.to;
            int nx_sil = cur_sil - e.cost;
            if (nx_sil >= 0 && nx_time < _time[nx_sil][nx_pos]) {
                _time[nx_sil][nx_pos] = nx_time;
                min_time[nx_pos] = min(min_time[nx_pos], nx_time);
                Q.push(make_pair(nx_time, make_pair(nx_pos, nx_sil)));
            }
        }
    }
}
int main() {
    cin >> n >> m >> sil;
    sil = min(sil, MAX_A);
    rep(i, m) {
        int u, v;
        cin >> u >> v >> A[i] >> B[i];
        u--, v--;
        G[u].push_back(edge(v, B[i], A[i]));
        G[v].push_back(edge(u, B[i], A[i]));
    }
    rep(i, n) { cin >> C[i] >> D[i]; }
    dijkstra(0);
    reps(i, n - 1) { cout << min_time[i] << endl; }
    return 0;
}

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

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

typedef pair< long long, long long > P;
typedef pair< long long, P > PP;
typedef pair< P, P > PPP;

const long long MOD = 1e9 + 7;
const  long long  INF = 5e18;
const double DINF = 5e14;
const double eps = 1e-10;
const int di[4] = { 1,0,-1,0 }, dj[4] = { 0,1,0,-1 };

#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define pb push_back
#define eb emplace_back
#define fr first
#define sc second

int h, w, a[510][510];
vector<PPP>ans;


int main() {
	cin >> h >> w;
	for (int i = 0;i < h;i++) {
		for (int j = 0;j < w;j++) {
			cin >> a[i][j];
		}
	}
	for (int i = 0;i < h;i++) {
		if (i % 2 == 0) {
			for (int j = 0;j < w;j++) {
				if (a[i][j] % 2 == 1) {
					if (j == w - 1&&i!=h-1) {
						ans.eb(PPP(P(i + 1, j + 1), P(i + 2, j + 1)));
						a[i + 1][j]++;
					}
					else if(j!=w-1) {
						ans.eb(PPP(P(i + 1, j + 1), P(i +1, j + 2)));
						a[i][j + 1]++;
					}
				}
			}
		}
		else {
			for (int j =w - 1;j >= 0;j--) {
				if (a[i][j] % 2 == 1) {
					if (j == 0&&i!=h-1) {
						ans.eb(PPP(P(i + 1, j + 1), P(i + 2, j + 1)));
						a[i + 1][j]++;
					}
					else if(j!=0) {
						ans.eb(PPP(P(i + 1, j + 1), P(i + 1, j)));
						a[i][j - 1]++;
					}
				}
			}
		}
	}
	cout << ans.size() << endl;
	for (int i = 0;i < ans.size();i++) {
		cout << ans[i].fr.fr << ' ' << ans[i].fr.sc << ' ' << ans[i].sc.fr << ' ' << ans[i].sc.sc << endl;
	}
	return 0;
}



Measured memory_bytes: 7408
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
 
using namespace std;
using Int = long long int;
using UInt = unsigned long long int;
using VI = vector<long long int>;

int main(void) {
    Int n;
    cin >> n;
    if (n <= 999) {
        cout << "ABC" << endl;
    } else {
        cout << "ABD" << endl;
    }
    return 0;
}



Measured memory_bytes: 3616
n, m = map(int, input().split())
l = [list(map(int, input().split())) for i in range(n)]

l.sort()

cost = 0
for i in range(n):
    if m > l[i][1]:
        cost += l[i][0] * l[i][1]
        m -= l[i][1]
    else:
        cost += l[i][0] * m
        break

print(cost)

Measured memory_bytes: 60760
import std.stdio, std.string, std.array, std.conv;

void main() {
    while (true) {
        int[] tmp = readln.chomp.split.to!(int[]);
        int h = tmp[0], w = tmp[1];
        if (h == 0 && w == 0) break;
        foreach (i; 0 .. h) {
            foreach (j; 0 .. w) {
                write(i == 0 || i == h - 1 || j == 0 || j == w - 1 ? "#" : ".");
            }
            writeln;
        }
        writeln;
    }
}


Measured memory_bytes: 2440
#include<map>
#include<cmath>
#include<stack>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
template<class Read>void in(Read &x){
    x=0;
    int f=0;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        f|=(ch=='-');
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    x=f?-x:x;
    return;
}
#define int long long
const int M=1e9+7;
int r1,r2,c1,c2,n,f[5000005],ans,sum;
int ksm(int x,int y){
    int s=1;
    while(y){
        if(y&1)s=(s*x)%M;
        x=(x*x)%M;
        y>>=1;
    }
    return s;
}
int work(int x,int y){
    return f[x]*ksm(f[y],M-2)%M*ksm(f[x-y],M-2)%M;
}
signed main(){
    in(r1);in(c1);in(r2);in(c2);
    n=max(c1,c2)+r2+2;
    f[0]=1;
    for(int i=1;i<=n;i++)f[i]=(f[i-1]*i)%M;
    for(int i=r1;i<=r2;i++)ans=(ans+work(i+c2+1,i+1))%M;
    for(int i=r1;i<=r2;i++)sum=(sum+work(i+c1,i+1))%M;
    cout<<(ans-sum+M)%M<<endl;
	return 0;
}


Measured memory_bytes: 16640
#include <stdio.h>
int main(void)
{
	int x, a, b, c;

	scanf("%d", &x);
	a = x / 3600;
	b = (x - a * 3600) / 60;
	c = x - (a * 3600 + b * 60);

	printf("%d:%d:%d\n", a,b,c);

	return 0;
}


Measured memory_bytes: 2044
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

template <typename T>
using vector2 = vector<vector<T>>;
template <typename T>
vector2<T> initVec2(size_t n0, size_t n1, T e = T()){
    return vector2<T>(n0, vector<T>(n1, e));
}

template <typename T>
using vector3 = vector<vector<vector<T>>>;
template <typename T>
vector3<T> initVec3(size_t n0, size_t n1, size_t n2, T e = T()){
    return vector3<T>(n0, vector2<T>(n1, vector<T>(n2, e)));
}

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

    int n;
    cin >> n;

    cout << 180 * (n - 2) << endl;

    return 0;
}


Measured memory_bytes: 888
#include <stdio.h>
 
#define BIG ((long long) 1e18)
 
int main(void)
{
    int n;
    long long as[100000];
    scanf("%d", &n);
 
    long long ans = 1;
    for (int i = 0; i < n; i++)
    {
        scanf("%lld", &as[i]);
    }
 
    for (int i = 0; i < n; i++)
    {
        if (as[i] == 0)
        {
            ans = 0;
            printf("%lld\n", ans);
            return 0;
        }
    }
 
        for (int i = 0; i < n; i++)
        {
            if (as[i] > BIG / ans)
            {
                ans = -1;
                printf("%lld\n", ans);
                return 0;
            }
            ans *= as[i];
        }
 
    printf("%lld\n", ans);
 
    return 0;
}

Measured memory_bytes: 2508
from collections import deque
h,w=map(int,input().split())
n=int(input())
a=list(map(int,input().split()))
ae=[]
ans=[]
rl=0
for i in range(n):
  ae.extend([i+1]*a[i])
for x in range(h):
  if x%2==0:
    ans.append(ae[w*x:w*(x+1)])
  else:
    ans.append(reversed(ae[w*x:w*(x+1)]))

for r in ans:
  print(' '.join(list(map(str,r))))
  
  
  
  

Measured memory_bytes: 9656
X=int(input())
mx=100100
p=[True]*(mx+10)
p[0]=p[1]=False
for i in range(2,mx+1):
  if p[i]==True:
    for j in range(i*i,mx+1,i):
      p[j]=False
A=[]
for i in range(1,mx+1):
  if p[i]==True:
    A.append(i)

i=0
while X>A[i]:
  i=i+1
print(A[i])

Measured memory_bytes: 4180
n, m = map(int, input().split())
s = [[]] * m
t = [[]] * m
for i in range(m):
    s[i] = list(map(int, input().split()))
    t[i] = s[i][1:]
p = [int(i) for i in input().split()]

def dfs(cur, switch):
    light = [0] * m
    for i in range(n):
        if switch[i]==1:
            for j in range(m):
                if i+1 in t[j]:
                    light[j] = 1-light[j]
    if light == p:
        ret = 1
    else: ret = 0

    if cur == n:
        return ret
    else:
        switch1 = switch.copy()
        switch1[cur] = 1
        return dfs(cur+1, switch) + dfs(cur+1, switch1)

print(dfs(0, [0] * n))

Measured memory_bytes: 3064
#include "bits/stdc++.h"
using namespace std;
const int N=1e5+20;
int n,m,a,b;
vector <int> v[N];
long long ans;
multiset <int> ms;
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d",&a,&b);
		if(a>m) continue;
		v[m-a].push_back(b);
	}

	for(int i=N-1;i>=0;i--)
	{
		for(auto j:v[i]) ms.insert(j);
		if(ms.empty()) continue;
		ans+=*--ms.end();
		ms.erase(--ms.end());
	}

	printf("%lld",ans);
}

Measured memory_bytes: 7808
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define MOD          1000000007
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    move(vector<vector<T>>(h,move(vector<T>(w))))
#define VVI(T,h,w,i) move(vector<vector<T>>(h,move(vector<T>(w,i))))
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

int main()
{
	string s; cin >> s;
	cout << (count(ALL(s), 'C') * count(ALL(s), 'F') != 0 && s.find('C') < s.find_last_of('F') ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
IDENTIFICATION DIVISION.
PROGRAM-ID. 160B.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 X          PIC 9(10).
01 S1         PIC 9(8).
01 S2         PIC 9(3).
01 A          PIC 9(3).
01 OUT        PIC Z(9)9.
*>
PROCEDURE DIVISION.
  ACCEPT X.
*>
  DIVIDE X BY 500 GIVING S1 REMAINDER A.
  DIVIDE A BY 5   GIVING S2.
  COMPUTE OUT = S1 * 1000 + S2 * 5.
*>
  DISPLAY FUNCTION TRIM(OUT).
  STOP RUN.

Measured memory_bytes: 892
#include"bits/stdc++.h"
using namespace std;
#define ll long long


int main()
{
    ll h;
    cin>>h;
    ll sum=1;

    for(int i=2;i<=45;i++)
    {
        sum*=2;
        if(sum>h)
        {
            cout<<sum-1<<endl;
            return 0;
        }
        //cout<<"YES"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(ll i = ll(a); i < ll(b); i++)
#define rer(i, a, b) for(ll i = ll(a) - 1; i >= ll(b); i--)
#define sz(v) (int)(v).size()
#define pb push_back
#define sc second
#define fr first
#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())
using namespace std;
typedef long long int ll;
typedef pair <int, int> P;

const ll MOD=1000000007;
vector<int> E[1000];
int X[1000];
int dp1[1000][2];
bool used[1000];
void dfs(int x){
    used[x]=1;
    if(sz(E[x])==0){
        dp1[x][1]=X[x];
        return;
    }
    else{
        rep(i,0,sz(E[x])){
            if(used[E[x][i]]==0) dfs(E[x][i]);
            if(dp1[E[x][i]][1]<0){
                dp1[x][1]=-1;
                return;
            }
        }
        bool dp2[sz(E[x])][X[x]+1];
        int sum=0;
        rep(i,0,sz(E[x])){
            sum+=dp1[E[x][i]][1]+dp1[E[x][i]][0];
            rep(j,0,X[x]+1){
                if(i==0){
                    dp2[i][j]=(dp1[E[x][i]][1]==j||dp1[E[x][i]][0]==j);
                    //cout<<dp2[i][j]<<"\n";
                }
                else{
                    dp2[i][j]=((j>=dp1[E[x][i]][1]&&dp2[i-1][j-dp1[E[x][i]][1]])||(j>=dp1[E[x][i]][0]&&dp2[i-1][j-dp1[E[x][i]][0]]));
                    //cout<<dp2[i][j]<<"\n";
                }
            }
        }
        bool t=true;
        rep(j,0,X[x]+1){
            if(dp2[sz(E[x])-1][j]){
                dp1[x][1]=X[x];
                t=false;
                break;
            }
        }
        if(t){
            dp1[x][1]=-1;
            return;
        }
        rer(j,X[x]+1,0){
            if(dp2[sz(E[x])-1][j]){
                dp1[x][0]=sum-j;
                break;
            }
        }
        return;
    }
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin>>N;
    rep(i,0,N-1){
        int P;
        cin>>P;
        E[P-1].pb(i+1);
    }
    rep(i,0,N){
        cin>>X[i];
    }
    dfs(0);
    cout <<(dp1[0][1]==-1?"IMPOSSIBLE":"POSSIBLE")<<"\n";
}

Measured memory_bytes: 512
import sys
import heapq, math
from itertools import zip_longest, permutations, combinations, combinations_with_replacement
from itertools import accumulate, dropwhile, takewhile, groupby
from functools import lru_cache
from copy import deepcopy

n = int(input())
S = input()

if n % 2 == 1:
    print("No")
else:
    print("Yes" if S[0:n // 2] == S[n // 2:n] else "No")

Measured memory_bytes: 3572
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		// Declare
		String out = "ABD";

		// Receive number
    	Scanner sc = new Scanner(System.in);
    	int n = sc.nextInt();

		// Check
		if ((1 <= n) && (n <= 999)) {
			out = "ABC";
		} else if ((1000 <= n) && (n <= 1998)) {
			out = "ABD";
		}

		// Display
		System.out.print(out);
	}
}

Measured memory_bytes: 20948