akhauriyash/Code-Regression huggingface dataset:
import itertools

n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))

i = 1
for l in itertools.permutations(list(range(1, n + 1))):
    if l == p:
        x = i
    if l == q:
        y = i
    i += 1

print(abs(x - y))

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

int main() {
  char c11, c12, c13, c21, c22, c23;
  cin >> c11 >> c12 >> c13 >> c21 >> c22 >> c23;

  if(c11==c23 && c12==c22 && c13==c21){
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
  return 0;
}

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

#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define FILL0(x) memset(x,0,sizeof(x))
#define FILL1(x) memset(x,-1,sizeof(x))

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    int n;
    cin >> n;

    bool nprime[n]={false};
    vector<int> a(1000010);
    
    rep(i, n)
    {
        int val;
        cin >> val;
        a[val]++;
    }
    bool f =false;
    int uprime[1000001]={0};
    int aa[1000001]={0};
    for(int i=2; i<1000001; i++)
    {
        if(uprime[i]==0)
        {
            for(int j=0; i+i*j<1000001; j++)
            {
                uprime[i+i*j]=1;
                aa[i]+=a[i+i*j];
            }
            if(aa[i]>1)
            {
                f=true;
            }
            if(aa[i]==n)
            {
                cout << "not coprime" << endl;
                return 0;
            }
        }
    }

    if(f)
    {
        cout << "setwise coprime" << endl;
    }
    else
    {
        cout << "pairwise coprime" << endl;
    }
    
 
    return 0;
}

Measured memory_bytes: 15828
#include <stack>
#include <utility>
#include <iostream>
#include <string>
using namespace std;

int main()
{
	string str;
	stack<int>s;
	stack< pair<int,int> >rep;
	cin >> str;
	for (int i = 0; i < str.size(); i++) {
		if (str[i] == '\\') { s.push(i); }
		if (str[i] == '/') {
			if (!s.empty()) {
				int k = s.top();
				s.pop();
				int p=0;
				while (!rep.empty() && (rep.top()).first>k) { p+=(rep.top()).second; rep.pop(); }
				 { rep.push(pair<int, int>(k, i - k + p)); }
			}
		}
		if (str[i] != '\\'&&str[i] != '/'&&str[i] != '_')break;
	}int ans = 0; int a[20009]; int cnt = 0; int ss = rep.size();
	for (int i = 0; i <ss; i++) {
		a[i] = (rep.top().second); ans += a[i]; rep.pop();
	}
	cout << ans << endl;
	cout << ss;
	for (int i = ss-1; i >=0; i--) {
		cout <<" "<<a[i];
	}
	cout << endl;
    return 0;
}

Measured memory_bytes: 1324
import java.util.*;
public class Main {
    static Map<Integer,List<Integer>> map = new HashMap();
    static int dp[] = new int[100001];
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int edges = sc.nextInt();
        int dp[] = new int[n+1];
        int ans = 0;
        for(int i=0;i<edges;i++){
            int a = sc.nextInt();
            int b = sc.nextInt();
            if(!map.containsKey(a))
                map.put(a,new ArrayList());
            map.get(a).add(b);
        }
        for(int i=1;i<=n;i++){
            ans = Math.max(ans,dfs(i));
        }
        System.out.println(ans);
    }
    static int dfs(int cur){
        int tmp = 0;
        if(dp[cur]!=0){
            return dp[cur];
        }
        if(!map.containsKey(cur))
            return 0;
        for(int next : map.get(cur))
            tmp = Math.max(tmp,dfs(next)+1);
        dp[cur] = tmp;
        return tmp;
    }
}


Measured memory_bytes: 82428
import collections
import sys
import numpy as np
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop
MOD = 10**9+7
import itertools

def gcd(a,b):
    if b == 0:
        return a
    else:
        return gcd(b,a%b)
#入力
k = int(input())
ans = 0
gcdli = []
for i in range(1,k+1):
    for j in range(1,k+1):
        pregcd = gcd(i,j)
        gcdli.append(pregcd) #a,bの最大公約数は求まった
"""
for i in range(len(gcdli)):
    for j in range(1,k+1):
        ans += gcd(gcdli[i],j)
"""
c = collections.Counter(gcdli)
valu = []
for value in c.values():
    valu.append(value)
ans = valu[0]*k
for i in range(1,k):
    kaisuu = valu[i]
    for j in range(kaisuu):
        for d in range(1,k+1):
            ans += gcd(i+1,d)
print(ans)

Measured memory_bytes: 27484
using System;
using System.CodeDom.Compiler;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Xml;

class Program
{
	static void Main(string[] args)
	{
		long N = long.Parse(Console.ReadLine());
		HashSet<string> HS = new HashSet<string>();
		for(long l = 0;l < N; l++)
		{
			HS.Add(Console.ReadLine());
		}
		Console.WriteLine(HS.Count);
	}
}

//string s = Console.ReadLine();
//int[] intArray = Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
//int H = intArray[0];
//int W = intArray[1];
//int N = int.Parse(Console.ReadLine());
//List<int> A = new List<int>(Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray());
//Boolean ok = false;

//Console.WriteLine(ans);
//Console.WriteLine("Yes");
//Console.WriteLine("No");
//Console.ReadKey();

//string[] strArray = Console.ReadLine().Split(' ').ToArray();
//string S = strArray[0];
//string T = strArray[1];


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

#define	INF (1<<29)

