akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, m, n) for(int i = m; i < (n); i++)
#define print(x) cout << (x) << endl;
#define printv(x) for(int i = 0; i < x.size(); i++){ cout << (x[i]) << " "; } cout << endl; 
#define printa(x,n) for(int i = 0; i < n; i++){ cout << (x[i]) << " ";} cout << endl;
#define printaa(x) for(int i = 0; i < (sizeof(x)/sizeof(x[0])); i++){ for(int j = 0; j < (sizeof(x[0])/sizeof(x[0][0])); j++){ cout << x[i][j] << " ";} cout << endl;}
#define INF (1e9)
typedef long long ll;
typedef struct{
    int x;
    int y;
} P;

using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,Y;
    cin >> N >> Y;
    rep(x,0,N+1){
        rep(y,0,N+1){
            if(x+y > N) continue;
            int z = N - x - y;
            if(x * 10000 + y * 5000 + z * 1000 == Y){
                cout << x << " " << y << " " << z << endl;
                return 0;
            }

        }
    }
    print("-1 -1 -1");
}


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

int main()
{
    double r;
    cin >> r;
    
    double s = r * r * 3.141592653589;
    double w = 2 * 3.141592653589 * r;
    
    printf("%.8lf %.8lf\n", s, w);
    
    return 0;
}


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int a,b,c,d;
int main(){
	bool win;
	cin>>b>>a>>d>>c;
	while(1){
		d-=a; if(d<=0){win=1;break;}
		b-=c; if(b<=0){win=0;break;}
	}
	if(win) puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 3620
#include "bits/stdc++.h"
using namespace std;
typedef long long LL;
int main() {
	string S, T;
	cin >> S >> T;
	for (int i = S.size() - T.size(); i >= 0; i--) {
		bool OK = 1;
		for (int j = 0; j < T.size(); j++) {
			if (S[i + j] != T[j] && S[i + j] != '?') {
				OK = 0;
				break;
			}
		}
		if (!OK) continue;
		for (int j = 0; j < T.size(); j++) S[i + j] = T[j];
		for (int i = 0; i < S.size(); i++) {
			if (S[i] == '?') S[i] = 'a';
		}
		cout << S << endl;
		return 0;
	}
	cout << "UNRESTORABLE" << endl;
}

Measured memory_bytes: 256
/*
ID: wangjun30
LANG: C++11
TASK:
*/
#include<iostream>
#include<algorithm>
#include<array>
#include<unordered_map>
#include<map>
#include<set>
#include<list>
#include<stack>
#include<unordered_set>
#include<vector>
#include<bitset>
#include<queue>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<climits>
//#include<fstream>
#define int long long
using namespace std;
//ifstream cin(".in");
//ofstream cout(".out");
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int l,r,d;
	cin>>l>>r>>d;
	int ans=(r/d)-(l/d);
	if(l%d==0)
		cout<<ans+1;
	else
		cout<<ans;
	return 0;
}

Measured memory_bytes: 3684
#include <bits/stdc++.h>
using namespace std;
    
int main() {
    int size = 3;
    char c[size];
    cin >> c;
    int cnt = 0;
    for (int i=0; i<size; i++){
        if(c[i] == '1'){
            cnt++;
        }
    }
    cout << cnt << endl;
}



Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define RT return
#define vv(a,b,c,d) vector<vector<a> >(b,vector<a>(c,d))
#define vvv(a,b,c,d,e) vector<vector<vector<a> > >(b,vv(a,c,d,e))
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

void dfs(int u, int p, int d, vector<vi> &H, vi &dist, vi &cost) {
    dist[u] = d + cost[u];
    each(v, H[u])if (v != p) {
        dfs(v, u, dist[u], H, dist, cost);
    }
}

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

    int N;
    cin >> N;
    vector<vi> G(N);
    rep(a, N - 1) {
        int x, y;
        cin >> x >> y;
        --x; --y;
        G[x].push_back(y);
        G[y].push_back(x);
    }

    string A;
    cin >> A;
    vi C(N);
    int nw = 0;
    rep(a, N) {
        char c = A[a];
        C[a] = c == 'W' ? 1 : 0;
        nw += C[a];
    }

    if (nw <= 1) {
        cout << nw << endl;
        return 0;
    }

    vi deg(N);
    queue<int> Q;
    rep(a, N) {
        deg[a] = sz(G[a]);
        if (deg[a]==1 && !C[a]) {
            Q.push(a);
        }
    }
    vector<bool> removed(N);
    while (sz(Q)) {
        int u = Q.front();
        removed[u] = true;
        Q.pop();
        each(v, G[u]) {
            if (--deg[v] == 1 && !C[v]) {
                Q.push(v);
            }
        }
    }

    fill(all(deg), 0);
    vector<vi> H(N);
    int V = 0;
    rep(u, N)if (!removed[u]) {
        V++;
        each(v, G[u])if (!removed[v]) {
            H[u].push_back(v);
            deg[u]++;
        }
    }

    // Euler Tourした場合のコスト
    int re = 2 * (V - 1), S = 0;
    vi cost(N);
    rep(a, N) if(!removed[a]){
        int x = C[a] ^ (deg[a] & 1);
        re += x;
        cost[a] = x;
        if(deg[a]==1)S = a;
    }

    // 完全にすべての頂点を訪れたらEuler Tourを打ち切る。
    // (あるパス上の頂点は(次数-1)回ずつ訪れる)
    vi dist(N);
    dfs(S, -1, 0, H, dist, cost);
    rep(a, N)if (!removed[a]) {
        if (dist[S] < dist[a] && deg[a] == 1)S = a;
    }
    dfs(S, -1, 0, H, dist, cost);
    int ma = 0;
    rep(a, N)if (!removed[a]) smax(ma, dist[a]);
    re -= 2*ma;
    cout << re << endl;
}

Measured memory_bytes: 20688
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace AtCoder_ABC089_A
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());

            Console.WriteLine(((int)(n / 3)).ToString());
        }
    }
}


Measured memory_bytes: 13140
A,B=map(int,input().split())
ans=0
while True:
    ans=ans^A
    #print(ans)
    if A%4==3:
        break
    A=A+1
#print("\n")
while True:
    ans=ans^B
    #print(ans)
    if B%4==0:
        break
    B=B-1
print(ans)

Measured memory_bytes: 61884
def com_div(x, y):
    dv = []
    for i in range(min(x, y), 0, -1):
        if x % i == 0 and y % i == 0:
            dv.append(i)
    return dv


