akhauriyash/Code-Regression huggingface dataset:
from sys import setrecursionlimit

setrecursionlimit(10 ** 6)

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

graph   = [ [] for _ in range(N) ]
queries = { p: 0 for p in range(N) }

for _ in range(N - 1):
    a, b = map(lambda x: int(x) - 1, input().split())

    graph[a].append(b)
    graph[b].append(a)

for _ in range(Q):
    p, x = map(int, input().split())

    queries[p - 1] += x

answer = [ 0 ] * N

def dfs(p, p_before, acc):
    acc += queries[p]

    answer[p] = acc

    for child in graph[p]:
        if child == p_before:
            continue

        dfs(child, p, acc)

dfs(0, -1, 0)

print(*answer)

Measured memory_bytes: 252292
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <utility>

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

using namespace std;

/* DP ??????*/
/* ????????????????????§?????????*/


int main(void){
    
    int dannsuu;
    int times[31] = {0};
    int year;
    times[0] = 1;
    times[1] = 1;
    times[2] = 2;
    
    while( cin >>dannsuu,dannsuu)
    {
        FOR(i, 3, dannsuu+1)
        times[i] = times[i-1]+times[i-2] + times[i-3];
        
        
        year = (times[dannsuu] /(365*10));
        
        if((times[dannsuu] % (365 * 10)))
            year +=1;
        
        cout << year << endl;
        
    }
    return 0;
    
}

Measured memory_bytes: 1164
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

string a[256];