int	main() {
	int N, M, R;
	cin >>N >>M >>R;
	vector<int> r(R);
	// Input: Nodes to go
	for (int i=0; i<R; i++)
		cin >>r.at(i);
	// Input: Bridges
	vector<vector<int>>	bridge(M, vector<int> (3));
	for (int i=0; i<M; i++) {
		for (int j=0; j<3; j++) {
			cin >> bridge.at(i).at(j);
		}
	}
	// Struct for each node
	struct Node {
		vector<int> to_node;
		vector<int> cost_to_node;
		bool fix;
		int cost;
	};
	vector<Node> node(N);
	// Data for each node
	for (int i=0; i<M; i++) {
		int F=bridge.at(i).at(0)-1;
		int T=bridge.at(i).at(1)-1;
		int L=bridge.at(i).at(2);
		node.at(F).to_node.push_back(T);
		node.at(F).cost_to_node.push_back(L);
		node.at(T).to_node.push_back(F);
		node.at(T).cost_to_node.push_back(L);
	}
	// Distance between nodes
	vector<vector<int>> D(R, vector<int> (R, 0));
	for (int i=0; i<R; i++) {
		// Clear
		for (int i=0; i<N; i++) {
			node.at(i).fix=false;
			node.at(i).cost=INF;
		}
		node.at(r.at(i)-1).cost=0;
		priority_queue<vector<int>, vector<vector<int>>, greater<vector<int>>> q;
		q.push({node.at(r.at(i)-1).cost, r.at(i)-1});
		// till all fixed
		while (!q.empty()) {
			// Pickup the Node with minimum cost
			int c=q.top().at(0);
			int ii=q.top().at(1);
			q.pop();
			// If fixed, skip
			if(node.at(ii).fix)
				continue;
			// Change it to fixed and search for near-by nodes
			node.at(ii).fix=true;
			for (int i=0; i<node.at(ii).to_node.size(); i++) {
				int o_node=node.at(ii).to_node.at(i);
				// Update cost
				int o_cost=node.at(ii).cost_to_node.at(i)+c;
				// Process only when smaller
				if (o_cost>=node.at(o_node).cost)
					continue;
				node.at(o_node).cost=o_cost;
				// Push into queue
				q.push({o_cost, o_node});
			}
		}
		for (int j=0; j<R; j++) {
			D.at(i).at(j)=node.at(r.at(j)-1).cost;
		}
	}
	// D fixed
	vector<int> order(R);
	for (int i=0; i<R; i++)
		order.at(i)=i;
	int S=INF;
	do {
		int SS=0;
		for (int i=0; i<R-1; i++)
			SS += D.at(order.at(i)).at(order.at(i+1));
		S = min(S, SS);
	} while(next_permutation(order.begin(), order.end()));
	cout <<S <<endl;
	return 0;
};


Measured memory_bytes: 1792
lis=list([int(input()) for i in range(5)])
ans=0
for i in range(5):
    if lis[i]%10!=0:
        ans+=(lis[i]-lis[i]%10)+10
    else:
        ans+=lis[i]
a=[]
for i in range(5):
    a.append((lis[i]-1)%10)
print(ans+min(a)-9)

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

class UnionFind
{
  public:
    vector<long long> root;

    UnionFind(long long N)
    {
        root = vector<long long>(N + 1, -1);
    }

    long long find_root(long long A)
    {
        if (root[A] < 0)
        {
            return A;
        }
        else
        {
            root[A] = find_root(root[A]);
        }
        return root[A];
    }

    long long size(long long A)
    {
        return -root[find_root(A)];
    }

    bool unite(long long A, long long B)
    {
        A = find_root(A);
        B = find_root(B);
        if (A == B)
        {
            return false;
        }

        if (size(A) < size(B))
        {
            swap(A, B);
        }

        root[A] += root[B];
        root[B] = A;

        return true;
    }