a, b, k = list(map(int, input().split()))
print(com_div(a, b)[k - 1])


Measured memory_bytes: 8992
S = list(input())
T = list(input())

matches = []
for i in range(len(S) - len(T) + 1):
    index = i
    for j in range(len(T)):
        if S[index] == '?' or S[index] == T[j]:
            if j == len(T) -1:
                matches.append(i)
            index += 1
        else:
            break

if len(matches) == 0:
    print('UNRESTORABLE')
else:
    strings = []
    for i in matches:
        strings.append(''.join(S[:i] + T[:] + S[i+len(T):]).replace('?', 'a'))
    print(sorted(strings)[0])

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int a,now,ans;
char u;
int main()
{
    cin>>a;
    for(int s=0;s<a;s++)
    {
        cin>>u;
        if(u=='I')now++;
        else
        now--;
        ans=max(ans,now);
    }
    cout<<ans<<endl; 
    return 0;
}

Measured memory_bytes: 256
import std.stdio, std.array, std.string, std.conv, std.algorithm;
import std.typecons, std.range, std.random, std.math, std.container;
import std.numeric, std.bigint, core.bitop, core.stdc.stdio;

void main() {
    auto s = readln.split.map!(to!int);
    auto N = s[0];
    auto P = s[1];
    auto A = readln.split.map!(to!int).array;

    auto dp = new long[][](N+1, 2);
    dp[0][0] = 1;

    foreach (i; 0..N) {
        if (A[i] % 2 == 0) {
            dp[i+1][0] = dp[i][0] + dp[i][0];
            dp[i+1][1] = dp[i][1] + dp[i][1];
        }
        else {
            dp[i+1][0] = dp[i][0] + dp[i][1];
            dp[i+1][1] = dp[i][0] + dp[i][1];
        }
    }

    dp[N][P].writeln;
}


Measured memory_bytes: 256
s=gets.chomp
n=s.size
pat=['dream', 'dreamer', 'erase', 'eraser'].map{|s| s.reverse}

s.reverse!
i=0
while i<n
  tmp=''
  pat.each do |t|
    if s[i...n].start_with?(t)
      tmp=t
      break
    end
  end
  if tmp.size>0
    i+=tmp.size
  else
    puts 'NO'
    exit 0
  end
end

puts 'YES'

Measured memory_bytes: 1916
#include <iostream>
#include <vector>

using namespace std;

int main(int argc, char *argv)
{
	int q;
	cin >> q;
	vector<int> A;
	A.reserve(200000);

	for (int i = 0; i < q; ++i) {
		int query;
		int x;

		cin >> query;
		if (query != 2) cin >> x;


		switch (query) {
		case 0:
			// push back.
			A.push_back(x);
			break;

		case 1:
			//random access
			cout << A[x] << endl;
			break;

		case 2:
			// pop
			A.pop_back();
			break;
		}
	}
}


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

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

    string s; cin >> s;
    reverse(s.begin(), s.end());

    const string words[] = {"maerd", "remaerd", "esare", "resare",};
    int idx = 0;
    while (idx < s.size()) {
        bool flag = false;
        for (int i = 0; i < 4; ++i) {
            if (s.substr(idx, words[i].size()) == words[i]) {
                idx += words[i].size();
                flag = true;
                break;
            }
        }
        if (!flag) {
            cout << "NO" << endl;
            return 0;
        }
    }

    cout << "YES" << endl;
    return 0;
}

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

int main(){
	
	string s; cin>>s;
	int n=s.length();
	int ans=999;
	
	rep(i,n-2) ans=min(ans,abs(stoi(s.substr(i,3))-753));
	cout<<ans<<endl;
	
	return 0;
	
}



Measured memory_bytes: 256
from collections import deque
while True:
    s = [i for i in input()]
    if s[0] == "-":
        break
    d = deque(s)

    m = int(input())
    for i in range(m):
        n = int(input())
        for j in range(n):
            d.append(d.popleft())
    print("".join(d))


Measured memory_bytes: 6008
n,k,s = map(int,input().split())
ans = []
o,e = s//2, -(-s//2)
for i in range(n):
    if n == k:
        ans.append(s)
    elif s == 1:
        if i < k:
            ans.append(1)
        else:
            ans.append(2)
    else:
        if i <= k:
            if i % 2 == 0:
                ans.append(o)
            else:
                ans.append(e)
        else:
            if s == 10**9:
                ans.append(1)
            else:
                ans.append(s+1)
print(*ans)

Measured memory_bytes: 9584
#include <bits/stdc++.h>
#include <algorithm>
#include <queue>
using namespace std;
int main(){
	int N; 
	cin >> N; 
	double P[3000] = {}; 
	for(int i = 1; i <= N; i++){
		cin >> P[i]; 
	}
	double dp[3000][3000] = {}; // iまで，表はj回
	dp[0][0] = 1; 
	for(int i = 1; i <= N; i++){
		dp[i][0] = dp[i-1][0] * (1 - P[i]); 
		for(int j = 1; j <= i; j++){
			dp[i][j] = dp[i-1][j-1] * P[i] + dp[i-1][j] * (1 - P[i]); 
		}
	}
	double ans = 0; 
	for(int j = (N + 1)/2; j <= N; j++){
		ans += dp[N][j]; 
	}
	cout.precision(12); 
	cout << ans << endl; 
}

Measured memory_bytes: 70528
import math
from collections import deque
from collections import defaultdict

import bisect

#自作関数群
def readInt():
	return int(input())
def readInts():
	return list(map(int, input().split()))
def readChar():
	return input()
def readChars():
	return input().split()
