akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include <limits.h>
#include <math.h>
#include <time.h>
#include <queue>
#include <stdarg.h>
#include <map>
#include <vector>
#include <algorithm>
#include <stack>
#include <iostream>
#include <numeric>
#include <set>

#define ll long long

using namespace std;

ll mod = 1e9 + 7;

void
solve() {
  ll n;
  cin>>n;

  ll ans = 0;
  for (ll i=1; i<=n; i++) ans += i * (n + 1 - i);

  ll a, b;
  for (ll i=0; i<n-1; i++) {
    cin>>a>>b;
    ans -= min(a, b) * (n + 1 - max(a, b));
  }
  cout<<ans<<endl;
}

int 
main() {
  cin.tie(0);
  cout.tie(0);
  ios_base::sync_with_stdio(0);

  int t = 1;
  //cin>>t;

  while (t > 0) {
    t--;
    solve();
  }

  return 0;
}



Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, A, K;
  cin >> N >> A;
  K = N % 500;
  
  if (K <= A) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
import * as fs from "fs";

// inputで受け取り配列化する
const input = fs
  .readFileSync("/dev/stdin", "utf8")
  .split("\n")[1]
  .split(" ")
  .map(Number);

let cnt = 0;
for (let i = 0; i < input.length - 2; i++) {
  for (let j = i + 1; j < input.length - 1; j++) {
    if (input[i] === input[j]) continue;
    for (let k = j + 1; k < input.length; k++) {
      if (input[k] === input[i] || input[k] === input[j]) continue;
      const sub = Math.abs(input[i] - input[j]);
      const sum = input[i] + input[j];
      if (sub < input[k] && input[k] < sum) {
        cnt++;
      }
    }
  }
}

console.log(cnt);


Measured memory_bytes: 32616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    int n;
    cin>>n;
    ll arr[n];
    for(int i=0;i<n;i++) {
        cin>>arr[i];
    }
    ll total=0;
    for(int i=1;i<n;i++) {
        if(arr[i-1]>arr[i]) {
            total+=(arr[i-1]-arr[i]);
            // cout<<total<<" ";
            arr[i]=arr[i-1];
        }
    }
    cout<<total;
}