    bool has_same_root(long long A, long long B)
    {
        return find_root(A) == find_root(B);
    }
};

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

    int matrix[N][N] = {};
    int a[M], b[M];
    for (int i = 0; i < M; i++)
    {
        cin >> a[i] >> b[i];
    }

    int ans = 0;
    for (int i = 0; i < M; i++)
    {
        UnionFind unionfind(N);
        for (int j = 0; j < M; j++)
        {
            if (j != i)
            {
                unionfind.unite(a[j], b[j]);
            }
        }
        bool flag = true;
        for (int j = 1; j <= N; j++)
        {
            for (int k = j + 1; k <= N; k++)
            {
                flag &= unionfind.has_same_root(j, k);
            }
        }
        if (!flag)
        {
            ans++;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
int ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.second < secondElof.second;
}
ll nod(ll F) { return log10(F) + 1; }
//**定義場所**//
//gcd, isPrime, eratos, modinv, bitSearch, dfs, bfs, dijkstra, UnionFind//
ll i, j, k, l, m, n; ll N, M, K, H, W, L; string S;
ll MOD = 1000000007; ll ans = 0; ll INF = 9999999999999;
vl flag, color; vll path;
//***********//
int main() {
	double A, B;
	cin >> A >> B;
	for (i = 0; i <= 10000; i++) {
		double p = 0.08;
		double q = 0.1;
		double P1 = i * p;
		double P2 = i * q;
		ll Q1 = P1 / 1;
		ll Q2 = P2 / 1;
		if (Q1 == A && Q2 == B) {
			cout << i;
			exit(0);
		}
	}
	cout << -1;
}


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

int N, x;
int a[110];

int main() {
    cin >> N >> x;
    for (int i = 0; i < N; i++) cin >> a[i];

    sort(a, a+N);

    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (i < N-1 && x >= a[i]) {
            x -= a[i];
            ans++;
        }
        else if (i == N-1 && x == a[i]) {
            ans++;
        }
        else {
            break;
        }
    }
    
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <math.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <queue>
#include <iomanip>
#include <deque>
#include <map>

typedef long long ll;
#define rep(i, a, n) for(int i = a; i<n; i++)
#define ALL(a) begin(a), end(a)
#define mii map<int, int>
#define msi map<string, int>
#define vi vector<int>
#define vl vector<ll>
#define MOD 1000000007
using namespace std;
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() {
    ll N;
    cin >> N;
    if (N % 2 != 0) {
        cout << 0 << endl;
        return 0;
    } else {
        ll a = 10;
        ll ans = 0;
        while (a <= N) {
            ans += N / a;
            a *= 5;
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
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();
		
		for(int i = 0; i < K; i++){
			if(A > B && A > C){
				A = A*2;
			}
			if(B > A && B > C){
				B = B*2;
			}
			if(C > A && C > B){
				C = C*2;
			}
			
			if(A == C && A > B){
				A = A*2;
			}
			if(A == B && A > C){
				A = A*2;
			}
			if(B == C && B > A){
				B = B * 2;
			}
			if(A == B && B == C){
				A = A*2;
			}
		}
		int S = A + B + C;
		System.out.println(S);
	}
}


Measured memory_bytes: 20948
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main() {
	int n,m=0;
	cin >> n;
	vector<int> a(101, 0);
	for (int i = 0; i < n; i++) {
		int b; cin >> b;
		a[b]++;
	}
	for (int i = 100; i >= 1; i--) {
		a[i-1]+= a[i];
	}
	for (int i = 1; i <=100; i++) {
		if (a[i] >= i) {
			m = i;
		}
	}
	cout << m << endl;
}



Measured memory_bytes: 3116
import bisect
n = int(input())
l = list(map(int, input().split()))
l.sort()

ans = 0
for i in range(len(l)-2):
    for j in range(i+1, len(l)-1):
        a1 = l[i] + l[j]
        index = bisect.bisect_left(l, a1)
        if index:
            ans += index - j - 1
print(ans)

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

using namespace std;
const int N = 1e5 + 10;

int n, m, s, t;
vector<int> G[N];
deque<int> Q;

bool flag[N];

bool go()
{
	for (int i = 0; i < (int) G[s].size(); i++)
	{
		int v = G[s][i];
		if (!flag[v])
		{
			Q.push_front(v);
			s = v;
			flag[s] = 1;
			return 1;
		}
	}
	for (int i = 0; i < (int) G[t].size(); i++)
	{
		int v = G[t][i];
		if (!flag[v])
		{
			Q.push_back(v);
			t = v;
			flag[t] = 1;
			return 1;
		}
	}
	return 0;
}
int main()
{
	cin >> n >> m;
	for (int i = 1; i <= m; i++)
	{
		int u, v;
		scanf("%d%d", &u, &v);
		G[u].push_back(v);
		G[v].push_back(u);
		s = u;
		t = v;
	}
	
	flag[s] = flag[t] = 1;
	Q.push_back(s);
	Q.push_back(t);
	while (go());
	int ans, cnt = 0;
	printf("%d\n", ans = Q.size());
	while (!Q.empty())
	{
		int u = Q.front();
		Q.pop_front();
		printf("%d%c", u, " \n"[++cnt == ans]);
	}
	return 0;
}

Measured memory_bytes: 6784
N, M, C = map(int, input().split())
bias = [int(i) for i in input().split()]
sources = [[int(i) for i in input().split()] for _ in range(N)]

oks = 0

for source in sources:
    score = C
    for key in range(M):
        score += bias[key] * source[key]
    if score> 0:
        oks += 1

print(oks)


Measured memory_bytes: 38384
#include <cstdio>
#include <algorithm>
#define fs first
#define sc second
#define mp make_pair
#define ll long long
#define org b[1].sc
#define rep(i,j,k) for (i=j;i<=k;i++)
#define down(i,j,k) for (i=j;i>=k;i--)
using namespace std;
const int N=2e5+5,mod=1e9+7;
typedef pair<int,int> Pair;
Pair a[N],b[N];
int n,bn,col,X,Y,i,sum,ans;
int fac[N],inv[N],cnt[N],flg[N],Min[N],con[N];
int fgm(int a,int n)
{
	int ret=1,bsc=a;
	for (;n>0;n>>=1,bsc=(ll)bsc*bsc%mod)
		if (n&1) ret=(ll)ret*bsc%mod;
	return ret;
}
int main()
{
//	freopen("colorful.in","r",stdin);
//	freopen("colorful.out","w",stdout);
	
	scanf("%d%d%d",&n,&X,&Y);
	rep(i,1,n) scanf("%d%d",&a[i].sc,&a[i].fs);
	sort(a+1,a+1+n);
	rep(i,1,n)
		if (!flg[a[i].sc]) b[++bn]=a[i],Min[a[i].sc]=a[i].fs,flg[a[i].sc]=1;
	if (bn==1 || b[1].fs+b[2].fs>Y) { printf("1\n"); return 0; }
	
	rep(i,2,bn) {
		if (b[i].fs+b[1].fs>Y) break;
		con[b[i].sc]=1;
	}
	
	rep(i,1,n)
	{
		col=a[i].sc;
		if (col==org) {
			if (a[i].fs+Min[col]<=X || a[i].fs+b[2].fs<=Y) cnt[col]++;
		}
		else
		if (con[col]) {
				if (a[i].fs+Min[col]<=X || a[i].fs+Min[org]<=Y) cnt[col]++;
		}
	}
	
	fac[1]=1; rep(i,2,n) fac[i]=(ll)fac[i-1]*i%mod;
	inv[n]=fgm(fac[n],mod-2);
	down(i,n-1,1) inv[i]=(ll)inv[i+1]*(i+1)%mod;
	
	ans=1;
	rep(i,1,n)
		if (cnt[i]) sum+=cnt[i],ans=(ll)ans*inv[cnt[i]]%mod;
	ans=(ll)ans*fac[sum]%mod;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 7808
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
#include <bitset>
#include <complex>
#include <cmath>
#include <array>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=2050;
//ここまでテンプレ
int main(){
	int R;
	cin>>R;
	if(R<1200)
		cout<<"ABC"<<endl;
	else if(R<2800)
		cout<<"ARC"<<endl;
	else
		cout<<"AGC"<<endl;
	return 0;
}

Measured memory_bytes: 768
import math

N,P = map(int,input().split())
A = list(map(int,input().split()))
pascal_triangle = []

memo = [[0 for _ in range(51)] for _ in range(51)]

def c(n,k):
  if memo[n][k] != 0:
      return memo[n][k]
  if(k<=0 or n<=k):
      memo[n][k] = 1
      return 1
  else:
      ans = c(n-1, k-1) + c(n-1, k)
      memo[n][k] = ans
      return ans

for i in range(51):
  pascal_triangle.append([c(i,j) for j in range(i+1)])

Numbers_1 = 0
for i in range(N):
    Numbers_1 += A[i] % 2

Select_0_count = sum(pascal_triangle[N - Numbers_1])

ans = 0

for i in range(Numbers_1+1):
    if i % 2 == P:
        ans += pascal_triangle[Numbers_1][i] * Select_0_count

print(ans)

Measured memory_bytes: 9164
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
const int N=1e5+3,inf=0x7fffffff;
int cnt,n,a[N],maxx,fail,minn=inf;
int main(){
	scanf("%d",&n);
	for(int i = 1;i<=n;i++){
		scanf("%d",&a[i]);
		if(a[i]>maxx) maxx=a[i],fail=i;
	}
	a[fail]=0;
	int mid=maxx/2;
	for(int i = 1;i<=n;i++){
		if(abs(a[i]-mid)<minn){
			minn=abs(a[i]-mid);
			cnt=a[i];
		}
	}
	printf("%d %d",maxx,cnt);
	return 0;
}

Measured memory_bytes: 640
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;

//typedef
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//conversion
inline LL toLong(string s) {LL 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;}

//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) LL((a).size())
#define EACH(i,c) for(auto 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(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define UNTIL(p) while(!(p))

//constant
const double EPS = 1e-5;
const double PI  = acos(-1.0);

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define PUTS(x) cout << (x) << endl;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    LL x;
    cin>>x;

    LL ans = 0;
    LL a = 100;
    while(a < x){
        ans++;
        a += a/100;
    }
    PUTS(ans);
}

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

int main()
{
	int n;
	double ans,num;
    cin>>n;
    if(n==1) cout<<1;
    else if(n%2==0) cout<<0.50;
    else {
    	num=n-n/2;
    	ans=num/n;
    	cout<<ans;
	}
}

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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const lint MOD   = 1e9 + 7;
const double EPS = 1e-10;

int main() {
    int K, N;
    cin >> N >> K;
    vector<int> P(N, 0);
    rep(i, N) { cin >> P[i]; }

    vector<double> Q(N, 0);
    for (int i = 0; i < N; i++) {
        double x = P[i];
        Q[i]     = (x * (1 + x) / 2) / x;
    }
    vector<double> L(N + 1, 0.0);
    for (int i = 0; i < N; i++) {
        L[i + 1] = L[i] + Q[i];
    }
    double ans = -1;
    for (int i = 0; i < N; i++) {
        if (i + K > N) break;
        ans = max(ans, L[i + K] - L[i]);
    }
    cout << setprecision(10) << ans << endl;
    return 0;
}

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

int main() {
    int n;
    const int principal = 10000;

    while (cin >> n, n) {
        int y, b, r, t, p, maxp, bid;
        cin >> y;
        maxp = 0;
        while (n--) {
            cin >> b >> r >> t;
            if (t == 1) { // simple
                p = principal * (100 + y * r) / 100;
            }
            else { // compound
                p = principal * pow(1 + (double)r / 100, y);
            }
            if (maxp < p) {
                maxp = p;
                bid = b;
            }
        }
        cout << bid << endl;
    }
    return 0;
}

Measured memory_bytes: 1168
N=int(input())
S=input()

value=0
ord("a")
for i in range(1,N):
    data1=[0 for i in range(ord("z")-ord("a")+1)]
    data2=[0 for i in range(ord("z")-ord("a")+1)]
    for s in S[:i]:
        data1[ord(s)-ord("a")]+=1
    for s in S[i:]:
        data2[ord(s)-ord("a")]+=1

    value=max(len([1 for i,m in zip(data1,data2) if i and m]),value)
print(value)


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

int main () {
  int x,a,b;
  cin >> x >> a >> b;

  int xa,xb;
  if (x>a) xa=x-a;
  else xa=a-x;
  if (x>b) xb=x-b;
  else xb=b-x;

  char ans;
  if (min(xa,xb)==xa) ans='A';
  else ans='B';

  cout << ans << endl;
  
  return 0;
}


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

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,int> plli;
typedef pair<int,pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()

const ll mod = 1e9 + 7;
const ll INF = 1<<30;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, c;
    cin >> a >> b >> c;
    while (a != 0) {
        int n;
        cin >> n;
        int ans[a + b + c + 1];
        fill(ans, ans + a + b + c, 2);
        int ii[n] = {}; int jj[n] = {}; int kk[n] = {}; int rr[n] = {};
        rep(m, n) {
            int i, j, k, r;
            cin >> i >> j >> k >> r;
            ii[m] = i; jj[m] = j; kk[m] = k; rr[m] = r;
            if (r == 1) {
                ans[i] = 1;
                ans[j] = 1;
                ans[k] = 1;
            }
            else {
                if (ans[i] == 1 && ans[j] == 1) ans[k] = 0;
                else if (ans[i] == 1 && ans[k] == 1) ans[j] = 0;
                else if (ans[j] == 1 && ans[k] == 1) ans[i] = 0;

            }

        }
        rep(m, n) {
            int i = ii[m]; int j = jj[m]; int k = kk[m]; int r = rr[m];
            if (r == 1) {
                ans[i] = 1;
                ans[j] = 1;
                ans[k] = 1;
            }
            else {
                if (ans[i] == 1 && ans[j] == 1) ans[k] = 0;
                else if (ans[i] == 1 && ans[k] == 1) ans[j] = 0;
                else if (ans[j] == 1 && ans[k] == 1) ans[i] = 0;

            }

        }
        rep2(i, 1, a + b + c + 1) cout << ans[i] << endl;
        cin >> a >> b >> c;
    }
}

Measured memory_bytes: 3120
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <stack>

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? (-(a)) : (a))