def factorization(n):
	res = []
	if n%2==0:
		res.append(2)
	for i in range(3,math.floor(n//2)+1,2):
		if n%i==0:
			c = 0
			for j in res:
				if i%j==0:
					c=1
			if c==0:
				res.append(i)
	return res
def fact2(n):
	p = factorization(n)
	res = []
	for i in p:
		c=0
		z=n
		while 1:
			if z%i==0:
				c+=1
				z/=i
			else:
				break
		res.append([i,c])
	return res
def fact(n):#階乗
	ans = 1
	m=n
	for _i in range(n-1):
		ans*=m
		m-=1
	return ans
def comb(n,r):#コンビネーション
	if n<r:
		return 0
	l = min(r,n-r)
	m=n
	u=1
	for _i in range(l):
		u*=m
		m-=1
	return u//fact(l)
def combmod(n,r,mod):
	return (fact(n)/fact(n-r)*pow(fact(r),mod-2,mod))%mod
def printQueue(q):
	r=copyQueue(q)
	ans=[0]*r.qsize()
	for i in range(r.qsize()-1,-1,-1):
		ans[i] = r.get()
	print(ans)
class UnionFind():
	def __init__(self, n):
		self.n = n
		self.parents = [-1]*n

	def find(self, x): # root
		if self.parents[x]<0:
			return x
		else:
			self.parents[x] = self.find(self.parents[x])
			return self.parents[x]

	def union(self,x,y):
		x = self.find(x)
		y = self.find(y)

		if x==y:
			return

		if self.parents[x]>self.parents[y]:
			x,y = y,x

		self.parents[x]+=self.parents[y]
		self.parents[y]=x

	def size(self,x):
		return -1*self.parents[self.find(x)]

	def same(self,x,y):
		return self.find(x)==self.find(y)

	def members(self,x): # much time
		root = self.find(x)
		return [i for i in range(self.n) if self.find(i)==root]

	def roots(self):
		return [i for i,x in enumerate(self.parents) if x<0]

	def group_count(self):
		return len(self.roots())

	def all_group_members(self):
		return {r: self.members(r) for r in self.roots()} # 1~n
def bitArr(n):#ビット全探索
	x = 1
	zero = "0"*n
	ans = []
	ans.append([0]*n)
	for i in range(2**n-1):
		ans.append(list(map(lambda x:int(x),list((zero+bin(x)[2:])[-1*n:]))))
		x+=1
	return ans;
def arrsSum(a1,a2):
	for i in range(len(a1)):
		a1[i]+=a2[i]
	return a1
def maxValue(a,b,v):
	v2 = v
	for i in range(v2,-1,-1):
		for j in range(v2//a+1): #j:aの個数
			k = i-a*j
			if k%b==0:
				return i
	return -1
def copyQueue(q):
	nq = queue.Queue()
	n = q.qsize()
	for i in range(n):
		x = q.get()
		q.put(x)
		nq.put(x)
	return nq
def get_sieve_of_eratosthenes(n):
	#data = [2]
	data = [0,0,0]
	for i in range(3,n+1,2):
		data.append(i)
		data.append(0)
	for i in range(len(data)):
		interval = data[i]
		if interval!=0:
			for j in range(i+interval,n-1,interval):
				data[j] = 0
	#ans = [x for x in data if x!=0]
	ans = data[:]
	return ans

a,b = readInts()

if a<=0 and b>=0:
	print("Zero")
elif a<0 and (a-b)%2==0:
	print("Negative")
else:
	print("Positive")

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

int main()
{
    ll n,i;
    cin>>n;
    ll arr[n];
    map<ll,ll> mp;
    for(i=0;i<n;i++)
    {
        cin>>arr[i];
        mp[arr[i]]++;
    }
    ll sum=0;
    for(auto itr=mp.begin();itr!=mp.end();itr++)
    {
        ll temp=itr->second;
        sum+=(temp*(temp-1))/2;
    }
    for(i=0;i<n;i++)
    {
        ll a=mp[arr[i]];
        ll diff=((a*(a-1))/2)-(((a-1)*(a-2))/2);
        cout<<sum-diff<<endl;
    }
}

Measured memory_bytes: 12672
// Aizu Vol-10 1043: Selecting Teams Advanced to Regional
// 2017.8.18 bal4u@uu

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef struct { int id, u, a, p; } TEAM;
TEAM team[302];
int affi[1002], total;

int cmp(TEAM *a, TEAM *b)
{
	int d;
	if ((d = b->a - a->a) != 0) return d;
	if ((d = a->p - b->p) != 0) return d;
	return a->id - b->id;
}

int main()
{
	int n, i, u;

	while (scanf("%d", &n) && n) {
		for (i = 0; i < n; i++)
			scanf("%d%d%d%d", &(team[i].id), &(team[i].u), &(team[i].a), &(team[i].p));
		qsort(team, n, sizeof(TEAM), cmp);
		total = 0; memset(affi, 0, sizeof(affi));
		for (i = 0; i < n; i++) {
			u = team[i].u;
			if (total < 10 && affi[u] < 3) goto Fin;
			if (total < 20 && affi[u] < 2) goto Fin;
			if (total < 26 && affi[u] < 1) goto Fin;
			continue;
Fin:		printf("%d\n", team[i].id);
			total++, affi[u]++;
		}
	}
	return 0;
}

Measured memory_bytes: 652
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define sec second
#define opr iterator
typedef long long ll;
using namespace std;
string s;
int n;
int pre[100001];
void work(int start,int end)
{
	cout<<pre[end]-pre[start]<<endl;
}
int main()
{
	int q;
	cin>>n>>q;
	cin>>s;
	pre[0]=0;
	pre[1]=0;
//	pre[2]=(s[0]=='A'&&s[1]=='C');
	char fro=s[0];
	for(int i=1;i<n;i++)
	{
		pre[i+1]+=pre[i];
		if(fro=='A'&&s[i]=='C')
		{
			pre[i+1]++;
		}
		fro=s[i];
	}
//	for(int i=1;i<=n;i++)
//	{
//		cout<<pre[i]<<endl;
//	}
	for(int i=1;i<=q;i++)
	{
		int a,b;
		cin>>a>>b;
		work(a,b);
	}
	return 0;
}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
using namespace std;
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define RFOR(i, a, b) for(int i = (b) - 1; i >= (a); i--)
#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 ALL(i) (i).begin(),(i).end()
#define RALL(i) (i).begin(),(i).end(),greater<int>()

#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second

typedef long long ll;
#define TENNINE 1000000005
#define TENFIVE 100005
#define TENFIVE2 200005
// #define int long long
const int INF = 999999999;
const int MOD = 1e9 + 7;
const double EPS = 1e9 + 7;
const double PI = acos(-1);
const int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};

inline int in(){int x;std::cin>>x;return x;}

using lint = long long;
using pint = pair<int, int>;
using vi = vector<int>;
using vii = vector<vector<int> >;
using vl = vector<long long>;
using vp = vector<pint>;

template <typename T> void print(T x) { std::cout << x << '\n'; }
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {
  std::fill((T*)array, (T*)(array + N), val);
}
signed main(){
  double ans = 0;
  int N,K;
  cin>>N>>K;
  
  for(int i=1;i<=N;i++){
    double tmp = 1.0/N;
    int now = i;
    while(now<K){
      tmp*=0.5;
      now*=2; 
      // print(now);
      // print(tmp);
    }
    // print(tmp);
    ans+=tmp;
  }
  printf("%.12f\n",ans);
  return 0;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

s = input().strip()
if len(s) == 1:
    print(0)
    sys.exit(0)
if len(s) == 2 and s[0] == s[1]:
    print(0)
    sys.exit(0)

# [i][0]: index iが1文字分割
# [i][1]: index iが2文字分割
dp = [[0] * 2 for _ in range(len(s))]
# 3文字以上では1文字/2文字の仮想結果が使われる
# 1文字
dp[0][0] = dp[0][1] = 1
# 2文字
if s[0] == s[1]:
    # 実際には常に2文字分割になる
    dp[1][0] = dp[1][1] = 1
else:
    dp[1][0] = 2
    dp[1][1] = 1

# 3文字以上
for i in range(2, len(s)):

    # [i][0]: 末尾の分割を1文字にする場合

    # 末尾2文字が同じ場合
    # - 1つ前を2文字分割にしなくてはならない
    if s[i] == s[i-1]:
        dp[i][0] = dp[i-1][1] + 1
    # 末尾2文字が異なる場合
    # - 1つ前が1文字分割
    # - 1つ前が2文字分割
    else:
        dp[i][0] = max(dp[i-1][0] + 1, dp[i-1][1] + 1)


    # [i][1]: 末尾の分割を2文字にする場合
    # 末尾前の2文字が末尾の2文字と同じ場合
    # 末尾前を1文字分割にしなくてはならない
    if s[i-3:i-1] == s[i-1:i+1]:
        dp[i][1] = dp[i-2][0] + 1
    # 末尾前の2文字が末尾の2文字と異なる場合
    # - 末尾前が1文字分割
    # - 末尾前が2文字分割
    else:
        dp[i][1] = max(dp[i-2][0] + 1, dp[i-2][1] + 1)

print(max(dp[-1][0], dp[-1][1]))


Measured memory_bytes: 39228
#include <stdio.h>
#include <math.h>


  int main()
 {
     long long int N,K,i,j,l,m;

     scanf("%lld %lld",&N, &K);

     if(N<K && K<N/2)
     {
         printf("%lld\n",N);
     }
else if (N<K && K>N/2)
     {
         m=-(N-K);
         if(N>m)
         {
             printf("%lld\n",m);
         }
         else
         {
             printf("%lld\n",N);
         }
     }

    else if(N>=K && ((N%K)==0 || K==1))
     {
         printf("0\n");
     }
     else if(N>K && !(N%K)==0)
     {
        j = N%K;
        l= j-K;
        if(j<l)
         {
             printf("%lld\n",j);
         }
         else
         {
             printf("%lld\n",-l);
         }
     }


     }





Measured memory_bytes: 128
import math
import fractions
import bisect
import collections
import itertools
import heapq
import string
import sys
import copy
from decimal import *
from collections import deque
sys.setrecursionlimit(10**7)
MOD = 10**9+7
INF = float('inf') #無限大
def gcd(a,b):return fractions.gcd(a,b) #最大公約数
def lcm(a,b):return (a*b) // fractions.gcd(a,b) #最小公倍数
def iin(): return int(sys.stdin.readline()) #整数読み込み
def ifn(): return float(sys.stdin.readline()) #浮動小数点読み込み
def isn(): return sys.stdin.readline().split() #文字列読み込み
def imn(): return map(int, sys.stdin.readline().split()) #整数map取得
def imnn(): return map(lambda x:int(x)-1, sys.stdin.readline().split()) #整数-1map取得
def fmn(): return map(float, sys.stdin.readline().split()) #浮動小数点map取得
def iln(): return list(map(int, sys.stdin.readline().split())) #整数リスト取得
def iln_s(): return sorted(iln()) # 昇順の整数リスト取得
def iln_r(): return sorted(iln(), reverse=True) # 降順の整数リスト取得
def fln(): return list(map(float, sys.stdin.readline().split())) # 浮動小数点リスト取得
def join(l, s=''): return s.join(l) #リストを文字列に変換
def perm(l, n): return itertools.permutations(l, n) # 順列取得
def perm_count(n, r): return math.factorial(n) // math.factorial(n-r) # 順列の総数
def comb(l, n): return itertools.combinations(l, n) # 組み合わせ取得
def comb_count(n, r): return math.factorial(n) // (math.factorial(n-r) * math.factorial(r)) #組み合わせの総数
def two_distance(a, b, c, d): return ((c-a)**2 + (d-b)**2)**.5 # 2点間の距離
def m_add(a,b): return (a+b) % MOD
def print_list(l): print(*l, sep='\n')
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def No(): print('No')

def sieves_of_e(n):
    is_prime = [True] * (n+1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5)+1):
        if not is_prime[i]: continue
        for j in range(i * 2, n+1, i): is_prime[j] = False
    return is_prime

L = iin()
x = L/3
print(x**3)

Measured memory_bytes: 5804
#include <bits/stdc++.h>
#define INF 1e9
#define endl '\n'
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); --i)
#define FORE(i, a, b) for (int i = (a), e = (b); i < e; ++i)
#define RFORE(i, a, b) for (int i = (b)-1, e = (a); i >= e; --i)
#define ALL(x) (x).begin(), (x).end()
#define SORT(c) sort((c).begin(), (c).end())
#define SORTR(c) sort((c).begin(), (c).end(), greater<int>())
using namespace std;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int A, B, C, X;
    cin >> A >> B >> C >> X;
    int ans = 0;
    FOR(a, 0, A + 1) {
        FOR(b, 0, B + 1) {
            int c = (X - 500 * a - 100 * b) / 50;
            if ((0 <= c) & (c <= C)) { ++ans; }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3652
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#include <math.h>

int main(void){
    long long n,x,ans=0;
    scanf("%lld%lld",&n,&x);
    long long a[n];
    for (int i=0; i<n; i++){
        scanf("%lld",&a[i]);
    }
    for (int i=0; i<n-1; i++){
        if (a[i]+a[i+1]>x){
            ans+=(a[i+1]+a[i])-x;
            a[i+1]-=(a[i+1]+a[i])-x;
            if (a[i+1]<0){
                a[i+1]=0;
            }
        }
    }
    printf("%lld",ans);
	return 0 ;
}

Measured memory_bytes: 896
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
const int INF = 1000000000;
const ll MOD = 1000000007;
ll pow_mod(ll a,ll b,ll m){
	if(b == 0)return 1;
	else if(b % 2 == 0){
		ll t = pow_mod(a,b/2,m);
		return t * t % m;
	}
	return a  * pow_mod(a,b-1,m) % m;
}

const long long MAX = 1000100;
long long fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for(int i = 2;i < MAX;i++){
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

long long COM(int n, int k){
	if(n < k) return 0;
	if(n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}



int main(){
	COMinit();

	map<ll,ll> cnt;
	int n;
	cin >> n;
	vector<ll> a(n);
	for(int i = 0;i < n;i++)cin >> a[i];

	for(int i = 0;i < n;i++){
		ll now = a[i];
		map<ll,ll> now_cnt;
		for(int j = 2;j * j <= now;j++){
			while(now % j == 0){
				now /= j;
				now_cnt[j]++;
			}
		}
		if(now != 1)now_cnt[now]++;

		for(auto p:now_cnt){
			cnt[p.first] = max(cnt[p.first],p.second);
		}
	}
	ll fact = 1;
	for(auto p:cnt){
		fact *= pow_mod(p.first,p.second,MOD);
		fact %= MOD;
	}
	ll ans = 0;
	for(int i = 0;i < n;i++){
		ans += fact * inv[a[i]] % MOD;
		ans %= MOD;
	}

	cout << ans << endl;
}


Measured memory_bytes: 24448
#include "bits/stdc++.h"
using namespace std;

#define RESIDUE(u,v) (capacity[u][v] - flow[u][v])
#define RCOST(u,v) (cost[u][v] + h[u] - h[v])
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define LL long long


LL mini=10000000,maxi=-10000000;
int minind,maxind,init,term;

void upd(int m,int n){
  REP(i,n-m){
    
  }

}

LL a[50];
int x[100];
int y[100];

int main(){
  int n;
  cin>>n;
  REP(i,n)
    cin>>a[i];
  
  REP(i,n){
    if(mini>a[i]){
      mini=a[i];
      minind=i;
    }
    if(maxi<a[i]){
      maxi=a[i];
      maxind=i;
    }
  }

  int m=0;
  if(mini>=0 || maxi>=-mini){
    if(mini<0){
      REP(i,n){
	if(a[i]<0){
	  x[m]=maxind+1;
	  y[m]=i+1;
	  m++;
	}
      }
    }
    REP(i,n-1){
      x[m]=i+1;
      y[m]=i+2;
      m++;
    }
  }

  if(maxi<0 || maxi<-mini){
    if(maxi>0){
      REP(i,n){
	if(a[i]>0){
	  x[m]=minind+1;
	  y[m]=i+1;
	  m++;
	}
      }
    }
    REP(i,n-1){
      x[m]=n-i;
      y[m]=n-1-i;
      m++;
    }
  }

  cout<<m<<endl;
  REP(i,m)
    cout<<x[i]<<" "<<y[i]<<endl;
  return 0;
}


Measured memory_bytes: 256
def main():
    import sys
    from bisect import bisect_left, bisect_right
    def input(): return sys.stdin.readline().rstrip()

    n = int(input())
    a = list(map(int, input().split()))
    b = list(map(int, input().split()))
    c = list(map(int, input().split()))
    a.sort()
    b.sort()
    c.sort()
    ans = 0
    for j in range(n):
        i = bisect_left(a, b[j])
        k = bisect_right(c, b[j])
        ans += i*(n-k)

    print(ans)
        




                
if __name__ == '__main__':
    main()

Measured memory_bytes: 29524
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i,n) for(int i=0;i<(n);++i)
#define all(x) (x).begin(), (x).end()
#define PB(x) push_back(x)
#define MP(x,y) make_pair(x,y)
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
 
int main() {
    
    int h,n;
    cin>>h>>n;
    vector<int> a(n);
    rep(i,n)    cin>>a[i];

    int sum=0;
    rep(i,n)    sum+=a[i];

    if(h<=sum)    cout<<"Yes"<<endl;
    else    cout<<"No"<<endl;

 return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<cstring>
#include<vector>
#include<sstream>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<map>
#include<utility>
#include<climits>
#include<set>
using namespace std;
#define ll long long


int main(){ 
	ios_base::sync_with_stdio(false);
	    cin.tie(0);
	    cout.tie(0);
	    
	#ifndef ONLINE_JUDGE
	    freopen("input.txt","r",stdin);
	    freopen("output.txt","w",stdout);
	#endif

	double d,t,s;
	cin>>d>>t>>s;
	if(d/s <= t)
		cout<<"Yes";
	else
		cout<<"No";
    
}

Measured memory_bytes: 3736
#include <iostream>
#include <vector>
#include <cstdlib>

using namespace std;
 
int main(){
    int N,M;
 
    cin >> N >> M;

    vector<int> A,B,C,D;

    for(int i = 0; i < N; i++){
        int a,b;
        cin >> a >> b;
        A.push_back(a);
        B.push_back(b);
    }

    for(int i = 0; i < M; i++){
        int c,d;
        cin >> c >> d;
        C.push_back(c);
        D.push_back(d);
    }

    for(int i = 0; i < N; i++){
        int dis = 1000000000;
        int p = 0;
        for(int j = 0; j < M; j++){
            if(abs(C[j] - A[i]) + abs(D[j] - B[i]) < dis){
                dis = abs(C[j] - A[i]) + abs(D[j] - B[i]);
                p = j+1;
            }
        }
        cout << p << endl;
    }

    return 0;
}


Measured memory_bytes: 256
//Allah vorosha
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define db double
#define pb push_back
#define pi acos(-1.0)
#define mod 1000000007
ll ans[2001];
int main() {
    //std::ios_base::sync_with_stdio(false);
    //cin.tie(NULL);
    //setbuf(stdout, NULL); //for interactive problem
    ll s, i;
    scanf ("%lld", &s);
    ans[3] = 1;
    ans[4] = 1;
    ans[5] = 1;
    for (i = 6; i <= s; i++) {
        ans[i] = (ans[i - 1] % mod + ans[i - 3] % mod) % mod;
    }
    printf ("%lld\n", ans[s]);
    return 0;
}


Measured memory_bytes: 3824
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll mod=1000000007;
const int MAX_N = 1000;         // n の最大値
 
// nCk を取得
double nCk(int n, int k) {
double res=1.0;
for(int i=0; i<n; i++){
res*=0.5;}
for(int i=0; i<k; i++){
res*=(double)(n-i);
res/=(double)(k-i);
}
return res;}
 
int main() {
ll n;
cin>>n;
ll a[n]={};
ll f=0;
ll q=1;
ll w=0;
for(ll i=0; i<n; i++){
cin>>a[i];}
sort(a,a+n);
for(ll i=0; i<n; i++){
if(2*f>=a[i]){
q++;}
else{q=1;}
f+=a[i];}
cout<<q<<endl;}


Measured memory_bytes: 1024
#include<iostream>
#include<cstdio>
#include<cctype>
using namespace std;
int main(){
	char ch;
	int cnt[26]={};

	while(cin>>ch){
		ch=tolower(ch);
		if(isalpha(ch)){
			cnt[ch-'a']++;
		}
	}

	for(int i=0;i<26;i++){
		printf("%c : %d\n",i+'a',cnt[i]);
	}

	return 0;
}

Measured memory_bytes: 1124
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main()
{
  int N;
  cin >> N;
  string S;
  cin >> S;
  
  int L=0,R=0,ans=0;
  //下処理
  for(int i=0; i<N; i++){
    if(S[i]=='E') R++;
  }
  //0番目がリーダー
  if(S[0]=='E') R--;
  ans = R;
  
  //i番目がリーダー
  for(int i=1; i<N; i++){
    if(S[i]=='E') R--;
    if(S[i-1]=='W') L++;
    ans = min(L+R,ans);
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 900
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here
    int h,w;
    cin>>h>>w;
    map<int,int> P1,P2;
    char maze[h][w];
    for(int i=0;i<h;i++){
        string s;
        cin>>s;
        for(int j=0;j<w;j++){
            maze[i][j]=s[j];
            if(maze[i][j]=='#'){
                P1[i]=1;
                P2[j]=1;
            }
        }
    }
    for(int i=0;i<h;i++){
        int rec=0;
        for(int j=0;j<w;j++){
            if(P1[i]==0 || P2[j]==0){rec++;continue;}
            cout<<maze[i][j];
        }
        if(rec!=w)cout<<endl;
    }
}


Measured memory_bytes: 256
from itertools import product as pro

n = int(input())
s = str(input())

r = [i for i in range(n) if s[i] == 'R']
g = [i for i in range(n) if s[i] == 'G']
b = [i for i in range(n) if s[i] == 'B']
cnt = len(r) * len(g) * len(b)

max1=set(b)

for i, j in pro(r, g):
    if 2*j-i in max1:
        cnt -= 1
    if 2*i-j in max1:
        cnt -= 1
    if (i+j)/2 in max1:
        cnt -= 1

print(cnt)

Measured memory_bytes: 74228
import java.util.*;
public class Main {
    public static void main(String[] args) throws Exception {
        try (Scanner sc = new Scanner(System.in)) {
            while (sc.hasNext()) {
                String s = sc.nextLine();
                int t = 0;
                if(s.charAt(0)=='o') t++;
                if(s.charAt(1)=='o') t++;
                if(s.charAt(2)=='o') t++;
                System.out.println(700 + 100 * t);
            }
        }
    }
}

Measured memory_bytes: 22484
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <array>
#include <tuple>
#include <random>

using namespace std;
typedef long long int ll;

#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); i++)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep,)(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()

#define const INF 10000000000

ll a, b, c, d, n, x, y, z, w, h, ans = 0, cnt = 0, max = 0;
string s;

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

    ll list[3] = {1, 100, 10000};
    cin >> d >> n;
    if(n == 100){
        n++;
    }
    ans = list[d] * n;
    cout << ans << endl;
}


Measured memory_bytes: 256
import math
import numpy as np
import sys
input = sys.stdin.readline
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

l = S()[:-1]
rel = S()[-2::-1]

if l == rel:
    print("YES")
else:
	print("NO")

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////

ll N;
ll i, j, k;
vector<ll> dv;
ll ans = 0;
bool ck(ll a){
        ll b = N;
        while(b%a==0){
            b /= a;
        }
        if((b-1)%a==0){
            //printf("a%lld,", a);
            return true;
        }
        return false;
}
int main(){
    scanf("%lld", &N);
    if(N==2){
        printf("1\n");
        return 0;
    }
    if(N==3){
        printf("2\n");
        return 0;
    }
    for (j = 0; j * j < N;++j)
        ;
    ++ans;
    fornum(i, 2, j)
    {
        if(N%i==0){
            if(ck(i))
                ++ans;
            if(ck(N/i))
                ++ans;
        }
    }
    if(N%j==0){
        if(ck(j))
            ++ans;
    }
    for (j = 0; j * j < N-1;++j)
        ;
    fornum(i, 1, j)
    {
        if ((N - 1) % i==0)
        {
            //printf("b%lld,", i);
            ans += 2;
        }
    }
    if((N-1)%j==0){
        ++ans;
    }
    --ans;

    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 256
w,h=gets.split.map &:to_i
t=[1,1]
p $<.each_with_index.map{|s,i|[-s.to_i,i<w ? 0:1]}.sort.reduce(0){|a,(c,d)|
  t[d]+=1
  a-c*t[1-d]
}


Measured memory_bytes: 17628
#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>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    cout << (n+1)/2 << endl;
    return 0;
}

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

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

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


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

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

char str[Mx];
void solve(){
  l=strlen(str);
  L l1=((l-1)/2)-1 , l2=((l+3)/2)-1;
  flg=0;
  l--;

  for(L i=0;i<l;i++,l--,l1--,l2++){
    if(str[i]!=str[l]){
      flg=1;break;
    }
    if(str[i]!=str[l1]){
      flg=1;break;
    }
    if(str[l2]!=str[l]){
      flg=1;break;
    }
  }
  if(flg)printf("No\n");
  else printf("Yes\n");
}
int main()
{
    scanf("%s",&str);
    solve();
    return 0;
}
/// empty() lld I64d push_back() top() pop() insert() upper_bound() lower_bound() memset() max() min() scanf continue


Measured memory_bytes: 3776
#include<iostream>
#include<string>
using namespace std;
int main(){
  string str;
  getline(cin,str);
  int i;
  for(i=0 ; str[i] != '\0' ; i++){
    if(str[i]>='a'&&str[i]<='z') str[i]+='A'-'a';
    else if(str[i]>='A'&&str[i]<='Z') str[i]+='a'-'A';
  }
    cout << str << endl;
  return 0;
}


Measured memory_bytes: 3156
#include <bits/stdc++.h>
#include <atcoder/convolution>

using namespace std;
using namespace atcoder;
 
using ll = long long;

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

  vector<ll> a(n), b(m);
  for(ll& e: a) cin >> e;
  for(ll& e: b) cin >> e;

  for(ll& e: convolution(a, b)) cout << e << endl;

  return 0;
}


Measured memory_bytes: 27264
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = long long;
using std::cout;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

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

int main() {
	int n, k; scanf("%d%d", &n, &k);
	std::vector<int> x(n), y(n), X(n), Y(n);
	std::vector<char> c(n);
	for(int i = 0; i < n; i++) {
		cin >> x[i] >> y[i] >> c[i];

		X[i] = x[i] % (2 * k);
		Y[i] = y[i] % (2 * k);
	}

	auto getCount = [k] (std::vector<std::vector<int>>& A, int sx, int sy) {
		int tx = sx + k - 1, ty = sy + k - 1;
		sx = std::max(0, sx);
		sy = std::max(0, sy);
		tx = std::min(2 * k - 1, tx);
		ty = std::min(2 * k - 1, ty);

		return A[tx + 1][ty + 1] - A[tx + 1][sy] - A[sx][ty + 1] + A[sx][sy];
	};
	
	auto A = make_v<int>(2 * k + 1, 2 * k + 1);
	auto B = make_v<int>(2 * k + 1, 2 * k + 1);
	for(int i = 0; i < n; i++) {
		if(c[i] == 'W') A[X[i] + 1][Y[i] + 1]++;
		if(c[i] == 'B') B[X[i] + 1][Y[i] + 1]++;
	}
	for(int i = 1; i < 2 * k + 1; i++) for(int j = 1; j < 2 * k + 1; j++) {
		A[i][j] += A[i][j - 1] + A[i - 1][j] - A[i - 1][j - 1];
		B[i][j] += B[i][j - 1] + B[i - 1][j] - B[i - 1][j - 1];
	}

	int ans = 0;
	for(int loop = 0; loop < 2; loop++) {
		for(int i = 0; i < k; i++) {
			for(int j = 0; j < k; j++) {
				int tmp = getCount(A, i - k, j - k)
						+ getCount(A, i - k, j + k)
						+ getCount(A, i, j)
						+ getCount(A, i + k, j - k)
						+ getCount(A, i + k, j + k)
						+ getCount(B, i - k, j)
						+ getCount(B, i, j - k)
						+ getCount(B, i, j + k)
						+ getCount(B, i + k, j);
				
				ans = std::max(ans, tmp);
			}
		}
		A.swap(B);
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 33280
n,m = map(int, input().split())
import itertools
array = []

for i in range(n):
    s = list(map(int, input().split()))
    array.append(s)

res = 0
ans = 0
for a,b,c in itertools.product([1,-1],repeat=3):
    tmp = []
    for x,y,z in array:
        tmp.append(a*x+b*y+z*c)
    tmp.sort(reverse=True)
    ans = max(ans,sum(tmp[:m]))

print(ans)


Measured memory_bytes: 3384
#include <iostream>

int main(int argc, char* argv[])
{
  int a = 0;
  int b = 0;
  
  std::cin >> a >> b;
  
  if (a < b)
  {
    std::cout << "a < b" << std::endl;
  }
  else if (a > b)
  {
    std::cout << "a > b" << std::endl;
  }
  else
  {
    std::cout << "a == b" << std::endl;
  }
  return 0;
}  

Measured memory_bytes: 1156
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    vector<int> nums(n);
    for(auto &c:nums)cin>>c;
    int ans = 0;
    for(int i = 0;i<n;i++){
        for(int j = i+1;j<n;j++){
            if(nums[i]== nums[j])continue;
            for(int k = j+1;k<n;k++){ 
                if(nums[j]== nums[k] || nums[k]== nums[i])continue;
                vector<int> s;
                s.push_back(nums[i]);
                s.push_back(nums[j]);
                s.push_back(nums[k]);
                sort(s.begin(),s.end());
                if(s[0]+s[1]>s[2])ans++;
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3520
#include<iostream>
#include<sstream>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define mp make_pair
#define pb push_back
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();i++)
#define dbg(x) cerr<<__LINE__<<": "<<#x<<" = "<<(x)<<endl

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
const int inf = (int)1e9;
const double INF = 1e12, EPS = 1e-9;

int w, h, in[10][10], tmp[10][10];
inline int f(int y, int x, int d, int dy, int dx){
	if(d >= 4) x = 10 - x - 1, d -= 4;
	if(d == 1) swap(y, x), x = 10 - x - 1;
	if(d == 2) y = 10 - y - 1, x = 10 - x - 1;
	if(d == 3) swap(y, x), y = 10 - y - 1;
	y += dy; x += dx;
	if(y < 0 || x < 0 || y >= h || x >= w) return -1;
	return y * 10 + x;
}
inline int g(int y, int x, int d, int dy, int dx){
	y -= dy; x -= dx;
	if(d%4 == 3) swap(y, x), x = 10 - x - 1;
	if(d%4 == 2) y = 10 - y - 1, x = 10 - x - 1;
	if(d%4 == 1) swap(y, x), y = 10 - y - 1;
	if(d >= 4) x = 10 - x - 1, d -= 4;
	if(y < 0 || x < 0 || y >= h || x >= w) return -1;
	return y * 10 + x;
}
void nul(int y, int x){
	const int dy[] = {-1, 0, 1, 0}, dx[] = {0, -1, 0, 1};
	int prev = tmp[y][x];
	tmp[y][x] = -1;
	rep(d, 4){
		int ny = y + dy[d], nx = x + dx[d];
		if(ny < 0 || nx < 0 || ny >= h || nx >= w || tmp[ny][nx] != prev) continue;
		nul(ny, nx);
	}
}
bool rec(int y, int x, int dy, int dx, int d){
	if(x == w) return rec(y + 1, 0, dy, dx, d);
	if(y == h){
		bool ok[3] = {};
		rep(i, h) rep(j, w) if(tmp[i][j] > 0){
			if(!tmp[i][j] || ok[tmp[i][j]]) return 0;
			ok[tmp[i][j]] = 1;
			nul(i, j);
		}
		return 1;
	}
	if(!in[y][x] || tmp[y][x]) return rec(y, x + 1, dy, dx, d);
	
	int t = f(y, x, d, dy, dx);
	if(t != y * 10 + x && t >= 0 && tmp[t / 10][t % 10] == 0 && in[t / 10][t % 10]){
		tmp[y][x] = 1;
		tmp[t / 10][t % 10] = 2;
		if(rec(y, x + 1, dy, dx, d)) return 1;
		tmp[y][x] = tmp[t / 10][t % 10] = 0;
	}
	t = g(y, x, d, dy, dx);
	if(t == y * 10 + x || t < 0 || tmp[t / 10][t % 10] != 0 || !in[t / 10][t % 10]) return 0;
	tmp[y][x] = 2;
	tmp[t / 10][t % 10] = 1;
	return rec(y, x + 1, dy, dx, d);
}

int main(){
	while(cin >> w >> h, w){
		rep(i, h) rep(j, w) cin >> in[i][j];
		rep(y, 30) rep(x, 30) rep(d, 8){
			memset(tmp, 0, sizeof(tmp));
			if(rec(0, 0, y - 15, x - 15, d)){
				cout << "YES" << endl;
				goto END;
			}
		}
		cout << "NO" << endl;
		END:;
	}
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
 
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast,unroll-loops,no-stack-protector") 
  
typedef long long ll;
using namespace std;
const ll MOD = 1e9 + 7;

int n, q[(int)1e5 + 5];

int main()
{
    cin >> n;
    
    for(int i = 1; i <= n; ++ i)
    {
        int u; 
        
        cin >> u;
        
        q[u] = i;
    }
    
    ll res = 0;
    
    multiset < int > w;
    
    w.insert(0);
    w.insert(0);
    w.insert(n + 1);
    w.insert(n + 1);
    
    for(int i = n; i >= 1; --i)
    {
        ll a = i;
        
        w.insert(q[a]);
        
        auto z = w.find(q[a]), x = prev(z), c = prev(x), v = next(z), b = next(v);
        
        int nx = *x, nc = *c, nv = *v, nb = * b;
        
        
        ll ans = (nv - q[i]) * 1LL * (nx - nc) + 1LL * (nb - nv) * (q[i] - nx);
        
        res += ans * a;
    }
    
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 5376
use std::io::prelude::*;

fn input<T: std::str::FromStr>() -> T {
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

fn main() {
    let n: usize = input();
    let v: Vec<i32> = (0..n).map(|_| input()).collect();

    let mut v0 = vec![];
    let mut v1 = vec![];
    for i in 0..n {
        if i % 2 == 0 {
            v0.push(v[i]);
        } else {
            v1.push(v[i]);
        }
    }
    v0.sort();
    v1.sort();

    let mut a0 = vec![];
    let mut i = 0;
    while i < v0.len() {
        let v = v0[i];
        let mut cnt = 0;
        while i < v0.len() && v0[i] == v {
            cnt += 1;
            i += 1;
        }
        a0.push((v, cnt));
    }
    let mut a1 = vec![];
    let mut i = 0;
    while i < v1.len() {
        let v = v1[i];
        let mut cnt = 0;
        while i < v1.len() && v1[i] == v {
            cnt += 1;
            i += 1;
        }
        a1.push((v, cnt));
    }

    a0.sort_by_key(|&(_, c)| -(c as i32));
    a1.sort_by_key(|&(_, c)| -(c as i32));

    if a0[0].0 != a1[0].0 {
        println!("{}", n - a0[0].1 - a1[0].1);
    } else {
        if a0.len() == 1 && a1.len() == 1 {
            println!("{}", n / 2);
        } else if a0.len() == 1 {
            println!("{}", n - a0[0].1 - a1[1].1);
        } else if a1.len() == 1 {
            println!("{}", n - a0[1].1 - a1[0].1);
        } else {
            let mn = std::cmp::min(n - a0[0].1 - a1[1].1, n - a0[1].1 - a1[0].1);
            println!("{}", mn);
        }
    }
}


Measured memory_bytes: 8444
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <bitset>
#include <string>
#include <numeric>
#include <algorithm>
#include <functional>
#include <iterator>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <complex>
#include <ctime>
#define ll long long
#define inf 0x3f3f3f3f
#define N 1000010
//#define int long long
//ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
int a[N],exist[N];

signed main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
    {
        scanf("%d",a+i);
        exist[a[i]]++;
    }
    int gc=a[1];
    for(int i=2;i<=n;i++)
        gc=__gcd(gc,a[i]);
    if(gc!=1)
    {
        printf("not coprime\n");
        return 0;
    }
    bool pairwise=true;
    for(int i=2;i<N;i++)
    {
        int cnt=0;
        for(int j=i;j<N;j+=i)
        {
            cnt+=exist[j];
        }
        if(cnt>1)
            pairwise=false;
    }
    if(pairwise)
        printf("pairwise coprime\n");
    else
        printf("setwise coprime");
	return 0;
}


Measured memory_bytes: 11520
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#define int long long
using namespace std;

void chmax(int &a, int b) { a = max(a, b); }

int INF = 1e+15;
int n, q;
int w[100], v[100];
int dp[300001];

signed main() {
	int i, j;
	
	cin >> n >> q;
	for (i = 0; i < n; i++) cin >> w[i] >> v[i];
	for (i = 0; i <= q; i++) dp[i] = -INF;
	dp[0] = 0;
	
	for (i = 0; i < n; i++) {
		for (j = q; j >= 0; j--) {
			chmax(dp[j + w[i]], dp[j] + v[i]);
		}
	}
	
	int ans = 0;
	for (i = 0; i <= q; i++) chmax(ans, dp[i]);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<string.h>
#include<stdbool.h>

#define MOD 998244353

#define MIN(a,b) ((a)<(b)?(a):(b));
#define MAX(a,b) ((a)>(b)?(a):(b));

typedef long long int64;

int main(void){
    int A,B;
    scanf("%d %d",&A,&B);
    if(A==B) printf("%d",A*2);
    else if(A>B) printf("%d",A*2-1);
    else printf("%d",B*2-1);
    
    
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define INF 2147483647

int main() {
    int n, m, x;
    cin >> n >> m >> x;
    vector<vector<int> > text(n, vector<int>(m+1));
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < m+1; j++) {
            cin >> text.at(i).at(j);
        }
    }
    vector<vector<int> > dp(1 << n, vector<int>(m+1));
    int cost = INF;
    for (int i = 0; i < 1 << n; i++) {
        for (int j = 0; j < n; j++) {
            if (i >> j & 1) {
                for (int k = 0; k < m+1; k++) {
                    dp.at(i).at(k) += text.at(j).at(k);
                }
            }
        }
        bool skill = true;
        for (int l = 1; l <= m; l++) {
            if (dp.at(i).at(l) < x) {
                skill = false;
            }
        }
        if (skill) {
            cost = min(cost, dp.at(i).at(0));
        }
    }
    if (cost == INF) {
        cout << -1 << endl;
    } else {
        cout << cost << endl;
    }
}

Measured memory_bytes: 3988