Measured memory_bytes: 5060
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
signed main(){
  string s;
  ll cnt=0;
  cin >> s;
  for(int i=1;i<s.size();i++){
    if(s[i]!=s[i-1]) cnt++;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int ans = 114514;
  for(int i = 1; i <= n/2+1; i++){
    int a = i;
    int b = n-i;
    int cnt = 0;
    while(a != 0){
      cnt += a%10;
      a /= 10;
    }
    while(b != 0){
      cnt += b%10;
      b /= 10;
    }
    ans = min(cnt, ans);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define Max 100000
using namespace std;
bool prime[Max+1];
vector<int>Q;
void IsPrime() {
	prime[0]=prime[1]=0;
	prime[2]=1;
	for(int i=3; i<Max; i++)
		prime[i]=i%2==0?0:1;
	int t=(int)sqrt(Max*1.0);
	for(int i=3; i<=t; i++)
		if(prime[i])
			for(int j=i*i; j<Max; j+=2*i)
				prime[j]=0;
}
int main() {
	int n,l,r,ct,flag;
	IsPrime();
	scanf("%d",&n);
	for(int j=0; j<=Max; j++) {
		if(prime[j]&&prime[(j+1)/2])Q.push_back(j);
	}
	while(n--) {
		flag=ct=0;
		scanf("%d%d",&l,&r);
		for(int i=0; i<Q.size(); i++) {
			if(Q[i]>r)break;
			if(Q[i]>=l)flag=1;
			if(flag) {
				ct++;
			}
		}
		printf("%d\n",ct);
	}
	return 0;
}

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

int main(){
	long long int n,x;
	cin>>n>>x;
	long long int ans=n;
	long long int y=n-x;
	while(x!=0&&y!=0){
		if(x>y)
			swap(x,y);
		ans+=2*(y/x*x);
		y%=x;
	}
	cout<<ans-x-y<<endl;
}


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

struct Node{
	Node(){
		parent = -1;
		depth = 0;
		left_child = -1;
		right_sibling = -1;
	}
	int parent;
	int depth;
	int left_child;
	int right_sibling;
};

void calc_depth(Node Tree[], int root, int depth)
{
	Tree[root].depth = depth;
	
	if (Tree[root].right_sibling != -1)
	{
		calc_depth(Tree, Tree[root].right_sibling, depth);
	}
	
	if (Tree[root].left_child != -1)
	{
		calc_depth(Tree, Tree[root].left_child, depth+1);
	}
	
}

void Print_Tree(Node Tree[], int n)
{
	for (int i = 0;i < n;i++)
	{
		printf("node %d: parent = %d, depth = %d, ", i, Tree[i].parent, Tree[i].depth);
		
		if (Tree[i].parent == -1)
		{
			printf("root, ");
		}
		else if (Tree[i].left_child == -1)
		{
			printf("leaf, ");
		}
		else
		{
			printf("internal node, ");
		}
		
		int tmp = i;
		printf ("[");
		if (Tree[i].left_child != -1)
		{
			tmp = Tree[i].left_child;
			printf("%d", tmp);
			while(Tree[tmp].right_sibling != -1)
			{
				tmp = Tree[tmp].right_sibling;
				printf(", ");
				printf("%d", tmp);
			}
		}
		printf ("]\n");
	}
}

int main ()
{
	int n;
	cin >> n;
	Node *Rooted_Tree = new Node [n];
	
	int root;
	for (int i = 0;i < n;i++)
	{
		int id, k, c, L_Child;
		cin >> id >> k;
		for (int j = 0;j < k;j++)
		{
			cin >> c;
			if (j)
			{
				Rooted_Tree[L_Child].right_sibling = c;
			}
			else
			{
				Rooted_Tree[id].left_child = c;
			}
			
			L_Child = c;
			Rooted_Tree[c].parent = id;
		}
	}

	for (int i = 0;i < n;i++)
	{
		if (Rooted_Tree[i].parent == -1)
		{
			root = i;
			break;
		}
	}
	
	calc_depth(Rooted_Tree, root, 0);
	
	Print_Tree(Rooted_Tree, n);
	
	return 0;
}


Measured memory_bytes: 7812
#include<stdio.h>
int main()
{
    int H,W,i=1,j=1;
    while (1)
    {
        scanf("%d%d",&H,&W);
        if (H==0 && W==0)
        break;
        for (i=1;i<=H;i++)
        {
            for (j=1;j<=W;j++) {
                printf("#");
            }
            printf("\n");
        }
        printf("\n");

    }
    return 0;
}


Measured memory_bytes: 2052
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

#define fast ios_base::sync_with_stdio(0); cin.tie(); cout.tie();

void solve() {

}

int main() {
	fast;

	int n;
	cin >> n;
	
	int ac = 0, wa = 0, tle = 0, re = 0;
	for (int i = 0; i < n; i++) {
		string s;
		cin >> s;

		if (s == "AC")
			ac++;
		else if (s == "WA")
			wa++;
		else if (s == "TLE")
			tle++;
		else
			re++;
	}

	cout << "AC x " << ac << endl;
	cout << "WA x " << wa << endl;
	cout << "TLE x " << tle << endl;
	cout << "RE x " << re << endl;

	return 0;
}

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

using namespace std;

#define pii pair<int, int>
#define ft first
#define sd  second

const int N = 1e5+5;

vector<pii> vec[N];
int col[N], ans = 0;

void dfs(int u, int p, int val){
    int k = 1;
    ans = max(ans, val);
    for(auto x: vec[u]){
        if(x.ft != p){
            if(val == k) k++;
            col[x.sd] = k;
            dfs(x.ft, u, k);
            k++;
        }
    }
}
int main(){
    int n;
    cin >> n;
    for(int i = 1; i < n; i++){
        int u, v;
        cin >> u >> v;
        vec[u].push_back({v, i});
        vec[v].push_back({u, i});
    }
    dfs(1, 0, 0);
    cout << ans << endl;
    for(int i = 1;  i< n; i++)
        cout << col[i] << " ";
}


Measured memory_bytes: 12584
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define MOD3 1000000000
#define MOD2 998244353
float PHI = 1.6180339;
const float  PI_F=3.14159265358979f;
#define MAX 1000 m
#define endl "\n"    
#define manhunt 32 
#define all(v) (v).begin(),(v).end()
#define sz(v) ((int)(v).size())
#define pi 3.1415926535897932384626433
//typedef long long float;
#define int long long
//#define double long long
typedef pair<int, int> pii;
//#define float unsigned long long
#define FAST ios_base::sync_with_stdio(false);cin.tie();cout.tie();
#define CHAR_SIZE 26 

int modpow(int x, int n, int m) { if (n == 0) return 1%m; long long u = modpow(x,n/2,m); u = (u*u)%m; if (n%2 == 1) u = (u*x)%m; return u; } 


int add(int x, int y) 
{
	x += y;
	if (x >= MOD) return x - MOD;
	return x;
}
int sub(int x, int y) 
{
	x -= y;
	if (x < 0) return x + MOD;
	return x;
}
int inv(int a, int m = MOD2)
{
	return modpow(a, m - 2, m);
}
int mul(int a, int b) 
{
	return (long long) a * b % MOD2;
}


int nCrModp(int n, int r, int p) 
{ 
    int C[r+1]; 
    memset(C, 0, sizeof(C)); 
  
    C[0] = 1; 
    for (int i = 1; i <= n; i++) 
    { 
        for (int j = min(i, r); j > 0; j--) 
            C[j] = (C[j] + C[j-1])%p; 
    } 
    return C[r]; 
} 

int32_t main()
{
    /* freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout); */
    FAST
    cout << fixed << setprecision(12);
 
    
    string s,t;
    cin>>s>>t;
    if(s.length()+1==t.length())
    {
        int flag=1;
        for(int i=0;i<s.length();i++)
        {
            if(s[i]!=t[i])
            {
                flag=0;
                break;
            }
        }
        if(flag==0)
        cout<<"No"<<endl;
        else
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    
    
    
    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <queue>

#define rep(i,n) for(int i=0;i<n;i++)
#define dup(x,y) (((x)+(y)-1)/(y)) // dup * y >= x なる最小のdup.
using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;
//	std::cout<<std::fixed<<std::setprecision(10);

int main() {
	int A, B, C;
	cin >>  A >> B >> C;

	int d = A%B;
	int cand = d;
	
	string ans = "NO";
	
	while(true) {
		if(cand==C) {
			ans = "YES";
			break;
		}
		cand = (cand+d)%B;
		if(cand == d) break; // 一周しても不可だった
	}
	
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#a,b,c = [int(i) for i in input().split()]

import sys
input = sys.stdin.readline

MOD = 10**9+7

n,x = [int(i) for i in input().split()]
s = [int(i) for i in input().split()]
s.sort(reverse=True)

ans = [0]*(x+1)
ans[x] = 1

#print(s)
for i, ss in enumerate(s):
    bairitu = n-i-1
#    print(bairitu)
    for j,xx in enumerate(ans):
#        print(j,xx)
        ans[j] = (xx*bairitu)%MOD
        ans[j%ss] = (ans[j%ss]+xx)%MOD

#    print(ans)

res=0
for j,xx in enumerate(ans):
    res += j*xx 
    res = res%MOD

print(res)



        

Measured memory_bytes: 43184
#include<iostream>
#include<cstdio>
#include<cstring>
#include<stack>
#include<vector>
#include<algorithm>
#include<cstdlib>
using namespace std;
#define N 1010
inline int read(){
    int x=0,f=1;
    char c=getchar();
    while(c<'0'||c>'9'){
        if(c=='-')f=-1;
        c=getchar();
    }
    while(c>='0'&&c<='9'){
        x=(x<<3)+(x<<1)+c-'0';
        c=getchar();
    }
    return x*f;
}
int n,m,vis[N],ok;
int ans[N],an,ins[N],G[N][N];
vector<int> st;
int head[N],cnt=0;
struct Edge{
	int to,nxt;
}edge[N<<1];
void add(int a,int b){
	cnt++;
	edge[cnt].to=b;
	edge[cnt].nxt=head[a];
	head[a]=cnt;
}
void dfs(int u){
	if(ok)return;
	//yet[u]=1;
	for(int i=st.size()-1;!ok&&i>=0;i--){
		int v=st[i];
		if(G[u][v]){
			cout<<st.size()-i<<endl;
			for(int j=i;j<st.size();j++){
				cout<<st[j]<<endl;
			}
			exit(0);
		}
	}
	int g=0,go[1001]={};
	for(int i=head[u];i;i=edge[i].nxt){
		int v=edge[i].to;
		if(!vis[v]){
			go[++g]=v;
		}
	}
	for(int i=head[u];i;i=edge[i].nxt){
		int v=edge[i].to;
		vis[v]=1;
	}
	for(int i=1;i<=g;i++){
		st.push_back(go[i]);
		dfs(go[i]);
		st.pop_back();
	} 
	for(int i=head[u];i;i=edge[i].nxt){
		int v=edge[i].to;
		vis[v]=0;
	}
}
int main(){
	n=read(),m=read();
	for(int i=1;i<=m;i++){
		int u=read(),v=read();
		add(u,v);
		G[u][v]=1;
	}
	for(int i=1;i<=n;i++){
		memset(vis,0,sizeof(vis));
		memset(ins,0,sizeof(ins));
		dfs(i);
	}
	if(!ok){
		cout<<-1<<endl;
		return 0;
	}
	return 0;
}
/*
8 12
1 2
3 4
4 5
5 6
2 7
6 7
7 8
8 1
1 5
2 8
1 7
2 3
*/
/*
11 13
1 2
2 3
3 4
4 5
5 6
6 7
7 8
1 4
3 8
9 10
11 9
10 11
9 1
*/
/*
3 2
1 2
2 1
*/

Measured memory_bytes: 7552
#include<iostream>
#include<vector>
#include<set>
#include<queue>
using namespace std;

bool startsWith(string str, int off, string pre){
    int s = str.length(), p = pre.length();
    if(off+p > s)   return false;

    int j;
    for(j = 0; j < p; j++){ 
        if(str[off+j] != pre[j])  break;
    }

    return j == p;
}

int main(){
    int n;
    while(cin >> n, n){
        string a[n], b[n];
        for(int i = 0; i < n; i++){
            cin >> a[i] >> b[i];
        }
        string s, t;
        cin >> s >> t;
        set<string> made;
        queue<pair<string,int>> q;
        q.push({s,0});
        int ans = -1;
        while(!q.empty()){
            pair<string,int> p = q.front(); q.pop();
            string x = p.first;
            if(x == t){
                ans = p.second;
                break;
            }
            for(int i = 0; i < n; i++){
                string tmp = "";
                for(int j = 0; j < x.length(); j++){
                    if(startsWith(x, j, a[i]))  tmp += b[i], j += a[i].length()-1;
                    else                        tmp += x[j];
                }
                if(tmp.length() > t.length() || made.count(tmp))    continue;
                made.insert(tmp);
                q.push({tmp, p.second+1});
            }
        }
        cout << ans << endl;
    }
    return 0;
}


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define PI 3.14159265358979
#define MOD 1000000007 // = 10^9 + 7

using namespace std;
using ll = long long;

void solve()
{
	ll h;
	cin >> h;

	int log2 = 0;
	while(h > 0)
	{
		h /= 2;
		log2++;
	}
	ll ans = pow(2, log2) - 1;
	cout << ans;
}

int main()
{
	fastio;
	solve();

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;


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

	long long n, m, i, j, k, x, ans, MOD = 1000000007;
	cin >> n >> m;
	vector<bool> broken(n + 1, false);
	for (i = 0; i < m; i++) {
		cin >> x;
		broken[x] = true;
	}

	vector<long long> dp(n + 1, 0);
	dp[0] = 1;
	for (i = 1; i <= n; i++) {
		if (broken[i]) continue;
		dp[i] = dp[i - 1];
		if (i - 2 >= 0) dp[i] += dp[i - 2];
		dp[i] %= MOD;
	}


	cout << dp[n] << "\n";
	return 0;
}


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

int main() {
  char c;
  cin >> c;
  if((c == 'a') || (c == 'i') || (c == 'u') || (c == 'e') || (c == 'o')) {
    cout << "vowel" << endl;
  } else {
    cout << "consonant" << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
const int maxn = 1007, maxm = 2007;
const int inf = 1e9 + 7;
int cnt = 1;
int head[maxn], vis[maxn], dfn[maxn], vis2[maxn];
//head[x]:点x连接的最后一条边号
//vis[x]:标记每次dfs访问过的点，以免重复搜索耗时
//dfn[x]:x的时间戳
//vis[x]2:dfs中标记访问过的次数，找环
int b[maxn];
struct edge
{
	int u, v, next;
}e[maxm];
void addedge(int u, int v)//前向星
{
	e[cnt].u = u;
	e[cnt].v = v;
	e[cnt].next = head[u];
	head[u] = cnt;
	cnt++;
}
vector<int> v;
int ans = inf;
void dfs(int x, int num)
{
	vis[x] = 1;//标记x访问过
	dfn[x] = num;
	for (int i = head[x]; i ; i = e[i].next)//遍历x点连接的所有边
	{
		int y = e[i].v;
		if (vis2[y] == 1)//y第二次被访问，说明形成环
		{
			if (dfn[x] - dfn[y] + 1 < ans)//ans记录最小环的大小
			{
				ans = dfn[x] - dfn[y] + 1;
				int sz = v.size();
				for (int i = 1; i <= ans; i++)
					b[i] = v[sz - i];//b[i]存最小环的点
			}
		}
		if (vis[y] == 0)//y没有访问过
		{
			vis2[y] = 1;
			v.push_back(y);
			dfs(y, num + 1);
		}
	}
	v.pop_back();
	vis2[x] = 0;
}
int main()
{
	int n, m;
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= m; i++)
	{
		int x, y;
		scanf("%d%d", &x, &y);
		addedge(x, y);
	}
	for (int i = 1; i <= n; i++)
	{
		if (vis[i] == 0)
		{
			v.clear();
			v.push_back(i);
			vis2[i] = 1;
			dfs(i, 1);
		}
	}
	if (ans == inf)
		printf("-1\n");
	else
	{
		printf("%d\n", ans);
		for (int i = ans; i >= 1; i--)
			printf("%d\n", b[i]);
	}
	return 0;
}

Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] ab = br.readLine().split(" ");
        int a = Integer.parseInt(ab[0]);
        int b = Integer.parseInt(ab[1]);
        System.out.println(problem143a(a, b));
    }

    private static int problem143a(int a, int b) {
        return Math.max((a - b * 2), 0);
    }
}

Measured memory_bytes: 21076
from itertools import permutations
n = int(input())
p = tuple(map(int, input().split()))
q = tuple(map(int, input().split()))

n_perm = [i for i in range(1, n + 1)]
n_perm = permutations(n_perm)
cnt = 0
for x in n_perm:
    if x == p: a = cnt
    if x == q: b = cnt
    cnt += 1
print(abs(a - b))

Measured memory_bytes: 3064
n = gets.to_i
x = gets.chomp.split.map(&:to_i)
y = gets.chomp.split.map(&:to_i)

z = []
x.zip(y){|i, j| z << (i - j).abs}

d1 = 0
d2 = 0
d3 = 0
z.each{|ele|
    d1 += (ele ** 1)
    d2 += (ele ** 2)
    d3 += (ele ** 3)
}
d1 = d1 ** (1/1.0)
d2 = d2 ** (1/2.0)
d3 = d3 ** (1/3.0)

printf("%.6f\n", d1)
printf("%.6f\n", d2)
printf("%.6f\n", d3)
printf("%.6f\n", z.max)

Measured memory_bytes: 8872
A1, A2, A3 = input().split()
A1 = int(A1)
A2 = int(A2)
A3 = int(A3)
if(A1>=1 and A2>=1 and A3>=1) and (A1<=13 and A2<=13 and A3<=13):
  if(A1+A2+A3>=22):
    print('bust')
  else:
    print('win')
else:
  print('Input too big')

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

using namespace std;

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define RREP(i,s,n) for(lli i=s;i>=n;i--)
#define MOD 1000000007
#define NUM 2520
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define INF (1LL<<50)

signed main(){

	lli n;
	cin>>n;

	cout<<(n+1)*n/2<<endl;

	return 0;
}

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

int main() {
    char b;
    cin >> b;
    char res;
    switch(b) {
        case 'A':
            res = 'T';
            break;
        
        case 'C':
            res = 'G';
            break;
        
        case 'G':
            res = 'C';
            break;
        
        case 'T':
            res = 'A';
            break;
    } 

    cout << res << endl;
    return 0;
}

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

int main() {
	int n, d, x, ans = 0;
	cin >> n >> d >> x;
	int a[100];
	for (int i = 0;i < n;i++)cin >> a[i];
	for (int i = 0;i < n;i++) {
		for (int j = 0;j*a[i] < d;j++) {
			ans++;
		}
	}
	cout << ans + x << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <queue>
#include <string>
#include <limits>
#include <algorithm>
#include <map>
#include <sstream>

using ll = long long;
using ull = unsigned long long;
using uint = unsigned int;
static ull tenq = 1000000000;
static ull mod = tenq + 7;

using namespace std;

int main()
{
  ll N;
  string s;
  cin >> N >> s;
  vector<ll> sum(N, 0);
  for (auto i = 0; i < N; i++) {
    sum[i] = (s[i] == 'E' ? 1 : 0) + (i > 0 ? sum[i-1] : 0);
  }
  ll res = N;
  for (auto i = 0; i < N; i++) {
    ll lcost, rcost;
    lcost = 0, rcost = 0;
    if (i > 0) {
      lcost = i - sum[i-1];
    }
    if (i + 1< N) {
      rcost = sum[N-1] - sum[i];
    }
//    cout << "i=" << i << " lcost=" << lcost << " rcost=" << rcost << endl;
    ll cost = lcost + rcost;
    if (cost < res) {
      res = cost;
    }
  }

  cout << res << endl;

  return 0;
}


Measured memory_bytes: 3076
#include <iostream>
 
using namespace std;
 
int main(void)
{
	int n,m,q;
	int i,j,k,l,a,b;
	struct points
	{
		int towards[501];
	} point[501];
	cin>>n>>m>>q;
	for(i=0;i<=n;i++)
		for(j=i;j<=n;j++)
			point[i].towards[j]=0;
	for(i=0;i<m;i++)
	{
		cin>>j>>k;
		for(l=k;l<=n;l++)
			point[j].towards[l]++;
	}
	for(i=0;i<q;i++)
	{
		a=0;
		cin>>j>>k;
		for(l=j;l<=k;l++)
			a+=point[l].towards[k];
		cout<<a<<endl;
	}
	return 0;
}


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

const int N=2e5+100;
const int mod=1e9+7;
typedef long long ll;


typedef pair<int,int> pa;

int a[600][600];
int p[600][600];
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);
    int n,m,q;
    cin>>n>>m>>q;
    int maxx=0;
    for(int i=1;i<=m;i++){
        int l,r;
        cin>>l>>r;
        maxx=max(maxx,r);
        a[l][r]++;
    }

    for(int i=1;i<=maxx;i++){
        for(int j=1;j<=maxx;j++){
            p[i][j]=p[i][j-1]+a[i][j];
        }
    }

    while(q--){
        int a,b;cin>>a>>b;
        int ans=0;
        for(int i=a;i<=b;i++){
            ans+=p[i][b];
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 5948
from collections import defaultdict
import queue

N,M = map(int,input().split())

guide = {}
room = defaultdict(list)

for i in range(M):
    a,b = map(int,input().split())
    room[a].append(b)
    room[b].append(a)


q = queue.Queue()

for i in room[1]:
    q.put(i)
    guide[i] = 1

while not(q.empty()):
    x = q.get()
    for i in room[x]:
        if i not in guide:
            guide[i]=x
            q.put(i)



if len(guide) != N:
    print("No")
else:
    print("Yes")
    for i in range(2,N+1):
        print(guide[i])


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

class __ufnode
{
public:
    __ufnode *m_parent;
    int m_count;

    __ufnode()
    {
        m_parent = this;
        m_count = 1;
    }

    __ufnode *root()
    {
        return _getroot(this);
    }

    bool connect_to(__ufnode *t)
    {
        __ufnode *root = _getroot(this);
        __ufnode *target = _getroot(t);
        if( root == target ) return false;
        if( root->m_count > target->m_count )
        {
            target->m_parent = root;
            root->m_count += target->m_count;
        }
        else
        {
            root->m_parent = target;
            target->m_count += root->m_count;
        }
        return true;        
    }

private:
    __ufnode *_getroot(__ufnode *current)
    {
        if( current->m_parent == current ) return current;
        __ufnode *root = _getroot(current->m_parent);
        current->m_parent = root;
        return root;
    }
};

class unionfind
{
private:
    __ufnode *m_nodes;
    int m_size;

public:
    unionfind(int size)
    {
        m_nodes = new __ufnode[size];
        m_size = size;
    }

    ~unionfind()
    {
        delete m_nodes;
    }

    bool unite(int a, int b)
    {
        return m_nodes[a].connect_to(m_nodes + b);
    }
    
    bool issame(int a, int b)
    {
        return m_nodes[a].root() == m_nodes[b].root();
    }

    // すべてを連結。連結前に何個のグループにわけたか
    int connectall()
    {
        int count = 1;
        for( int i = 1; i < m_size; i++ )
        {
            if( unite(0, i) ) count++;
        }
        return count;
    }
};

int* mallocint(int si)
{
    return (int*) malloc(si * sizeof(int));
}

int* inputint_0(int n)
{
    int *ans = mallocint(n);
    for( int i = 0; i < n; i++ ) 
    {
        cin >> ans[i];
        ans[i]--;
    }
    return ans;
}

int main()
{
    int n, m;
    cin >> n >> m;
    int *p = inputint_0(n);
    unionfind uf(n);
    for( int i = 0; i < m; i++)
    {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        uf.unite(x, y);
    }

    int *invp = new int[n];
    for( int i = 0; i < n; i++ ) invp[p[i]] = i;

    int ans = 0;
    for( int i = 0; i < n; i++)
    {
        if( uf.issame(i, invp[i]) ) ans++;
    }

    cout << ans;
}


Measured memory_bytes: 5572
#include <iostream>
#include <string>
#include <algorithm>
// #include <vector>
// #include <algorithm>
// #include <cmath>
// #include <math.h>
using namespace std;

int sum(int N){
    int s = 0;
    while(N > 0){
        s += N % 10;
        N /= 10;
    }
    return s;
}

int main(){
    int N;
    cin >> N;
    int A, B, s;
    int m = 1000000000;
    for (int i=1; i<N; i++){
        A = i;
        B = N-i;
        s = sum(A) + sum(B);
        if (m>s) m=s;
    }
    cout << m << endl;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
typedef unsigned long long ull;

int main()
{
    int N;
    int Ai;
    vector<int> A;
    cin >> N;
    for(int i=0;i<N;i++){
        cin >> Ai;
        A.push_back(Ai);
    }
    sort(A.begin(), A.end());
    ull sum = 0;
    if(A.size()%2==1){
        auto med = A.at(A.size()/2);
        for(auto a : A){
            sum += 2 * abs(a-med);
        }
        sum -= min(
                    abs(med - A.at(A.size()/2-1)),
                    abs(med - A.at(A.size()/2+1))
                  );
    }else{
        auto med1 = A.at(A.size()/2-1);
        auto med2 = A.at(A.size()/2);
        for(auto a : A){
            sum += abs(a-med1);
            sum += abs(a-med2);
        }
        sum -= med2 - med1;
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 892
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef long double ld;
const double pi=acos(-1.0);
const ll mod=pow(10,9)+7;
const ll INF=pow(2,31)-1;
using str=string;
typedef pair<int,int> P;
typedef vector<int> vi;

ll gcd(ll a,ll b){
    ll v0=a,v1=b,v2=a%b;
    while(v2!=0){
        v0=v1;
        v1=v2;
        v2=v0%v1;
    }
    return v1;
}

ll lcm(ll a,ll b){
    return (a*b/gcd(a,b));
}

int main(){
    int h,a;
    cin >> h >> a;
    int ans=0;
    while(h>0){
        h-=a;
        ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MOD 1000000007
#define INF 1e9
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(){
    int a,p;
    cin>>a>>p;
    
    int ans=0;
    p+=3*a;
    ans=p/2;
    cout<<ans<<endl;
}

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

int n;
char pre;
map<string,int>Map;



int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		string s;
		cin>>s;
		if(Map[s])
		{
			puts("No");
			return 0;
		}
		Map[s]++;
		if(s[0] != pre && i != 1)
		{
			puts("No");
			return 0;
		}
		pre = s[s.size()-1];
	}
	puts("Yes");
	return 0;
}

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

using namespace std;
#define DBG(x)                         \
    (void)(cout << "L" << __LINE__     \
                << ": " << #x << " = " \
                << (x) << '\n')
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int maxn = 110000;
int main()
{
    //检查有没有特判0,有没有越界限.
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setiosflags(ios::fixed) << setprecision(12);
    int h, a;
    cin >> h >> a;
    int ans = ceil(h * 1.0 / a);
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
typedef struct s{char w[33];int a;}s;main(){int i,j,k,o,e=0;char w[1001];s t[1000];for(i=0;i<1000;i++){t[i].w[0]='\0';t[i].a=0;}scanf("%[^\n]",w);getchar();j=0,k=0;for(i=0;w[i]!='\0';i++){if(isalpha(w[i])){t[j].w[k]=w[i];k++;}else if(w[i]=' '){k=0;j++;}}o=0;for(i=0;t[i].w[0]!='\0';i++){for(j=i+1;t[j].w[0]!='\0';j++){if(strcmp(t[i].w,t[j].w)==0){t[i].a+=1;if(o<t[i].a) o=t[i].a;}}}for(i=0;t[i].w[0]!='\0';i++){if(o==t[i].a){printf("%s ",t[i].w);break;}}for(i=32;i>0;i--){for(j=0;t[j].w[0]!='\0';j++){if(isalpha(t[j].w[i])){printf("%s\n",t[j].w);return 0;}}}return 0;}

Measured memory_bytes: 608
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
//#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

//string yorn(bool a){if(a) return"Yes" ; return "No" ;}
//string YorN(bool a){if(a) return"YES" ; return "NO" ;}
ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
//ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vector<long long> &a){sort(a.begin(),a.end()) ;}
//void myrev(vector<long long> &a){reverse(a.begin(),a.end()) ;}

int main(){
	ll n ; cin >> n ;
	vll a(n) ;
	for(int i=0;i<n;i++) cin >> a.at(i) ;
	vll l(n+1),r(n+1) ;
	l.at(0) = r.at(n) = 0 ;
	for(int i=0;i<n;i++){
		l.at(i+1) = gcd(l.at(i),a.at(i)) ;
		r.at(n-1-i) = gcd(r.at(n-i),a.at(n-1-i)) ;
	}
	ll ans = 0 ;
	for(int i=0;i<n;i++){
		ll sub = gcd(l.at(i),r.at(i+1)) ;
		if(ans<sub) ans = sub ;
	}
	cout << ans << endl ;
}


Measured memory_bytes: 2560
#include <iostream>
#include <queue>
#include <map>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;

long long N; vector<int>V;

void init() {
	for (int i = 2; i <= 100; i++) {
		bool prime = false;
		for (int j = 2; j <= i - 1; j++) {
			if (i%j == 0) prime = true;
		}
		if (prime == false) V.push_back(i);
	}
}

long long solve(long long M) {
	long long sum = 0, cx = N;
	while (cx >= 1) {
		sum += (cx / M); cx /= M;
	}
	return sum;
}

long long F[109], ret = 0;

int main() {
	cin >> N; init();
	for (int i = 0; i < V.size(); i++) {
		F[i] = solve(V[i]);
	}

	// (5, 5, 3)
	for (int i = 0; i < 25; i++) {
		for (int j = i + 1; j < 25; j++) {
			for (int k = 0; k < 25; k++) {
				if (i == j || i == k || j == k) continue;
				if (F[i] >= 4 && F[j] >= 4 && F[k] >= 2) ret++;
			}
		}
	}

	// (15, 5)
	for (int i = 0; i < 25; i++) {
		for (int j = 0; j < 25; j++) {
			if (i == j) continue;
			if (F[i] >= 14 && F[j] >= 4) ret++;
		}
	}

	// (25, 3)
	for (int i = 0; i < 25; i++) {
		for (int j = 0; j < 25; j++) {
			if (i == j) continue;
			if (F[i] >= 24 && F[j] >= 2) ret++;
		}
	}

	// (75)
	for (int i = 0; i < 25; i++) {
		if (F[i] >= 74) ret++;
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 384
import sys
input = sys.stdin.readline
sys.setrecursionlimit(1000000)
n, q = map(int, input().split())

trees = [ [] for i in range(n) ]
for i in range(n-1):
    a, b = map(int, input().split())
    trees[a-1].append(b-1)
    trees[b-1].append(a-1)

values = [ 0 for i in range(n) ]
for i in range(q):
    p, x = map(int, input().split())
    values[p-1] += x

def dfs(i, parent):
    for j in trees[i]:
        if j == parent: continue
        values[j] += values[i]
        dfs(j, i)

dfs(0, -1)
print(*values)

Measured memory_bytes: 230920
from collections import deque
k = int(input())
d = deque([1,2,3,4,5,6,7,8,9])

for i in range(k):
    a = d.popleft()
    l = [a%10-1, a%10, a%10+1]
    for j in l:
        if j==-1 or j==10:
            continue
        d.append(a*10 + j)

print(a)

Measured memory_bytes: 12404
#include <stdio.h>

int		main()
{
	int		N, i = 0;
	char	S[10000];

	scanf("%d\n", &N);
	scanf("%s\n", S);
	while (S[i])
	{
		S[i] += N;
		if (S[i] > 'Z')
			S[i] = S[i] - 'Z' - 1 + 'A';
		i++;
	}
	printf("%s\n", S);
	return (0);
}


Measured memory_bytes: 128
#include <stdio.h>
#include <string.h>

int main(void)
{
	int i;
	int length;
	char s[101];

	scanf("%s", s);

	length = strlen(s);

	for (i = 0; i < length; i++) //偶数文字目にLが含まれる場合
	{
		if (i % 2 == 0 && s[i] == 'L') {
			printf("No\n");
			return 0;
		}
		else if (i % 2 != 0 && s[i] == 'R') //奇数文字目にRが含まれる場合
		{
			printf("No\n");
			return 0;
		}
	}

	printf("Yes\n");

	return 0;
}

Measured memory_bytes: 128
from collections import deque
H, W = [int(x) for x in input().split()]
maze = [input() for i in range(H)]
move = [[0, 1], [0, -1], [1, 0], [-1, 0]]
d = [[float('inf')] * W for i in range(H)]
black = 0
for i in range(H):
    for j in range(W):
        if maze[i][j] == '#':
            black += 1

def bfs():
    q = deque()
    q.append([0, 0])
    d[0][0] = 0

    while q:
        x, y = q.popleft()
        if x == H - 1 and y == W - 1:
            break
        for v in move:
            nx = x + v[0]
            ny = y + v[1]
            if 0 <= nx < H and 0 <= ny < W and maze[nx][ny] == '.' and d[nx][ny] == float('inf'):
                q.append([nx, ny])
                d[nx][ny] = d[x][y] + 1
    return d[H-1][W-1]

print(-1) if bfs() == float('inf') else print(H*W - black - (bfs() + 1))


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

int main() {
int n;
cin >> n;
vector<int>a(n);
for(int i=0;i<n;i++){
    cin >> a.at(i);
}
for(int i=0;i<n-1;i++){
    cout << a.at(n-i-1) << " ";
}
cout << a.at(0) << endl;
}



Measured memory_bytes: 3116
n = int(input())

s =list(map(int, input().split()))
s.sort()
a = 1
for i in range(n):
    a = a * s[i]
    if a > 1000000000000000000:
        print('-1')
        exit()
    else:
        if a == 0:
            print('0')
            exit()

print(a)


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

using namespace std;

#define all(x) (x).begin(), (x).end()
typedef long double ld;
typedef long long ll;


int main() {
#ifdef LOCAL
  assert(freopen("a.in", "r", stdin));
#endif

  ios_base::sync_with_stdio(false);

  int x, y;
  cin >> x >> y;
  if (x % y == 0)
    cout << -1;
  else
    cout << x;
  cout << endl;

}



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

ll N,M;
ll ans=0;
int main(){
    cin>>N>>M;
    ll guusuu=N;
    ll kisuu=M;
    ans=kisuu*(kisuu-1)/2+guusuu*(guusuu-1)/2;
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
import itertools as it

N =  int(input())
n =list(map(str,range(10)))
ans = 0
for i in it.combinations_with_replacement(n,16):
  a = int("".join(i))
  if a <= N:
    b = sum(map(int,i))
    ans = max(ans,b)
print(ans)

Measured memory_bytes: 74812
#include <bits/stdc++.h>
#include<chrono>
using namespace std;
using ll = long long;

int main() {
  int N;
  cin >> N;
  int A = 0;
  int B = 0;
  int C = 0;
  //A,B,Cはそれぞれ奇数、2だけの倍数、4の倍数の個数
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    if (a%2 == 1) {
      A++;
    }
    else {
      if (a%4 == 0) {
        C++;
      }
      else {
        B++;
      }
    }
  }
  if (B == 0) {
    if (A <= C+1) {
      cout << "Yes" << endl;
    }
    else {
      cout << "No" << endl;
    }
  }
  else {
    if (A <= C) {
      cout << "Yes" << endl;
    }
    else {
      cout << "No" << endl;
    }
  }
}

  

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

#define sz(x) (int)x.size() 
#define pb push_back 
#define mp make_pair 
#define fi(a, b) for(int i=a; i<=b; i++) 
#define fj(a, b) for(int j=a; j<=b; j++) 
#define fo(a, b) for(int o=a; o<=b; o++) 
#define fdi(a, b) for(int i=a; i>=b; i--) 
#define fdj(a, b) for(int j=a; j>=b; j--) 
#define fdo(a, b) for(int o=a; o>=b; o--) 

#ifdef LOCAL
#define err(...) fprintf(stderr, __VA_ARGS__)
#else
#define err(...) while(false) {}
#endif

typedef long long ll; 
typedef pair<int, int> pii; 
typedef pair<ll, ll> pll; 
typedef vector<int> vi; 
typedef vector<ll> vll;
typedef vector<pii> vpii; 
typedef vector<pll> vpll; 
typedef long double ld;
typedef unsigned long long ull;

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

int const MAX = 2e5 + 41;

char s1[MAX];
char s2[MAX];

string a, b;

int n;

void solve() {
	a = string(s1 + 1);
	b = string(s2 + 1);
	if (a + b > b + a) {
		swap(a, b);
	}
	fi(0, n) {
		int len = i * sz(b);
		if ( (n - len) % sz(a) == 0) {
			int q = (n - len) / sz(a);
			fj(1, q) {
				printf("%s", a.c_str());
			}
			fj(1, i) {
				printf("%s", b.c_str());
			}			
			return;
		}
	}
}

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

  scanf("%d", &n);
  scanf(" %s", s1 + 1);
  scanf(" %s", s2 + 1);
	solve();		

	
#ifdef LOCAL
	err("ELAPSED TIME: %.3Lf\n", (ld) clock() / CLOCKS_PER_SEC);
#endif	
	
	return 0;
}

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

#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define lrep(i,n) for(long long  i = 0; i < (long long)(n); i++)
#define lrep2(i,a,n) for(long long i = (long long)(a); i <= (long long)(n); i++)
#define irrep(i,n) for(int i = (int)(n-1); i > -1; i--)
#define irrep2(i,a,n) for(int i = (int)(n); i >= (int)(a); i--)
#define fi first
#define se second

using ll = long long;
using v_int = std::vector<int>;
using v2_int = std::vector<v_int>;
using v_ll = std::vector<ll>;
using v2_ll = std::vector<v_ll>;
using v_string = std::vector<std::string>;
using v_bool = std::vector<bool>;
using v2_bool = std::vector<v_bool>;
using pii = std::pair<int, int>;
using pll = std::pair<ll, ll>;

const double PI = 3.1415926535897932;
const int INF = (int)1e9;
const ll LINF = (ll)1e18;
const ll MOD = 1000000007;
const int dr[4] = {1, 0, -1, 0};
const int dc[4] = {0, 1, 0, -1};

using namespace std; 

template<typename T, typename U> inline
ostream& operator<<(ostream &o, pair<T,U> &p)
{
    return o << "{" << p.first << "," << p.second << "}";
}

template<typename T, typename U, typename V> inline
ostream& operator<<(ostream &o, tuple<T,U,V> &p)
{
    return o << "{" << get<0>(p) << "," << get<1>(p) << "," << get<2>(p) << "}";
}

template<typename T> inline
istream& operator>>(istream &is, vector<T> &v)
{
    int len = (int)v.size();
    for(int i = 0; i < len; i++) {
        is >> v[i]; 
    }
    return is;
}

template<typename T> inline
ostream& operator<<(ostream &os, vector<T> &v)
{
    int len = (int)v.size();
    for(int i = 0; i < len; i++) { 
        os << v[i];
        if(i != len-1) { os << ","; } 
    } 
    return os;
}

template<typename T> inline
void chmin(T &a, T b) { a = min(a, b); }

template<typename T> inline
void chmax(T &a, T b) { a = max(a, b); }

int main(void)
{
    ll n;
    cin >> n;
    
    string s;
    do {
        n--;
        s = (char)((n)%26 + 'a') + s;
        n /= 26;
    } while(n);
    cout << s << endl;
    return 0;
}

/*atcoder*/


Measured memory_bytes: 3608
#include<stdio.h>
#include<string.h>
int main()
{
    char s[20],i,a;
    int p,q;
    while(gets(s)){
    p=0;
    q=strlen(s)-1;
    while(p<q){
        a=s[p];
        s[p]=s[q];
        s[q]=a;
        p++;
        q--;
    }
    printf("%s\n",s);
    }
    return 0;
}

Measured memory_bytes: 524
def knapsack(points):
    days = len(points)

    # dp[i][j] is the max points we can get at day i and choosing activity j
    dp = [[0]*3] * days
    dp[0] = points[0]
    for i in range(1, days):
        newdp = [0] * 3
        for j in range(3):
            newdp[j] = points[i][j] + max([dp[i-1][k] for k in range(3) if k != j])
            #dp[i][j] = points[i][j] + max([dp[i-1][k] for k in range(3) if k != j])
        dp[i] = newdp

    return max(dp[-1])


if __name__ == "__main__":
    N = int(input())
    points = []
    for _ in range(N):
        points.append([int(x) for x in input().split()])

    print(knapsack(points))


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

const int maxn = 1 << 18;

int n, m, M, v[20], f[maxn + 10], g[maxn + 10], x[maxn + 10], y[maxn + 10], z[maxn + 10], LOG[maxn + 10], ans[maxn + 10], fy[maxn + 10][20], fz[maxn + 10][20];

void chkmax(int &x, int y) {
	(x < y) && (x = y);
	return;
}

void chkmin(int &x, int y) {
	(x > y) && (x = y);
	return;
}

int main() {
	scanf("%d%d", &n, v);
	while(v[m]) {
		v[m + 1] = v[m] >> 1;
		++m;
	}
	v[m] = v[0];
	v[0] = 0;
	M = 1 << m;
	for (int i = 2; i < M; ++i) {
		LOG[i] = LOG[i >> 1] + 1;
	}
	for (int i = 1; i <= n; ++i) {
		scanf("%d", x + i);
		z[i] = y[i - 1] = x[i] - x[i - 1];
	}
	for (int i = 0; i <= m; ++i) {
		int lst = n;
		fy[n][i] = n;
		for (int j = n - 1; j; --j) {
			if(y[j] > v[i]) {
				lst = j;
			}
			fy[j][i] = lst;
		}
		lst = 1;
		fz[1][i] = 1;
		for (int j = 2; j <= n; ++j) {
			if(z[j] > v[i]) {
				lst = j;
			}
			fz[j][i] = lst;
		}
	}
	for (int s = 0; s < M; ++s) {
		g[s] = n + 1;
	}
	for (int s = 1; s < M; ++s) {
		int t = s;
		while(t) {
			int x = (t & (-t)), i = LOG[x], y = s ^ x, j = f[y];
			chkmax(f[s], j == n ? n : fy[j + 1][i]);
			j = g[y];
			chkmin(g[s], j == 1 ? 1 : fz[j - 1][i]);
			t ^= x;
		}
	}
	for (int s = 0; s < M; ++s) {
		int t = M - 1 ^ s;
		int l = f[s] + 1, r = g[t] - 1;
		if(l >= r) {
			for (int i = 1; i <= n; ++i) {
				puts("Possible");
			}
			return 0;
		}
		int i = fy[l][m];
		if(i >= r) {
			++ans[l];
			--ans[r + 1];
		}
	}
	for (int i = 1; i <= n; ++i) {
		ans[i] += ans[i - 1];
		puts(ans[i] ? "Possible" : "Impossible");
	}
	return 0;
}

Measured memory_bytes: 42368
N=int(input())
num_list=[]
num_list.append(int(input()))
num_list.append(int(input()))
num_list.append(int(input()))
num_list.append(int(input()))
num_list.append(int(input()))

min_num=min(num_list)
if N%min_num==0:
    group=N//min_num
else:
    group=N//min_num+1
ans=5+(group-1)
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#define ll long long
using namespace std;
const int MAX_SIZE = 3e5+10;
ll dp[MAX_SIZE], n;
const ll mod =1e9+7;
int main()
{
    //freopen("test.txt", "r", stdin);

    scanf("%d", &n);
    //memset(dp, 0, sizeof(dp));
    for (int i = 1; i <= n; i++)
    {
        ll t;
        scanf("%lld", &t);
        int cnt = 0;
        while (t)
        {
            cnt++;
            if (t % 2)
                dp[cnt]++;
            t /= 2;
        }
    }
    ll ans = 0;
    for (int i = 0; i < 61; i++)
        ans =(ans+ ((1LL << i)%mod * dp[i + 1]%mod * (n - dp[i + 1])%mod)%mod)%mod;
    printf("%lld\n", ans);
    return 0;
}


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

int main() {
	long long int n, a, t;
	cin >> n >> a;
	for(int i = 0; i<4; i++){
		cin >> t;
		a = min(t, a);
	}
	cout << (n-1)/a+5 << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <ctime>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <functional>
#include <fstream>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <numeric>
#include <cassert>
using namespace std;
static const double EPS = 1e-10;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(a) a.begin(),a.end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define SS stringstream
#define DBG1(a) rep(_X,sz(a)){printf("%d ",a[_X]);}puts("");
#define DBG2(a) rep(_X,sz(a)){rep(_Y,sz(a[_X]))printf("%d ",a[_X][_Y]);puts("");}
#define bitcount(b) __builtin_popcount(b)
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)

#define delete(a,n) a.erase(remove(all(a),n),a.end())
template<typename T, typename S> vector<T>& operator<<(vector<T>& a, S b) { a.push_back(b); return a; }
template<typename T> void operator>>(vector<T>& a, int b) {while(b--)if(!a.empty())a.pop_back();}
bool isprime(int n){ if(n<2)return false;  for(int i=2;i*i<=n;i++)if(n%i==0)return false;  return true;} 
ll b_pow(ll x,ll n){return n ? b_pow(x*x,n/2)*(n%2?x:1) : 1ll;}
string itos(int n){stringstream ss;ss << n;return ss.str();}

long long in(){
	long long n;
	scanf("%lld",&n);
	return n;
}

int cnt[101][3];
int score[201][3];
//ok
int main(){
	//ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	for(int i = 0 ; i < n ; i++){
		for(int j = 0 ; j < 3 ; j++){
			cin >> score[i][j];
			cnt[score[i][j]][j]++;
		}
	}
	for(int i = 0 ; i < n ; i++){
		int ans = 0;
		for(int j = 0 ; j < 3 ; j++){
			if( cnt[score[i][j]][j] == 1 ) ans += score[i][j];
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 1168
#include<stdio.h>
int main(void){
	int n,i,x,j;
	int card[4][13]={};
    char M;
	
	scanf("%d",&n);
	for(i = 0;i < n+1;i++){
		scanf("%c %d%*c",&M ,&x);
		if(M == 'S'){
			card[0][x-1]=1;
		}else if(M =='H'){
			card[1][x-1]=1;
		}else if(M == 'C'){
			card[2][x-1]=1;
		}else if(M == 'D'){
			card[3][x-1]=1;
		}
	}
	for(i = 0;i < 4;i++){
		for(j = 0;j < 13;j++){
			if(card[i][j] == 0){
			if(i == 0){
				printf("S %d\n",j+1);
		}else if(i == 1){
			printf("H %d\n",j+1);
		}else if(i == 2){
			printf("C %d\n",j+1);
		}else if(i == 3){
			printf("D %d\n",j+1);
		}
		}
	}
	}
return 0;
}

Measured memory_bytes: 596
import sys

def solve():
    N = int(input())
    T, A = [int(i) for i in input().split()]
    H = [int(i) for i in input().split()]

    dif = sys.maxsize
    ans = -1
    for i in range(N):
        t = T - H[i] * 6 / 1000
        if abs(t - A) < dif:
            dif = abs(t - A)
            ans = i + 1
    print(ans)

if __name__ == "__main__":
    solve()

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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = 1LL << 60;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(16);

	//cout << setprecision(10) << scientific << ans << endl;
}

signed main() {
	ll k;

	cin >> k;

	if (k % 2 == 0) {
		cout << (k / 2) * (k / 2) << endl;
	}
	else {
		cout << ((k + 1) / 2) * ((k - 1) / 2) << endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(int i = 0; i < x; i++)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
const ll MOD = 1e9+7;
const int n_max = 1e5+10;

int main(){
    int n; cin >> n;
    vector<int> h(n);
    rep(i,n) cin >> h[i];
    int res = 0;
    int tmp_max;
    rep(i,n){
        // if(!i){
        //     res++;
        //     tmp_max = max(tmp_max, h[i]);
        //     continue;
        // }
        if(h[i] >= tmp_max)res++;
        tmp_max = max(tmp_max, h[i]);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#define MAX 110;
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
    int c[3][3];
    for(int i=0;i<3;++i)
    {
        scanf("%d %d %d",&c[i][0],&c[i][1],&c[i][2]);
    }

    int a1,a2,a3,b1,b2,b3;

    bool can=false;

    a1=0;
    b1=c[0][0]-a1;
    b2=c[0][1]-a1;
    b3=c[0][2]-a1;

    a2=c[1][0]-b1;
    a3=c[2][0]-b1;
    if(a2==c[1][1]-b2 && a2==c[1][2]-b3 && a3==c[2][1]-b2 && a3==c[2][2]-b3) can=true;

    if(can) cout<<"Yes"<<"\n";
    else cout<<"No"<<"\n";

}

Measured memory_bytes: 256