typedef long long ll;

using namespace std;

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

	long long L;

	scanf("%lld", &L);
	printf("%Lf\n", 1.0L * L / 3 * L / 3 * L / 3);

	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef long long ll;

int main(void){
    string S;
    cin >> S;
    
    reverse(S.begin(), S.end());
    
    vector<string> word(4);
    word[0] = "dream";
    word[1] = "dreamer";
    word[2] = "erase";
    word[3] = "eraser";
    
    rep(i, 4) {
        reverse(word[i].begin(), word[i].end());
    }
    
    int i = 0;
    while (i < S.size()) {
        bool ok;
        for (string s : word) {
            ok = true;
            rep(j, s.size()) {
                if (S[i + j] != s[j]) {
                    ok = false;
                }
            }
            if (ok) {
                i += s.size();
                break;
            }
        }
        if (!ok) break;
    }
    
    if (S.size() == i) {
        puts("YES");
    } else {
        puts("NO");
    }
}


Measured memory_bytes: 512
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<iostream>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<cmath>
#include<string>

#define ls (t<<1)
#define rs ((t<<1)+1)
#define mid ((l+r)>>1)
#define fi first
#define se second
#define mk make_pair
#define pb push_back

#define N 100005
#define M 200005
#define seed 23333

using namespace std;
int i,j,m,n,p,k,A[N],x;
long long ans;
int main()
{
		scanf("%d%d",&n,&x);
		for (i=1;i<=n;++i) 
		{
			scanf("%d",&A[i]);
			if (A[i]>x) ans+=A[i]-x,A[i]=x;
		}
		for (i=2;i<n;++i)
		{
				if (A[i-1]+A[i]<=x) continue;
				int now=(A[i-1]+A[i]-x);
				A[i]-=now;
				ans+=now;
		}
		if (A[n-1]+A[n]>=x) ans+=A[n-1]+A[n]-x;
		printf("%lld\n",ans);
}


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