int main() {
	a[' ']="101";
	a['\'']="000000";
	a[',']="000011";
	a['-']="10010001";
	a['.']="010001";
	a['?']="000001";
	a['A']="100101";
	a['B']="10011010";
	a['C']="0101";
	a['D']="0001";
	a['E']="110";
	a['F']="01001";
	a['G']="10011011";
	a['H']="010000";
	a['I']="0111";
	a['J']="10011000";
	a['K']="0110";
	a['L']="00100";
	a['M']="10011001";
	a['N']="10011110";
	a['O']="00101";
	a['P']="111";
	a['Q']="10011111";
	a['R']="1000";
	a['S']="00110";
	a['T']="00111";
	a['U']="10011100";
	a['V']="10011101";
	a['W']="000010";
	a['X']="10010010";
	a['Y']="10010011";
	a['Z']="10010000";
	string str;
	string b;
	string c;
	while(getline(cin,str)){
		int i=0;
		b="";
		for(i=0;str[i]>=' ';i++){
			b+=a[str[i]];
		}
		while(b.size()%5)b+="0";
		int num;
		for(i=0;i<b.size();i+=5){
			int j;
			num=0;
			for(j=0;j<5;j++){
				num*=2;
				num+=b[i+j]-'0';
			}
			if(num<26)cout<<(char)(num+'A');
			else if(num==26)cout<<" ";
			else if(num==27)cout<<".";
			else if(num==28)cout<<",";
			else if(num==29)cout<<"-";
			else if(num==30)cout<<"\'";
			else if(num==31)cout<<"?";
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
# C - Average Length
import math
N = int(input())
A = [list(map(int, input().split())) for i in range(N)]

tmp = 0
for i in range(N):
    for j in range(N):
        if i == j:
            pass
        else:
            tmp += (((A[i][0]-A[j][0])**2)+((A[i][1]-A[j][1])**2))**0.5
tmp = tmp* math.factorial(N-1)

ans = tmp/math.factorial(N)
print(ans)


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

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

	map<string, int> map;
	int max_val = 0;

	rep(i, N) {
		string s;
		cin >> s;

		map[s]++;
		max_val = max(max_val, map[s]);
	}

	for (auto p : map) {
		if (p.second == max_val)
			cout << p.first << endl;
	}
}


Measured memory_bytes: 25216
#include <stdio.h>
//#include <math.h>
#define MIN(x,y) (((x) > (y)) ? (y) : (x))
#define ABS(x) ((x) >= 0 ? (x) : (-(x)))
#define M_PI 3.14159265
int main() {
  int r;
  scanf("%d", &r);
  printf("%lf", 2.0 * (double)r * M_PI);
  return 0;
}

Measured memory_bytes: 2216
package main 

import (
  "fmt"
)

func main() {
  var h, w int
  fmt.Scan(&h, &w)
  
  c := make([]string ,h)
  for i := 0; i < h; i++ {
    fmt.Scan(&c[i])
  }
  
  for i := 0 ; i < h; i++ {
    fmt.Println(c[i])
    fmt.Println(c[i])
  }
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << x << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
typedef long long ll;
int N,M;
ll K;
ll x[100000];
int s[100000];
int ans[100000];
bool vis[100000];
int main(){
	cin>>N;
	rep(i,N) cin>>x[i];
	int fst=x[0];
	rep(i,N-1) x[i]=x[i+1]-x[i];
	rep(i,N-1) s[i]=i;
	cin>>M>>K;
	rep(i,M){
		int a;
		cin>>a;
		a-=2;
		swap(s[a],s[a+1]);
	}
	rep(i,N-1) if(!vis[i]){
		int n=0;
		int v=i;
		vector<int> vc;
		while(!vis[v]){
			vis[v]=1;
			vc.pb(v);
			v=s[v];
			n++;
		}
		rep(j,n) ans[vc[j]]=x[vc[(j+K)%n]];
	}
	ll sum=fst;
	rep(i,N){
		cout<<sum<<endl;
		if(i==N-1) break;
		sum+=ans[i];
	}
}


Measured memory_bytes: 3072
//#pragma GCC optimize("03,unroll-loops")
//#pragma GCC target("avx,avx2,fma")

#include<bits/stdc++.h>
typedef long long ll;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update>
#define pb           push_back
#define ff           first
#define ss           second
#define gcd(a, b)    __gcd(a, b)
#define lcm(a, b)    ((a)*((b)/gcd(a,b)))
#define all(v)       v.begin(),v.end()
#define rall(v)      v.rbegin(),v.rend()
#define lllim        2147483648
#define Pi           2*acos(0.0)
#define pii          pair<int,int>
#define pll 	     pair<ll,ll>
#define mem(a,b)     memset(a, b, sizeof(a))
#define fill_(a,b)   fill(a,a+n,b);
#define mod          1000000007
#define fast_cin     ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define filein       freopen("input.txt","r", stdin)
#define D(x)         cerr << __LINE__ << ": " << #x << " = " << (x) << '\n'
#define case		 int t,cas=1;cin>>t;while(t--)
#define rep(i,a,n)   for(int i=a;i<n;i++)
#define rev(i,n,a)   for(int i=n;i>=a;i--)
#define sim 		 template<class T

/*------------------------------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
/*---------------------------------------------------------------------*/

sim > void ckmin(T& a, const T& b) {
    a= b < a? b:a;
}
sim > void ckmax(T& a, const T& b) {
    a= b > a? b:a;
}

///.............................input.................................///
sim > void readvec( std::vector<T>& v, const int n) {
    rep(i,0,n) {
        T p;
        std::cin>>p;
        v.pb(p);
    }
}
///...........................input end...............................///


using namespace std;
using namespace __gnu_pbds;

const int maxn=200005;

void solve()
{
  ll n;
  cin>>n;
  ll ans=0;
  
  int div[n+2]={0};
  
   for (int i = 1; i <= n; i++)
   { 
        for (int j = 1; j * i <= n; j++) 
            div[i * j]++; 
    }
  
  for(ll i=1;i<n;i++)
  {
	  ll num=n-i;
	  
	  ll cnt=1;
	  
	  if(num==1)
		ans++;
	  else if(div[i]%2)
	  {
		  ans+=(2*(div[num]/2));
		  ans++;
	  }
	  else ans+=(2*(div[num]/2));
	  
	 // cout<<ans<<endl;
	 
  }
  if(n!=2)
  ans--;
  
  cout<<ans<<endl;

}


int main()
{
    fast_cin;


    //case
    {
        //  cout<<"Case "<<cas++<<": ";
        solve();
    }

    return 0;
}


Measured memory_bytes: 7528
export class Main {
  static main(input: string): void {
    const tmp: string[] = input.split("\n");
    const [n]: number[] = tmp.shift().split(" ").map(int => parseInt(int));
    const a: number[] = tmp.shift().split(" ").map(int => parseInt(int));
    const map = {};
    for (let i = 0; i < n; i++) {
      const ai = a[i];
      if (map[ai] == null) {
        map[ai] = 1;
      } else {
        map[ai] = map[ai] + 1;
      }
    }
    const keys = Object.keys(map);
    let all = 0;
    const minusMap = {};
    for (let i = 0, len = keys.length; i < len; i++) {
      const value = map[keys[i]];
      const count = value * (value - 1) / 2;
      all += count;
      minusMap[keys[i]] = count - (value - 1) * (value - 2) / 2;
    }
    for (let i = 0; i < n; i++) {
      console.log(all - minusMap[a[i]]);
    }
  }
}
Main.main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

#define rep(i, N) for (int i = 0; i < (N); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back

using ll = long long;
using i_i = tuple<int, int>;

vector<vector<int>> f(string s) {
    int N = s.length();
    vector<vector<int>> nxt(N + 2);
    vector<int> a(2, N + 1);
    nxt[N] = nxt[N + 1] = a;
    for (int i = N - 1; i >= 0; i--) {
        int k = s[i] - '0';
        a[k] = i + 1;
        nxt[i] = a;
    }
    return nxt;
}

int main() {
    string s, t;
    cin >> s >> t;
    int N = s.length();
    int M = t.length();
    vector<vector<int>> a = f(s), b = f(t);
    vector<vector<int>> dp(N + 2, vector<int>(M + 2, INT_MAX / 2));
    dp[0][0] = 0;
    rep(i, N + 2) rep(j, M + 2) rep(k, 2) {
        int _i = a[i][k];
        int _j = b[j][k];
        dp[_i][_j] = min(dp[_i][_j], dp[i][j] + 1);
    }
    vector<vector<bool>> pro(N + 2, vector<bool>(M + 2));
    pro[N + 1][M + 1] = true;
    for (int i = N + 1; i >= 0; i--) for (int j = M + 1; j >= 0; j--) rep(k, 2) {
        int _i = a[i][k];
        int _j = b[j][k];
        if (dp[_i][_j] == dp[i][j] + 1 && pro[_i][_j]) pro[i][j] = true;
    }
    // cout << dp[N + 1][M + 1] << endl;
    string ans;
    int i = 0, j = 0;
    while (i < N + 1 || j < M + 1) {
        rep(k, 2) {
            int _i = a[i][k];
            int _j = b[j][k];
            if (dp[_i][_j] == dp[i][j] + 1 && pro[_i][_j]) {
                i = _i;
                j = _j;
                ans.pb('0' + k);
                break;
            }
        }
    }
    cout << ans << endl;
}



Measured memory_bytes: 68020
#include<iostream>
#include <algorithm>

using namespace std;

int nine[6];
int six[7];

int vis[100001];
int num[100001];
int func(int N){
    int m = 100000;
    if (vis[N]) return num[N];
    for (int i = 9; i <= N; i*=9){
        if (9*i <= N && i!=N)continue;
        //cout << i << endl;
        for(int j = 1; j*i <= N; j++){
            int a = j;
            int b = N - a*i;
            //cout << "b" << b << endl;
            //cout << "a" << a << endl;
            m = min(a + func(b), m);
        }
        break;
    }
    //cout << "m" << m << endl;
    for (int i = 6; i <= N; i*=6){
        if (6*i <= N && i!=N)continue;
        for(int j = 1; j*i <= N; j++){
            int a = j;
            int b = N - a*i;
            //cout << a + func(b) << endl;
            //cout << "i:" << i << endl;

            m = min(a + func(b), m);
            
        }
        break;
    }
    vis[N] = 1;
    num[N] = m;
    return m;
}
int main()
{
    // 整数の入力
    int N;
    cin >> N;
    for(int i = 0; i < 100001; i++){
        vis[i] = 0;
    }
    for(int i = 1; i < 6; i++){
        vis[i] = 1;
        num[i] = i;
    }
    
    vis[0] = 1;
    num[0] = 0;
    num[6] = 1;
    vis[6] = 1;
    num[9] = 1;
    vis[9] = 1;
    
    cout <<  func(N) << endl;
    return 0;
}

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

string FMT_F = "%.10f";

static File _f;
void file_io(string fn) { _f = File(fn, "r"); }
static string[] s_rd;
T _RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T _RD(T = long)(File f) { while(!s_rd.length) s_rd = f.readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
T[] _RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[] _RDA(T = long)(File f, T fix = 0) { auto r = f.readln.chomp.split.to!(T[]); r[] += fix; return r; }
T RD(T = long)() { if (_f.isOpen) return _RD!T(_f); else return _RD!T; }
T[] RDA(T = long)(T fix = 0) { if (_f.isOpen)  return _RDA!T(_f, fix); else return _RDA!T(fix); }

size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto N = RD;
	auto edges = new long[2][][](N);
	foreach (i; 0..N-1)
	{
		auto a = RD-1;
		auto b = RD-1;
		edges[a] ~= [b, i];
		edges[b] ~= [a, i];
	}

	auto ans = new long[](N-1);
	long[3][] open = [[0, -1, 0]];
	while (!open.empty)
	{
		auto n = open.front; open.popFront;
		auto u = n[0];
		auto last = n[1];
		auto used = n[2];
		long c = 1;
		foreach (e; edges[u])
		{
			auto v = e[0];
			auto i = e[1];
			if (v == last) continue;
			if (c == used) ++c;
			ans[i] = c;
			open ~= [v, u, c];
			++c;
		}
	}

	long x;
	foreach (e; ans)
		x = max(x, e);
	writeln(x);

	foreach (e; ans)
		writeln(e);
	stdout.flush();
	debug readln();
}

Measured memory_bytes: 20476
#include <cstdio>
#include <cstring>

using namespace std;

char day[10];

int main()
{
    scanf(" %s", day);
    if (strcmp(day, "SUN") == 0)
    {
        printf("7\n");
    }
    else if (strcmp(day, "MON") == 0)
    {
        printf("6\n");
    }
    else if (strcmp(day, "TUE") == 0)
    {
        printf("5\n");
    }
    else if (strcmp(day, "WED") == 0)
    {
        printf("4\n");
    }
    else if (strcmp(day, "THU") == 0)
    {
        printf("3\n");
    }
    else if (strcmp(day, "FRI") == 0)
    {
        printf("2\n");
    }
    else if (strcmp(day, "SAT") == 0)
    {
        printf("1\n");
    }

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  vector<long> a(N);
  for (int i=0;i<N;i++) {
    cin >> a.at(i);
  }
  
  int count=0;
  for (int i=0;i<N;i++) {
    while (a.at(i)%2==0) {
      a.at(i) = a.at(i)/2;
      count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main()
{
   string  s,p;
   cin>>s;
   for (int i = 0; i < s.size(); ++i)
   {
      if(s[i]=='1')
        p+='1';
      if( s[i]=='0')
        p+='0';
      if(s[i]=='B'){  
        if(p.size())
          p.pop_back();
        }
   }
   cout<<p<<endl;;
   return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define repp(i, m, n) for(int i = m; i < (int)n; i++)
#define reps(i, n) for(int i = 1; i <= (int)n; i++)
const int    INF = 100000000;
const double EPS = 1e-10;
const int    MOD = 1000000007;
using namespace std;
typedef long long ll;
typedef pair<int, int> pai;
typedef pair<ll,ll> pal;


int main()
{
	pai a[10010];
	int n;
	while(1)
	{
		cin >> n;
		int h, m, s;
		if(n==0) break;
		rep(i, n)
		{
			char dummy;
			cin >> h >> dummy >> m >> dummy >> s;
			a[i].first=h*3600+m*60+s;
			cin >> h >> dummy >> m >> dummy >> s;
			a[i].second=h*3600+m*60+s;
		}
		sort(a, a+n);
		int b[10010]={};
		rep(i, n)
		{
			for(int j=i+1; j<=n; j++)
			{
				if(a[j].first>=a[i].second && b[j]==0)
				{
					b[j]=b[i]+1;
					break;
				}
			}
		}
		int ans=0;
		rep(i, n) if(b[i]==0) ans++;
		cout << ans << endl;
	}
	return 0;
}

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

const int MOD = 1000000007;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define copy(from, to) copy(from.begin(), from.end(), back_inserter(to))
#define sort(a) sort(a.begin(), a.end())
#define reverse(s) reverse(s.begin(), s.end())
#define p(s) cout << (s) << endl

typedef long long ll;
using namespace std;

template<class T>
void load(vector<T> &v, int n) {
  for (int i = 0; i < n; ++i) {
    T t;
    cin >> t;
    v.push_back(t);
  }
}

template<class T>
T max(vector<T> &v) {
  return *max_element(v.begin(), v.end());
}

template<class T>
T min(vector<T> &v) {
  return *min_element(v.begin(), v.end());
}

void py(bool isUpper = false) {
  if (isUpper) {
    p("YES");
  } else {
    p("Yes");
  }
}

void pn(bool isUpper = false) {
  if (isUpper) {
    p("NO");
  } else {
    p("No");
  }
}

int main() {
  int n, x;
  cin >> n >> x;
  int l[n], d[n + 1];
  for (int i = 1; i <= n; ++i) {
    cin >> l[i];
  }

  d[1] = 0;
  for (int i = 2; i <= n + 1; ++i) {
    d[i] = d[i - 1] + l[i - 1];
  }

  int c = 0;
  for (int i = 1; i <= n + 1; ++i) {
    if (d[i] <= x) c++;
  }
  p(c);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll; 
const ll mod = 1e9+7;
#define fo(i, n) for (int i = 0; i < n; i++)
#define sc(n) scanf("%d", &n) 
using namespace std;

void solve() {
    int a, b; cin >> a >> b;
    cout << max(0, a-2*b);
}

int main() {
    int t = 1;
    //scanf("%d", &t);
    while (t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
using vs = vector<string>;
using vb = vector<bool>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
template<class T> inline void prn(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << ' ';}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int n, k;
    cin >> n >> k;
    vl p;
    vl m;
    ll a;
    REP(i, n) {
        cin >> a;
        if (a >= 0) p.emplace_back(a); else m.emplace_back(-a);
    }

    ll ans = 1;
    if (n == k) {
        REP(i, sz(p)) ans = ans * p[i] % MOD;
        REP(i, sz(m)) ans = ans * -m[i] % MOD;
        if (ans >= 0) cout << ans << endl; else cout << (ans + MOD) % MOD << endl;
        return;
    } else if (sz(p) == 0 and k % 2 == 1) {
        SORT(m);
        REP(i, k) ans = ans * -m[i] % MOD;
        if (ans >= 0) cout << ans << endl; else cout << (ans + MOD) % MOD << endl;
        return;
    }

    SORT(p); REV(p);
    SORT(m); REV(m);
    p.emplace_back(-1);
    m.emplace_back(-1);
    int pi = 0;
    int mi = 0;
    REP(i, k) {
        if (mi == sz(m) - 1) ans = ans * p[pi++] % MOD;
        else if (pi == sz(p) - 1) ans = ans * m[mi++] % MOD;
        else if (p[pi] >= m[mi]) ans = ans * p[pi++] % MOD;
        else ans = ans * m[mi++] % MOD;
    }
    if (mi % 2 == 0) {
        cout << ans << endl;
        return;
    }

    ans = 1;
    if (pi != k and (mi + 1 == sz(m) or mi == k or p[pi] * p[pi - 1] >= m[mi] * m[mi - 1])) {
        REP(i, pi + 1) ans = ans * p[i] % MOD;
        REP(i, mi - 1) ans = ans * m[i] % MOD;
    } else {
        REP(i, pi - 1) ans = ans * p[i] % MOD;
        REP(i, mi + 1) ans = ans * m[i] % MOD;
    }

    cout << ans << endl;
}


Measured memory_bytes: 5552
#include <bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	long long length,num=0;
	length=s.length();
	for(long i=0;i<length;i++)
	{
		int k=s[i]-'0';
		num+=k;
		num=num%9;
	}
	if(num%9==0)
		cout<<"Yes"<<endl;
	else
		cout<<"No"<<endl;
}


Measured memory_bytes: 3692
#include<bits/stdc++.h>
using namespace std;
int main(){
    vector<int>x(10000);
    vector<int>y(10000);
    for(int i=0;i<10000;i++){
        cin>>x.at(i)>>y.at(i);
        if(x.at(i)==0&&y.at(i)==0){
            break;
        }
        else if(x.at(i)<=y.at(i)){
            cout<<x.at(i)<<" "<<y.at(i)<<endl;
        }
        else{cout<<y.at(i)<<" "<<x.at(i)<<endl;
    }
    
    }
}


Measured memory_bytes: 3160
#include<bits/stdc++.h>
using namespace std;const int MOD=1e9+7;map<long long ,long long>dp;
long long Dp(long long x){return dp[x]? dp[x]:dp[x]=((Dp(x/2)+Dp((x-1)/2)+Dp((x-2)/2)))%MOD;}
int main(){dp[0]=1,dp[1]=2;long long n;return cin>>n,cout<<Dp(n),0;} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef complex<double> P;
int H,R;
int U[3];
double D[3];
const double eps = 1e-8;
double getRtoA( double r ){ return 180.0/M_PI*r; }
double da[]={-360.0,0.0,360.0};
bool check(P p, P f, double a, double w, double d ){
  P v = p - f;
  if( abs(v) > a + eps ) return false;
  double an = getRtoA( arg(v) );
  for(int i=0;i<3;i++){
    if( w - d - eps < an + da[i] && an + da[i] < w + d + eps ) return true;
  }
  return false;
}

bool check( P p, vector<vector<P>> u, double a, double w){
  for(int i=0;i<3;i++){
    for(int j=0;j<U[i];j++){
      if( check( p, u[i][j], a, w, D[i] ) ) return false;
    }
  }
  return true;
}

int main(){
  while( cin >> H >> R && (H|R) ){
    vector<P> h;
    vector<vector<P>> u;
    vector<int> w,a;
    u.resize(3);
    for(int i=0;i<H;i++){
      int x,y; cin >> x >> y; h.push_back( P( x, y ) );
    }
    cin >> U[0] >> U[1] >> U[2] >> D[0] >> D[1] >> D[2];
    for(int i=0;i<3;i++){
      D[i]/=2.0;
      for(int j=0;j<U[i];j++){
        int x,y; cin >> x >> y;
        u[i].push_back( P(x,y) );
      }
    }

    w.resize(R);a.resize(R);
    for(int i=0;i<R;i++){
      cin >> w[i] >> a[i];
    }

    
    vector<int> res;
    int maxs = 0;
    for(int i=0;i<H;i++){
      int cnt = 0;
      for(int j=0;j<R;j++){
        if( check( h[i], P(0,0), a[j], w[j], D[0] ) ) {
          if( check( h[i], u, a[j], w[j] ) ) cnt++;
        }
      }
      if( cnt == 0 ) continue;
      if( maxs < cnt ){
        res.clear();
        res.push_back( i+1 );
        maxs = cnt;
      } else if( maxs == cnt )
        res.push_back( i+1 );

    }

    if( res.empty() ) cout << "NA";
    else {
      for(int i=0;i<(int)res.size();i++){
        if( i ) cout << " ";
        cout << res[i];
      }
    }
    cout << endl;
    
  }
}

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

using ll = long long;
using P = pair<int, int>;

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

// 4近傍、8近傍
int dx[] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[] = {0, 1, 0, -1, 1, 1, -1, -1};

int main() {
  int a;
  cin >> a;

  cout << a + a * a + a * a * a << endl;
  return 0;
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define str string
#define rep(x,y) for(int i=x;i<y;i++)
#define REP(x,y) for(int j=x;j<y;j++)
#define all(x) x.begin(),x.end()
#define int long long
signed  main(){
  double N,K,B;
  char dif='A'-'a';
  str S1,S2,S3;
  cin>>N>>K>>B;
  if(N<=B&&B<=K)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>

using namespace std;
int n,m;
int a[233333],b[23],p[233333];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		p[i]=p[i-1];
		for(int l=0;l<20;l++)
		{
			if(a[i]&(1<<l))
				p[i]=max(p[i],b[l]),b[l]=i;
		}
	}
	long long ans=0;
	for(int i=1;i<=n;i++)ans+=i-p[i];
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1792
(function main(){
  const lines = require('fs').readFileSync('/dev/stdin', 'utf8').trim().split('\n');
  const n = Number(lines.shift());
  const arr = lines.shift().split(' ').map(Number);
  buildMaxHeap(arr);
  console.log(arr.reduce((s, e) => s += ' ' + e, ''));
})();

function buildMaxHeap(arr) {
  const n = arr.length;
  let left, right, largest;
  const maxHeapify = (i) => {
    right = (left = 2 * i + 1) + 1;
    if (left < n && arr[left] > arr[i]) largest = left;
    else largest = i;
    if (right < n && arr[right] > arr[largest]) largest = right;
    if (largest != i) {
      arr[largest] = [arr[i], arr[i] = arr[largest]][0];
      maxHeapify(largest);
    }
  };

  for (let i = Math.floor(arr.length / 2); i >= 0; i--) maxHeapify(i);
}



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

int main()
{
    vector<int> a(5);
    rep(i, 5) cin >> a[i];
    int k;
    cin >> k;
    string ans = ":(";
    sort(all(a));
    if (a[4] - a[0] <= k)
        ans = "Yay!";
    cout << ans << endl;
    return 0;
}

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

int main() {
    int64_t k, n;
    cin >> k >> n;
    vector<int64_t> a(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    vector<int64_t> b(n);
    for(int i = 0; i < n - 1; i++) b[i] = a[i + 1] - a[i];
    b[n - 1] = k - a[n - 1] + a[0];
    sort(b.rbegin(), b.rend());
    cout << k - b[0] << endl;
    return 0;
}

Measured memory_bytes: 3328
import java.io.*;
import java.util.Scanner;
import java.util.Arrays;

class Main {
    static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) throws IOException {
        int W = ReadInt();
        int H = ReadInt();
        int x = ReadInt();
        int y = ReadInt();
        int r = ReadInt();
        if( r <= x && x <= W - r && r <= y && y <= H - r ) {
            System.out.println("Yes");
        }
        else {
            System.out.println("No");
        }
    }
    static int ReadInt() throws IOException {
        return Integer.parseInt(sc.next());
    }
}

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

using namespace std;

char str[1001];
int main( ) {
	scanf("%s", str + 1);
	int len = (int )strlen(str + 1);
	if (len >= 4) {
		if (str[1] == 'Y' && str[2] == 'A' && str[3] == 'K' && str[4] == 'I')
			printf("Yes\n");
		else printf("No\n");
	}
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;
#define pb push_back
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	vector<ll> a(max(n, 3));
	for (int i = 0; i < n; i++) cin >> a[i];
	for (int i = 3; i < n; i++) a[2] ^= a[i];
	ll ans = (a[0] + a[1] - a[2]);
	bool impossible = (ans & 1) || (ans < 0);
	ans >>= 1;
	impossible &= (ans & a[2]) == (ans + a[2]);
	if (impossible || a[2] < a[1] - a[0]) {
		cout << "-1\n";
		return 0;
	}
	for (int i = log2(a[2]) + 1; i >= 0; i--) {
		if (a[2] & (1LL << i)) {
			if ((ans ^ (1LL << i)) <= a[0])
				ans ^= (1LL << i);
		}
	}
	if (ans > 0 && !(ans ^ a[2] ^ (a[0]+ a[1] - ans))) cout << a[0] - ans << "\n";
	else cout << "-1\n";
	return 0;
}

Measured memory_bytes: 3816
using System;
using System.Linq;
using System.Collections.Generic;
using System.IO;

namespace atcorder2
{
    class Program
    {
        public static long Read()
        {
            return long.Parse(Console.ReadLine());
        }

        public static long[] Reads()
        {

            return Console.ReadLine().Split().Select(long.Parse).ToArray();
        }






        static void Main(string[] args)
        {
            var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);


            var n = Read();
            var s = new long[n];
            for (int j = 0; j <n; j++)
            {
                s[j] = Read();
            }
            Array.Sort(s);
            long i = 0;
            while (i < n&&s[i] % 10 == 0) i++;
            if (s.Sum() % 10 != 0) Console.Write(s.Sum());
            else
            {
                if (i < n) Console.WriteLine(s.Sum() - s[i]);
                else Console.WriteLine(0);
            }

            
           
         
            Console.Out.Flush();
        }
    }
}




Measured memory_bytes: 13396
#include <iostream>
using namespace std;
int main(){
	int n;
	int a, x = 1;
	cin >> n;
	for(int i=0;i < n;i++){
		cin >> a;
		if(a % 2 == 0){
			x*=2;
		}
	}
	int b = 1;
	for(int i = 0;i < n;i++){
		b*=3;
	}
	cout << (b - x) << endl;
}

Measured memory_bytes: 256
mod = 1000000007
n,m = map(int, input().split(" "))
a = set([int(input()) for i in range(m)])
ans = [0]*(n+1)
ans[0] = 1
for j in range(1,n+1):
  if j in a:
    ans[j] = 0
  else:
    ans[j] = (ans[j-1] + ans[j-2])%mod
print(ans[-1])
      

Measured memory_bytes: 56664
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = br.readLine();
        char[] c = line.toCharArray();
        int n = c.length-2;
        System.out.println(c[0] + "" + n + "" + c[c.length-1]);
    }    
}


Measured memory_bytes: 21204
import math
import itertools
n = int(input())
s = tuple(map(int,input().split()))
t = tuple(map(int,input().split()))

ari = [i for i in range(1,n+1)]
l = list(itertools.permutations(ari))
for i in range(math.factorial(n)):
    if s == l[i]:
        a = i
    if t == l[i]:
        b = i
if a >= b:
    print(a-b)
else:
    print(b-a)

Measured memory_bytes: 8052
#include<stdio.h>
int main(void){
    int t[5]={0,6000,4000,3000,2000};
    int i,a,b;
    for(i=0;i<4;i++){
        scanf("%d %d",&a,&b);
        printf("%d\n",t[a]*b);
    }
    return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int mod=1e9+7;
map<int,int>a;
int dfs(int x){
    return a[x]?a[x]:a[x]=(dfs(x/2)+dfs((x-1)/2)+dfs((x-2)/2))%mod;
}
signed main(){
    a[0]=1;
    a[1]=2;
    int n;
    cin>>n;
    cout<<dfs(n)<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.IntStream;
class Main{
	static Scanner s=new Scanner(System.in);
	static int gInt(){return Integer.parseInt(s.next());}
	public static void main(String[]$){
		int n=gInt(),k=gInt();
		int[]a=IntStream.range(0,n).map(i->gInt()).filter(i->i<k).toArray();
		n=a.length;

		int res=0;

		byte[]memo=new byte[k+1];
		boolean[]dp=new boolean[k];
		loop:
		for(int i=0;i<n;++i) {
			if(memo[a[i]]!=0) {
				if(memo[a[i]]==1)
					++res;
				continue;
			}

			Arrays.fill(dp,false);
			dp[0]=true;
			for(int j=0;j<n;++j)if(i!=j) {
				for(int m=k-1-a[j];m>=0;--m) {
					if((dp[m+a[j]]|=dp[m])&&m+a[j]>=k-a[i]) {
						memo[a[i]]=-1;
						continue loop;
					}
				}
			}
			memo[a[i]]=1;
			++res;
		}
		System.out.println(res);
	}
}


Measured memory_bytes: 29312
#include <stdio.h>
int a[200001];
int main()
{
	int n, sum = 0, cnt = 1;
	scanf("%d", &n);
	for(int i=1;i<=n;i++)
	    scanf("%d", &a[i]);
	for(int i=1;i<=n;i++)
	{
		if(a[i]==cnt)
		{
			cnt++;
			sum++;
		}
	}
	if(sum==0)
	{
		printf("-1\n"); return 0;
	}
	printf("%d\n", n-sum);
	return 0;
}

Measured memory_bytes: 896
import java.util.*;
class Main{
    int[] A;
    boolean[] B;
    void run(){
	Scanner sc=new Scanner(System.in);
	while(true){
	    int n=sc.nextInt();
	    int m=sc.nextInt();
	    if((n|m)==0)break;
	    A=new int[n];
	    B=new boolean[101];
	    int sum=0,sumA=0;
	    int temp;
	    for(int i=0;i<n;i++){
		temp=sc.nextInt();
		sum+=temp;sumA+=temp;
		A[i]=temp;
	    }
	    for(int i=0;i<m;i++){
		temp=sc.nextInt();
		sum+=temp;
		B[temp]=true;
	    }
	    if(sum%2==1){
		System.out.println(-1);
		continue;
	    }
	    Arrays.sort(A);
	    int sum2=sum/2;
	    int temp2;
	    int i;
	    for(i=0;i<A.length;i++){
		temp2=sum2-(sumA-A[i]);
		if(temp2>0){
		    if(B[temp2]){
			System.out.println(A[i]+" "+temp2);
			break;
		    }
		}
	    }
	    if(i==A.length)System.out.println(-1);
	}
    }
    public static void main(String[] args){
	new Main().run();
    }
}
//dirty..

Measured memory_bytes: 12000
import math
n=int(input())

x=n**0.5

if x-x//1!=0:
    x=int(x//1)
else:
    x=int(x//1)-1
y=0

for i in range(1,x+1):
    if (n-i)/i-(n-i)//i==0:
        if int((n-i)//i)!=i:
            y+=int((n-i)//i)

print(y)
        

     

    

     

    


Measured memory_bytes: 3060
#define _USE_MATH_DEFINES
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <stack>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <memory.h>
#include <set>
#include <cmath>
#define fio ios::sync_with_stdio(false); cin.tie(NULL);
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int N, M, C;
int func(vector<int>& a, vector<int>& b) {
	int ans = 0;
	for (int i = 0; i < M; i++) {
		ans += a[i] * b[i];
	}
	return ans;
}
int main(void) {
	scanf("%d %d %d", &N, &M, &C);
	vector<int> A(M), B(M);
	for (int i = 0; i < M; i++) {
		scanf("%d", &B[i]);
	}
	int res = 0;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			scanf("%d", &A[j]);
		}
		int ans = func(A, B);
		if (-C < ans) res++;
	}
	printf("%d\n", res);
	return 0;
}
	

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n;
vector<int> v;
int main(){
	cin >> n;
	if(n == 0)
		v.push_back(0);
	while(n != 0){
		if(n % 2 == 0){
			v.push_back(0);
		}else{
			v.push_back(1);
			n--;
		}
		n /= (-2);
	}
	reverse(v.begin(), v.end());
	for(int i=0; i<v.size(); ++i)
		cout << v[i];
	cout << endl;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	int N;
  	int summ = 0;
  	cin >>N;
  int N1 = N;
  while(N1){
  	summ += N1%10;
    N1 /= 10;
  }
  (N%summ == 0)? cout << "Yes"<<'\n': cout << "No"<<'\n';
  return 0;
}


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

using namespace std;

int N;
vector<vector<int>> es;
bool visited[100001];
int df[100001];
int ds[100001];

int dfs1(int v, int d) {
	int result = 0;
	visited[v] = true;
	df[v] = d;
	for (auto &u : es[v]) {
		if (visited[u]) continue;
		dfs1(u, d + 1);
	}
	return result;
}

int dfs2(int v, int d) {
	int result = 0;
	visited[v] = true;
	ds[v] = d;
	for (auto &u : es[v]) {
		if (visited[u]) continue;
		dfs2(u, d + 1);
	}
	return result;
}

int main(int argc, char *argv[]) {
	cin >> N;

	es = vector<vector<int>>(N+1);
	for (int i = 0; i < N - 1; i++) {
		int a, b;
		cin >> a >> b;
		es[a].push_back(b);
		es[b].push_back(a);
	}

	dfs1(1, 0);
	for (int i = 1; i <= N; i++) visited[i] = false;
	dfs2(N, 0);

	int b = 0;
	for (int i = 1; i <= N; i++) {
		if (df[i] <= ds[i]) b++;
	}
	int w = N - b;

	if (b > w) printf("Fennec\n");
	else printf("Snuke\n");

	return 0;
}

Measured memory_bytes: 9728
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long int a,b,ans=0;
  cin>>a>>b;
  long long int k[a];
  for(int i=0;i<a;i++){
    cin>>k[i];
  }
  for(int i=0;i<a;i++){
    if(k[i]+b>=k[i+1]) ans+=b-(k[i]+b-k[i+1]);
    else ans+=b;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
const int MOD = (int)1e9 + 7;
const double PI = 3.14159265358979323846;
typedef long long ll;

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

Measured memory_bytes: 3624
#include <iostream>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<queue>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
typedef pair<int,int> pint;
typedef long long ll;
typedef pair<ll,ll> pll;
const int inf   = 510101010;
const ll longinf=1LL<<60;


int main(){
  string s;
  cin>>s;
  if(s[0]==s[2])cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
  return 0;
  }


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define dbug(x) cout<<#x<<"="<<x<<endl
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while ('0'>ch||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do {(t*=10)+=ch-'0';ch=getchar();} while ('0'<=ch&&ch<='9'); t*=f;
}
const int maxn=(1e5)+10;
int n,a,cnt;
int main() {
	//freopen("1.txt","r",stdin);
	read(n);
	for (int i=1;i<=n;i++) {
		read(a); if (a&1) cnt++;
	}
	if (cnt&1) printf("NO\n");
	else printf("YES\n");
	return 0;
}

Measured memory_bytes: 256
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
//#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <iterator>
#include <functional>
#include <limits>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <stack>
using namespace std;
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define trace(x) cerr << #x << ": " << x << " " << endl;
 
typedef int64_t ll;
 
#define endl '\n'
#define int ll
ll mod=1e9+7;
ll mod1=1e9+5;
ll power(ll a,ll b)
{
    if(b==0) return 1;
    else if(b%2==0)
        return power(((((a)%mod)*((a)%mod))%mod),b/2)%mod;
    else return (((a)%mod)*(power(((((a)%mod)*((a)%mod))%mod),b/2)%mod))%mod;
}
inline ll inverse(ll a,ll md) {
  a %= md;
  if (a < 0) a += md;
  ll b = md, u = 0, v = 1;
  while (a) {
    ll t = b / a;
    b -= t * a; swap(a, b);
    u -= t * v; swap(u, v);
  }
  assert(b == 1);
  if (u < 0) u += md;
  return u;
}
  
  
 //using namespace __gnu_pbds;
 //#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
//find_by_order(k)  returns iterator to kth element starting from 0;
//order_of_key(k) returns count of elements strictly smaller than k;
//erase,insert same as normal set
//mt19937 mrand(chrono::high_resolution_clock::now().time_since_epoch().count()); //for randomized solution
const int ce=1e9+7;
ll fast_mod(ll input)
{
    return input < ce ? input : input%ce;
}

int32_t main()
{
    IOS
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    #endif    
    
    int h,w;
    cin>>h>>w;
    int m;
    cin>>m;
    pair<int,int> a[h+1];
    for(int i=1;i<=h;i++)
    {
        a[i].first=0;
        a[i].second=i;
    }
    pair<int,int> b[w+1];
    for(int i=1;i<=w;i++)
    {
        b[i].first=0;
        b[i].second=i;
    }

    map<pair<int,int>,int> m1;
    while(m--)
    {
        int x,y;
        cin>>x>>y;
        m1[{x,y}]++;
        a[x].first++;
        b[y].first++;
    }
    sort(a+1,a+h+1,greater<pair<int,int>>());
    sort(b+1,b+w+1,greater<pair<int,int>>());
    int ans=a[1].first+b[1].first-m1[{a[1].second,b[1].second}];
    if(m1[{a[1].second,b[1].second}]==0)
    {
        cout<<ans;
        return 0;
    }
    int te=ans;
    for(int i=1;i<=h;i++)
    {
        if(a[i].first!=a[1].first)
            break;
        if(te>ans)
            break;
        for(int j=1;j<=w;j++)
        {
            if(b[j].first!=b[1].first)
                break;
            if(m1[{a[i].second,b[j].second}]==0)
            {
                //cout<<a[i].second<<" "<<b[j].second<<endl;
                te=ans+1;
                break;
            }
        }
    }
    cout<<te;
    
}    
 

Measured memory_bytes: 31760
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <random>

#define int long long
#define pb push_back
#define ff first
#define ss second
#define ld long double
#define rsz resize
#define ass assign

using namespace std;

mt19937 gen(time(nullptr));

const int INF = 1e6;

int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> a(n), b(INF), c(INF);
    vector<pair<int, int>> bs, cs;
    vector<bool> fl(INF);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (i % 2 == 0) {
            b[a[i]]++;
        } else c[a[i]]++;
    }
    for (int i = 0; i < INF; i++) {
        if (b[i] == 0 || c[i] == 0) continue;
        fl[i] = true;
        bs.pb({b[i], i});
        cs.pb({c[i], i});
    }
    sort(bs.begin(), bs.end());
    sort(cs.begin(), cs.end());
    reverse(bs.begin(), bs.end());
    reverse(cs.begin(), cs.end());
    int mx1 = 0, mx2 = 0;
    if (bs.size() == 0 && cs.size() != 0) {
        mx2 = cs[0].ff;
    }
    if (bs.size() > 0 && cs.size() == 0) {
        mx1 = bs[0].ff;
    }
    if (cs.size() > 0 && bs.size() > 0 && bs[0].ss != cs[0].ss) {
        mx1 = bs[0].ff;
        mx2 = cs[0].ff;
    }
    for (int i = 0; i < INF; i++) {
        if (fl[i]) continue;
        mx1 = max(mx1, b[i]);
        mx2 = max(mx2, c[i]);
    }
    int ans = n - mx1 - mx2;
    if (cs.size() > 0 && bs.size() > 0 && cs[0].ss == bs[0].ss) {
        ans = min(ans, min(n - max(mx1, bs[0].ff) - max(mx2, (cs.size() == 1 ? mx2 : cs[1].ff)),
            n - max(mx1, (bs.size() == 1 ? mx1 : bs[1].ff)) - max(mx2, cs[0].ff)));
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 18548
import copy
H,W,n_black = map(int,input().split())
grid = [list(input()) for _ in range(H)]
for y in range(H):
    for x in range(W):
        if grid[y][x] == "#":
            grid[y][x] = 1
        else:
            grid[y][x] = 0
num_pat = 2**(H+W)
ans = 0
for i in range(num_pat):
    now_grid = copy.deepcopy(grid)
    for j in range(H+W):    
        if i>>j & 1:
            if j < H:
                for x in range(W):
                    now_grid[j][x] = 0
            else:
                j -= H
                for y in range(H):
                    now_grid[y][j] = 0
    black = 0
    for y in range(H):
        black += sum(now_grid[y])
    if black == n_black:
        ans += 1
print(ans)


    
    


Measured memory_bytes: 9292
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <queue>
using namespace std;
 
int N;
int M[100001];
priority_queue<int,vector<int>,greater<int>> F;
priority_queue<int> B;
long long Sf[100001];
long long Sb[100001];
long long ans;
 
int main() {
    cin >> N;
    for (int i=0;i<N;i++){
        int a;
        cin >> a;
        F.push(a);
        Sf[0] += a;
    }
    for (int i=0;i<N;i++){
        int a;
        cin >> a;
        M[i] = a;
    }
    for (int i=0;i<N;i++){
        int a;
        cin >> a;
        B.push(a);
        Sb[N] += a;
    }
    for (int k=1;k<=N;k++){
        F.push(M[k-1]);
        Sf[k] = Sf[k-1] - F.top() + M[k-1];
        F.pop();
    }
    for (int k=1;k<=N;k++){
        B.push(M[N-k]);
        Sb[N-k] = Sb[N+1-k] - B.top() + M[N-k];
        B.pop();
    }
    ans = Sf[0] - Sb[0];
    for (int i = 1;i<=N;i++){
        if ( ans < Sf[i] - Sb[i]){
            ans = Sf[i] - Sb[i];
        }
    }
    cout << ans << endl;

}


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int K,i,a,MOD=1e9+7;
long x=1,ans=0;
vector<long> fact_inv,inv,Com;
void init_nCk(int n,int k){
  fact_inv.resize(k+1);
  inv.resize(k+1);
  fact_inv[0]=fact_inv[1]=inv[1]=1;
  for(int i=2;i<=k;i++){
    inv[i]=MOD-inv[MOD%i]*(MOD/i)%MOD;
    fact_inv[i]=fact_inv[i-1]*inv[i]%MOD;
  }
  Com.resize(k+1);
  Com[0]=1;
  for(int i=1;i<=k;i++){
    Com[i]=Com[i-1]*((n-i+1)*inv[i]%MOD)%MOD;
  }
}
int nCk(int k){
  return Com[k];
}
int main(){
  string S;
  cin>>K>>S;
  a=K+S.size();
  init_nCk(a,K);
  for(i=0;i<=K;++i){
    ans+=x*nCk(i);
    ans%=MOD;
    x=x*25%MOD;
  }
  cout<<ans<<endl;
}

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

int main(){
  int n;
  cin>>n;
  vector<int> A(n);
  for(int i=0; i<n; i++){
    cin>>A.at(i);
  }
  ll ans=0;
  ll x=0;
  for(int i=0; i<n; i++){
    ans=(ans+A.at(i)*x)%1000000007;
    x=(x+A.at(i))%1000000007;
  }
  cout<<ans<<endl;
}

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

#define nalp 26

using namespace std;


char alp[nalp] = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l',
                'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'};

// アルファベット->数値
int alp2num(char c) {
    for(int i = 0; i < nalp; i++)
    {
        if(c == alp[i]) {
            return i;
        }
    }
    return 0;
}

// x < yで渡さないと死
int dist(char x, char y) {
    int ix = alp2num(x);
    int iy = alp2num(y);
    return iy-ix;
}

int main() {
    string str = "";
    int K = 0;
    cin >> str;
    cin >> K;

    // できるだけ'a'にする
    for(int i = 0; i < str.size(); i++) {
        char tmp = str[i];

        if(tmp == 'a') continue;

        // str[i]を'a'にできるなら操作
        if(dist(tmp, 'z') < K) {
            str[i] = 'a';
            K -= (dist(tmp, 'z') + 1);
        }
    }

    // 一番下位の文字から操作
    for(int i = str.size()-1; i >= 0; i--) {

        // 26回操作したことにする(a -> a)
        while(K >= nalp){
            K-=nalp;
        }
        if(K == 0) break; // 終わり

        char tmp = str[i];
        //printf("dist:%d, K:%d\n", dist(tmp, 'z'), K);

        // 'ｚ'にする
        if(dist(tmp, 'z') <= K) {
            K -= dist(tmp, 'z'); // zにするまでの距離
            str[i] = 'z';
        }
        else {
            int crnt = alp2num(tmp);
            str[i] = alp[K+crnt];
            K = 0;
        }
    }
    cout << str << endl;

    return 0;
}

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

int main()
{
    string s;
    cin >> s;
    int count = 0;
    s[0] == '1' ? count++ : 0;
    s[1] == '1' ? count++ : 0;
    s[2] == '1' ? count++ : 0;

    cout << count;
}

Measured memory_bytes: 256