int main() {
  int a, b;
  cin >> a >> b;
  int ans = a - 2 * b;
  if (ans < 0)
    ans = 0;
  cout << ans << endl;
}

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

using namespace std;


string s;

int counting(char c) { 
    int counter = 0;
    for(int i = 0; i < s.size(); i++) { 
        if(s[i] == c) {
            counter++;
        }
    }    
    return counter;
}

int main() {
    cin >> s;
    int n = s.size();
    if(n == 1) {
        puts("YES");
        return 0;
    }
    if(n == 2) {
        if(s[0] == s[1]) {
            puts("NO");
        } else {
            puts("YES");
        }
        return 0;
    }
    if(n == 3) {
        if(s[0] == s[1] || s[1] == s[2] || s[0] == s[2]) {
            puts("NO");
        } else {
            puts("YES");
        }
        return 0;
    }
    int a = counting('a');
    int b = counting('b');
    int c = counting('c');
    int diff1 = abs(a - b);
    int diff2 = abs(b - c);
    int diff3 = abs(a - c);
    if(diff1 > 1 || diff2 > 1 || diff3 > 1) {
        puts("NO");
    } else {
        puts("YES");
    }
    return 0;
}

Measured memory_bytes: 3764
import sys

#+++++
		
def main():
	n = int(input())
	if n == 1:
		print('Hello World')
		return 
	else:
		a=int(input())
		b=int(input())
		print(a+b)
		return
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)

if __name__ == "__main__":
	if sys.platform =='ios':
		sys.stdin=open('inputFile.txt')
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

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

int main() {
  int n, sum = 0;
  cin >> n;
  int tmp = n;
  while(0 != n){
  	sum += n % 10;
    n /= 10;
  }
  if(tmp % sum == 0){
  	cout << "Yes" << endl;
  }else{
  	cout << "No" << endl;
  }
  return 0; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < n; ++i)
ll dx[4] = { 0, 1, 0, -1 };
ll dy[4] = { 1, 0, -1, 0 };
const ll INF = 1e14;
const ll MOD = 1e9 + 7;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll N, D;
    cin >> N >> D;
    ll X[15][15];
    rep(i, N)
    {
        rep(j, D)
        {
            cin >> X[i][j];
        }
    }
    int cnt = 0;
    for (int i = 0; i < N; ++i) {
        for (int j = i + 1; j < N; ++j) {
            int area = 0;
            for (int k = 0; k < D; ++k) {
                area += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
            }
            for (int p = 0; p <= 200; ++p) {
                if (p * p == area) {
                    cnt++;
                }
            }
        }
    }
    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int w = s.nextInt();
		int a = s.nextInt();
		int b = s.nextInt();

		int answer = b - (a + w);
		int ans = a - (b + w);
		if (a <= b) {
			if (answer < 0) {
				System.out.println("0");
			} else {
				System.out.println(answer);
			}
		}else if (a > b) {
			if (ans < 0) {
				System.out.println("0");
			} else {
				System.out.println(ans);
			}
		}

	}
}

Measured memory_bytes: 21076
#include <bits/stdc++.h>
#define maxs 2020202
#define ll long long
#define mme(i,j) memset(i,j,sizeof(i))
using namespace std;

int main()
{
    ll n,t;
    while(~scanf("%lld%lld",&n,&t))
    {
        ll ans = 0 ,stop=0,x;
        for(int i=1;i<=n;i++){
            scanf("%lld",&x);
            if(x>=stop)
                ans+=t;
            else
                ans+= t-(stop-x);

            stop = t+x;
        }
        printf("%lld\n",ans);
    }
    return 0;
}

Measured memory_bytes: 256
#-*-coding:utf-8-*-
import sys
input=sys.stdin.readline

def main():
    steps=[]
    step_data=[]
    step = int(input())
    steps=list(map(int,input().split()))
    count=0

    for idx in range(1,len(steps)):
        if steps[idx-1]>=steps[idx]:
            count+=1
        else:
            step_data.append(count)
            count=0
    step_data.append(count)
    print(max(step_data))
        

if __name__=="__main__":
    main()

Measured memory_bytes: 20588
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define fi first
#define se second
#define mp make_pair
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
#define dame { printf("No\n"); return 0;}
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;
#define MOD llong(1e9+7)
#define MAX int(2 * 1e5 +5)
#define debug(x)  cout << #x << " = " << (x) << endl;
#define pi acos(-1.0)
#define int llong
#define INF llong(1e17)


signed main(){
    int n;
    cin >> n;
    int tmp,old = -1;
    int iti[MAX] = {};
    vector< pair<int ,int > > kukan;
    REP(i,n){
        scanf("%lld",&tmp);
        if(i ==0) old = tmp;
        if(tmp!= old){
            if(iti[tmp] !=0) kukan.push_back ( mp (iti[tmp],i + 1) );
            old = tmp;
        }
        iti[tmp] = i + 1;
    }
    Sort(kukan);
//    itrfor(itr,kukan) cout << itr->fi << " " << itr->se << endl;
    int ans[n+2];
    ans[n+1] = 1;
    int kosuu = kukan.size();
    int id = kosuu -1;
    REPR(i,n){
        if(id >= 0 and i == kukan[id].fi){
            ans[i] = ans[i+1] + ans[kukan[id].se] ;
            id--;
        }
        else{
            ans[i] = ans[i+1];
        }
        ans[i] %= MOD;
        
    }
//    REP(i,n) cout << ans[i] << endl;


    cout << ans[0] << endl;

}


Measured memory_bytes: 8176
#define _USE_MATH_DEFINES
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<list>
#include<stack>
#include<queue>
#include<cctype>
#include<iomanip>
#include<functional>
#include<numeric>
#include<map>
#include<set>
#include<complex>
#define EPS 1e-10
using namespace std;
typedef long long llong;
class Point {
public:
	int x, y;
};
int cross(Point z, Point a, Point b) {
	a.x -= z.x; a.y -= z.y;
	b.x -= z.x; b.y -= z.y;
	return a.x*b.y - a.y*b.x;
}
bool juge(Point z, Point a, Point b, Point c) {
	bool g = false, h = false;
	if (cross(z, a, b) > 0 && cross(z, b, c) > 0 && cross(z, c, a) > 0) {
		g = true;
	}
	if (cross(z, a, b) < 0 && cross(z, b, c) < 0 && cross(z, c, a) < 0) {
		h = true;
	}
	return g || h;
}
int main() {
	int n; cin >> n;
	while (n--) {
		Point p1, p2, p3, k, s;
		cin >> p1.x >> p1.y >> p2.x >> p2.y >> p3.x >> p3.y >> k.x >> k.y >> s.x >> s.y;
		bool g = juge(k, p1, p2, p3);
		bool h = juge(s, p1, p2, p3);
		if (g^h == true)cout << "OK" << endl;
		else cout << "NG" << endl;

	}
	return 0;
}

Measured memory_bytes: 3040
#include <bits/stdc++.h>
#define rep(i,N) for(int i=0;i<N;i++)
using namespace std;
long long  INF=1000000000000000000;
long long mod=1000000007;
using namespace std;


int main(){
int N;
cin>>N;
vector<vector<int>>to(N);
vector<pair<int,int>>bre(N-1);
int cnt[N]={};
rep(i,N-1){
    int a,b;
    cin>>a>>b;
    a--,b--;
    bre[i]=make_pair(a,b);
    to[a].emplace_back(b);
    to[b].emplace_back(a);
    cnt[a]++;
    cnt[b]++;
}
vector<long long >c(N);
rep(i,N){
    cin>>c[i];
}
sort(c.begin(),c.end());
multimap<int,int>v;
rep(i,N){
    v.insert(make_pair(-cnt[i],i));
}
auto iter=v.begin();
int start=iter->second;

int p=N-1;
bool checked[N]={};
long long ans[N];
queue<int>q;
q.push(start);
checked[start]=true;

while(!q.empty()){
    int now=q.front();
    q.pop();
    ans[now]=c[p];
    p--;
    for(auto vp:to[now]){
        if(checked[vp])continue;
        checked[vp]=true;
        q.push(vp);
    }
}
long long M=0;
rep(i,N-1){
M+=min(ans[bre[i].first],ans[bre[i].second]);
}

cout<<M<<endl;

rep(i,N){
    cout<<ans[i]<<" ";
}


 return 0;
}
/*

by my self
first       1h 21m 37s
second         20m 49s

5
1 2
2 3
3 4
4 5
1 2 3 4 5

10
1 2 3 4 5


5
1 2
1 3
1 4
1 5
3141 59 26 53 59

197
59 26 3141 59 53

*/

Measured memory_bytes: 1664
import java.util.*;
import java.io.*;
public class Main{
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
int n,k;
n = sc.nextInt();
k = sc.nextInt();
n = n+1;
n=n/2;
if(k>n)
System.out.println("NO");
else
System.out.println("YES");
}
}


Measured memory_bytes: 22740
import sys


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n, x = list(map(int, readline().split()))
    a = list(map(int, readline().split()))
    cnt = 0
    for i in range(n):
        if i == 0:
            if a[i] > x:
                t = abs(x - a[i])
                a[i] -= t
                cnt += t
        else:
            if a[i] + a[i-1] > x:
                t = abs(x - (a[i] + a[i-1]))
                a[i] -= t
                cnt += t
    print(cnt)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 58224
#include<iostream>
#define int long long
using namespace std;
const int N=3e5+5;
const int mod=998244353;
long long fact[N];
long long binpow(long long x,long long y){
	long long tich=1;
	while(y){
		if((y&1)){
			tich*=x;
			tich%=mod;
		}
		x=(x*x);
		x%=mod;
		y>>=1;
	}
	return tich;
}
long long C(int x,long long y){
	return ((fact[y]*binpow(fact[x],mod-2)%mod)*binpow(fact[y-x],mod-2))%mod;
}
signed main(){
	long long n,i,j,l,a,b,k;
	long long ans=0;
	cin>>n>>a>>b>>k;
	fact[0]=1;
	for(i=1;i<=n;i++){
		fact[i]=(fact[i-1]*i)%mod;
	}
	for(i=0;i<=min(n,k/a);i++){
		j=k-i*a;
		if(j%b!=0){
			continue;
		}
		j=j/b;
		if(j<=n){
			ans+=C(i,n)*C(j,n);
			ans%=mod;
		}
	}
	cout<<ans;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int main()
{
	ll i,j,k,n,s=0;
	cin>>n;
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=n;j++)
		{
			for(k=1;k<=n;k++)
			{
				s=s+__gcd(i,__gcd(j,k));
			}
		}
	}
	cout<<s;
	
    
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
#define mygc(c) (c)=getchar_unlocked()
#define mypc(c) putchar_unlocked(c)
void reader(int& x) { int k, m = 0; x = 0; for (;;) { mygc(k); if (k == '-') { m = 1; break; }if ('0' <= k&&k <= '9') { x = k - '0'; break; } }for (;;) { mygc(k); if (k<'0' || k>'9')break; x = x * 10 + k - '0'; }if (m) x = -x; }
void writer(int x, char c) { int s = 0, m = 0; char f[10]; if (x<0)m = 1, x = -x; while (x)f[s++] = x % 10, x /= 10; if (!s)f[s++] = 0; if (m)mypc('-'); while (s--)mypc(f[s] + '0'); mypc(c); }
template<class T> void writerLn(T x) { writer(x, '\n'); }
using namespace std;
typedef pair<int, int>P;

vector<P>E[100000];
int d[100000], b[100000], cnt[200001], u[200000], v[200000], r[200000], que[100000];
int main() {
	int n, m, q; reader(n); reader(m); reader(q);
	rep(i, m) {
		reader(u[i]); reader(v[i]); u[i]--; v[i]--; r[i] = q;
	}
	rep(i, q) {
		int a; reader(a); r[a - 1] = i;
	}
	rep(i, m) {
		E[u[i]].push_back(P(v[i], r[i])); E[v[i]].push_back(P(u[i], r[i]));
	}
	d[0] = 1; b[0] = q;
	int s = 0, g = 1;
	while (s != g) {
		int p = que[s++];
		rep(i, E[p].size()) {
			P v = E[p][i];
			if (d[v.first] == 0) {
				d[v.first] = d[p] + 1; que[g++] = v.first;
			}
			if (d[v.first] == d[p] + 1)
				b[v.first] = max(b[v.first], min(b[p], v.second));
		}
	}
	rep(i, n)cnt[b[i]]++;
	int ans = 0;
	rep(i, q) {
		ans += cnt[i];
		writer(ans, '\n');
	}
}

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

#define int long long

int x[1005], y[1005], z[1005];
int sum[9][1005];

signed main()
{
	int n, m;
	scanf ("%lld%lld", &n, &m);
	for (int i=1; i<=n; i++){
		scanf ("%lld%lld%lld", &x[i], &y[i], &z[i]);
		sum[1][i] = x[i] + y[i] + z[i];
		sum[2][i] = x[i] + y[i] - z[i];
		sum[3][i] = x[i] - y[i] + z[i];
		sum[4][i] = -x[i] + y[i] + z[i];
		sum[5][i] = x[i] - y[i] - z[i];
		sum[6][i] = -x[i] + y[i] - z[i];
		sum[7][i] = -x[i] - y[i] + z[i];
		sum[8][i] = -x[i] - y[i] - z[i];
	}
	
	int ans=0;
	for (int i=1; i<=8; i++){
		sort (sum[i]+1, sum[i]+n+1);
		int cnt=0;
		for (int j=1; j<=m; j++){
			cnt += sum[i][n-j+1];
		}
		
		ans = max (ans, cnt);
	}
	
	printf ("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 384
use std::error::Error;
use std::io;
use std::str::FromStr;

fn get_line() -> io::Result<String> {
	let mut buffer = String::new();
	io::stdin().read_line(&mut buffer)?;
	Ok(buffer)
}

#[allow(dead_code)]
fn get_input_number<T>() -> Result<T, Box<dyn Error + 'static>>
where
	T: FromStr,
	<T as FromStr>::Err: Error + 'static,
{
	Ok(get_line()?.trim().parse::<T>()?)
}

#[allow(dead_code)]
fn get_input_array<T>() -> Result<Vec<T>, Box<dyn Error + 'static>>
where
	T: FromStr,
	<T as FromStr>::Err: Error + 'static,
{
	Ok(get_line()?
		.split_whitespace()
		.map(|s| s.parse::<T>())
		.collect::<Result<Vec<_>, _>>()?)
}

fn main() -> Result<(), Box<dyn Error>> {
	let input = get_input_array::<u8>()?;
	if input[0] > input[1] {
		println!("{}", "safe");
	} else {
		println!("{}", "unsafe");
	}
	Ok(())
}


Measured memory_bytes: 2180
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<iomanip>
using namespace std;

int main(){
    int r;
    cin>>r;
    if(r<1200)cout<<"ABC"<<endl;
    else if(r>=1200&&r<2800)cout<<"ARC"<<endl;
    else cout<<"AGC"<<endl;

    return 0;
}

Measured memory_bytes: 3504
from collections import defaultdict

N, K = map(int, input().split())
Items = [tuple(map(int, input().split())) for _ in range(N)]
Items.sort(reverse=True, key=lambda x: x[1])
Kinds = defaultdict(int)
ans = 0
k = 0
Candidates = []
for i, (t, d) in enumerate(Items):
    if i < K:
        ans += d
        if t not in Kinds:
            k += 1
        else:
            Candidates.append(d)
        Kinds[t] += 1
        if i == K - 1:
            ans += k ** 2
            a = ans
    else:
        if Kinds[t]:
            continue
        if not Candidates:
            break
        else:
            x = Candidates.pop()
            a -= x
            a -= k ** 2
            k += 1
            a += d
            a += k ** 2
            Kinds[t] -= 1
            ans = max(ans, a)
print(ans)

Measured memory_bytes: 101968
#include <iostream>
#include <queue>

#define H_MAX 1005
#define W_MAX 1005

using namespace std;

char f[H_MAX][W_MAX];

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

int main() {
    int H, W;

    cin >> H >> W;

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

    queue< pair< int, int > > next;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (f[i][j] == '#') {
                for (int k = 0; k < 4; k++) {
                    int y = i + dy[k];
                    int x = j + dx[k];
                    if (y >= 0 && y < H && x >= 0 && x < W && f[y][x] == '.') {
                        f[y][x] = '-';
                        next.push(make_pair(y, x));
                    }
                }
            }
        }
    }

    int cnt = 0;
    while (!next.empty()) {
        cnt++;
        queue< pair< int, int > > q(next);
        queue< pair< int, int > >().swap(next);

        // cout << endl;
        // for (int i = 0; i < H; i++) {
        //     for (int j = 0; j < W; j++) {
        //         cout << f[i][j];
        //     }
        //     cout << endl;
        // }

        while (!q.empty()) {
            pair< int, int > p = q.front();
            q.pop();
            for (int k = 0; k < 4; k++) {
                int y = p.first + dy[k];
                int x = p.second + dx[k];
                if (y >= 0 && y < H && x >= 0 && x < W && f[y][x] == '.') {
                    f[y][x] = '-';
                    next.push(make_pair(y, x));
                }
            }
        }
    }

    cout << cnt << endl;
}


Measured memory_bytes: 9600
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) range(i,0,b)
#define debug(x) cout << "debug" << x << endl;
using namespace std;

int main(){
    int w,h,x,y,r;
    x = 1;
    while(cin >> w){
        if(w == 0) break;
        cout << "Case " << x << ": " << w << endl;
        x++;
    }
}

Measured memory_bytes: 1160
#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef vector<vector<int>> v2int;
typedef vector<ll> vll;
typedef vector<vector<ll>> v2ll;
typedef list<int> liint;
typedef pair<int, int> pint;
const int INF = int(2e9);
const ll LINF = ll(2e9) * ll(2e9);
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
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; }



int main() {
    int K, X;
    cin >> K >> X;
    for (int x = -1000000; x <= 1000000; x++) {
        if (x > X - K && x < X + K)
            cout << x << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	static Scanner scanner;

	public static void main(String[] args) {
	    scanner = new Scanner(System.in);

	    int N=gi();
	    int A=gi();
	    int B=gi();
	    String S=gs();
	    int t=0;
	    int k=0;
	    for (int i=0; i<S.length();i++) {
	    	char c=S.charAt(i);
	    	if(c=='a' && t<A+B) {
	    		t++;
	    		System.out.println("Yes");
	    	} else if(c=='b' && t<A+B && k<B){
	    		t++;
	    		k++;
	    		System.out.println("Yes");
	    	} else {
	    		System.out.println("No");
	    	}
	    }
	    

        //System.out.println(c);
	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 49928
N=int(input())
a=list(map(int, input().split()))
a.sort()

if N%3==1:
  if a[0]==a[N-1]:
    ans = 'Yes'
  else:
    ans = 'No'
elif N%3==2:
  if a[0]==a[N-1]:
    ans = 'Yes'
  else:
    ans = 'No'
else:
  if a[0]==a[N//3-1] and a[N//3]==a[N//3*2-1] and a[N//3*2]==a[N-1] and a[0]^a[N//3]==a[N//3*2]:
    ans = 'Yes'
  else:
    ans = 'No'
print(ans)

Measured memory_bytes: 60784
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		int n = stdIn.nextInt();
		boolean[][] judg = new boolean[n+1][n+1];
		for(int i=0;i<n+1;i++){
			Arrays.fill(judg[i],false);
		}
		ArrayList<ArrayList<Integer>> graph = new ArrayList<ArrayList<Integer>>();
		for(int i=0;i<2;i++){
			graph.add(new ArrayList<Integer>());
		}
		for(int i=0;i<n;i++){
			int u = stdIn.nextInt();
			int k = stdIn.nextInt();
			for(int j=0;j<k;j++){
				int v = stdIn.nextInt();
				judg[u][v] = true;
			}
		}
		
		int[] d = new int[n+1];
		Arrays.fill(d,-1);
		d[1] = 0;
		
		for(int i=0;i<n;i++){
			for(int k=1;k<=n;k++){
				if(d[k]==i){
					for(int j=1;j<=n;j++){
						if(judg[k][j] && d[j]==-1){
							d[j] = d[k] + 1;
						}
					}
				}
			}
		}
		
		for(int i=1;i<=n;i++){
			System.out.println(i+" "+d[i]);
		}
	}
}

Measured memory_bytes: 21104