akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<bits/stdc++.h>

using namespace std;

int res(int a){
	if(a == 1){
		return 300000;
	}
	else if(a == 2){
		return 200000;
	}
	else if(a == 3){
		return 100000;
	}
	return 0;
}
int main(){
	int a, b;
	cin >> a >> b;
	int sum= 0;
	if(a == b && a == 1){
		cout << 2 * res(a) + 400000 << "\n";
		return 0;
	}
	cout << res(a) + res(b) << "\n";
	return 0;
}

Measured memory_bytes: 256
a,b,q=gets.split.map(&:to_i)

s = a.times.map{gets.to_i}.sort
sr= s.reverse
t = b.times.map{gets.to_i}.sort
tr= t.reverse

q.times.each do
  x = gets.to_i

  s1 = s.bsearch{|y| x <= y}
  s2 = sr.bsearch{|y| x >= y}

  t1 = t.bsearch{|y| x <= y}
  t2 = tr.bsearch{|y| x >= y}

  puts ([s1, s2].select{|x|x}.map do |s|
    [t1, t2].select{|x|x}.map do |t|
      [[s-x, t-s], [t-x, s-t]].map{|a| a.map(&:abs).inject(&:+)}.min
    end.min
  end.min)
end


Measured memory_bytes: 9456
#include<stdio.h>
int main(){
  int n,i,j,d[2][100010]={};
  scanf("%d",&n);
  for(i=0;i<2;i++){
    for(j=0;j<n;j++)scanf("%d",&d[i][j]);
  }
  for(i=1;i<n;i++)d[0][  i  ]+=d[0][i-1];
  for(i=1;i<n;i++)d[1][n-i-1]+=d[1][n-i];
  //for(i=0;i<n;i++)printf("%2d %2d\n",d[0][i],d[1][i]);
  for(i=j=0;i<n;i++){
    if(j<d[0][i]+d[1][i])j=d[0][i]+d[1][i];
  }
  printf("%d\n",j);
  return 0;
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repr(i,n) for(int (i)=(n);(i)>0;(i)--)
#define rrep(i,n,m) for(int (i)=(n);(i)<(m);(i)++)
#define rrepr(i,n,m) for(int (i)=(n);(i)>(m);(i)--)
#define esort(s) sort((s).begin(),(s).end())

typedef long long ll;
typedef pair<int,int> ipair;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;

const int INF = 1000000000;
const ll LINF = 1000000000000000000;
const double PI = acos(-1.0);
const double EPS = 1e-10;

const ll MOD = 1000000007ll;
const int MAX=510000;

ll N;
void solve(){
    cin>>N;
    ll a,b;
    for(ll i=1; i<1000100; i++){
        if((i*i)>N) break;
        if(N%i==0){
            a=i; b=N/i;
            // cout<<a<<" "<<b<<"\n";
        }
    }
    cout<<a+b-2<<endl;
    return;
}

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

    solve();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S,T;
  cin >> S >> T;
  for (int i = 0; i < S.size(); i++){
    if (T.at(i) != S.at(i)){
      cout << "No";
      break;
    }
    else if (i == S.size() - 1){
      cout << "Yes";
      break;
    }
  }
}
    

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

using namespace std;

int main()
{
  int n, m; cin >> n >> m;
  vector<int> d(m);
  vector<int> dp(n + 1, INT_MAX);
  dp[0] = 0;
  dp[1] = 1;
  for(int i = 0; i < m; i++) cin >> d[i];
  for(int i = 2; i < n + 1; i++)
  {
    for(int j = 0; j < m; j++) if(i - d[j] > -1)
      dp[i] = min(dp[i], dp[i - d[j]]);
    dp[i]++;
  }
  cout << dp[n] << endl;

  return 0;
}


Measured memory_bytes: 3184
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using vs=vector<string>;
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(ll i=(a);i<(n);i++)
#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

int dx[]={1,0,-1,0,1,-1,-1,1},dy[]={0,1,0,-1,1,1,-1,-1};
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}
template<class S>void tf(bool b,S t,S f){cout<<(b?t:f)<<endl;}
void OUT(bool b){tf(b,"YES","NO");}
void Out(bool b){tf(b,"Yes","No");}
void out(bool b){tf(b,"yes","no");}
template<class T>void puta(T&&t){cout<<t<<endl;}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}

int popcnt(int x){return __builtin_popcount(x);}
int popcnt(ll x){return __builtin_popcountll(x);}
int bsr(int x){return 31 - __builtin_clz(x);}
int bsr(ll x){return 63 - __builtin_clzll(x);}
int bsf(int x){return __builtin_ctz(x);}
int bsf(ll x){return __builtin_ctzll(x);}
template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}

/*他のライブラリを入れる場所*/
struct segTree{
	vl val;
	int N;
	segTree(int n){
		N=1;
		while(N<n)N*=2;
		val.resize(N*2);
		fill(all(val),0);
	}
	void replace(int k, ll a){
		k+=N;
		val[k]=a;
		while(k){
			k/=2;
			val[k]=max(val[k*2],val[k*2+1]);
		}
	}
	ll maximum(int a, int b){return maximum(a,b,1,0,N);}
	ll maximum(int a, int b, int k, int l, int r){
		if(r<=a or l>=b) return -INF;
		if(a<=l and r<=b) return val[k];
		int m=(l+r)/2;
		return max(maximum(a,b,k*2,l,m),maximum(a,b,k*2+1,m,r));
	}	
};


int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	vl h(n),a(n);
	rep(i,n)cin>>h[i];
	rep(i,n)cin>>a[i];
	segTree st(n+1);
	vl dp(n+1,0);
	rep(i,n){
		dp[h[i]]=st.maximum(0,h[i])+a[i];
		st.replace(h[i],dp[h[i]]);
	}
	puta(*max_element(all(dp)));
	return 0;
}

Measured memory_bytes: 9088
#include <bits/stdc++.h>
#include<ext/pb_ds/hash_policy.hpp>
#include<ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;
typedef long long LL;
typedef unsigned long long uLL;
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }
    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
LL z = 1;
int read(){
	int x, f = 1;
	char ch;
	while(ch = getchar(), ch < '0' || ch > '9') if(ch == '-') f = -1;
	x = ch - '0';
	while(ch = getchar(), ch >= '0' && ch <= '9') x = x * 10 + ch - 48;
	return x * f;
}
int ksm(int a, int b, int p){
	int s = 1;
	while(b){
		if(b & 1) s = z * s * a % p;
		a = z * a * a % p;
		b >>= 1;
	}
	return s;
}
int main(){
	int i, j, n, m;
	n = read();
	if(n % 2) printf("%d", n * 2);
	else printf("%d", n);
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<math.h>
#include<iomanip>
#define rep(i, n) rep2(i,0,n)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define PI acos(-1);
typedef long long ll;
using namespace std;
#define MOD 1000000007
//scanf("%d", &a) '\n'

int main() {
	int n;
	cin >>n;
	string s;
	cin >> s;
	vector<string> v(1000);
	int ans = 0;
	rep(i, 1000) {
		vector<int> v = { i / 100,(i / 10) % 10,i % 10 };
		int f = 0;
		rep(j, n) {
			if (s[j] == ('0'+v[f])) f++;
			if (f == 3)break;
		}
		if (f == 3) ++ans;
	}
	cout << ans << endl;

}
	

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define all(n) begin(n), end(n)
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    int x,n;
    cin>>x>>n;
    vint p(n);
    set<int> s;
    for (size_t i = 0; i < n; i++)
    {
        cin>>p[i];
        s.insert(p[i]);
    }
    int dist = INT_MAX;
    for (int i = -1000; i < 1000; i++)
    {
        if(s.count(i)==0)
        chmin(dist,abs(x-i));
    }
    for (int i = -1000; i < 1000; i++)
    {
        if(s.count(i)==0 and abs(x-i) == dist)
        {
            cout<<i<<endl;
            return 0;
        }
    }
    
    return 0;
}

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

#define ll long long
#define pb push_back
#define mk make_pair
#define fr first
#define sc second
#define vi vector < int >
#define pi pair < int, int >

const int N = 1e5 + 7;
const int INF = 1e9 + 7;

ll n;

main(){
    cin >> n;
    cout << n * (n - 1) / 2;
}


Measured memory_bytes: 256
N = int(input())
M = 10 ** 2

L = [0] * (N + 1)
for i in range(1, M + 1):
  for j in range(1, M + 1):
    for k in range(1, M + 1):
      t = (i + j + k) ** 2 - i * j - j * k - k * i
      if t <= N:
        L[t] +=1

for i in range(1, N + 1):
  print(L[i])



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

#define ll long long
#define endl '\n'
#ifndef _WINDOWS
// no getchar_unlocked on Windows so just call getchar
#define getchar getchar_unlocked
#endif

template <typename Func>
inline void loop(int e, Func&& f) {
    for (int i = 0; i < e; i++) {
        std::forward<Func>(f)(i);
    }
}
template <typename Func>
inline void loop(int s, int e, Func&& f) {
    for (int i = s; i < e; i++) {
        std::forward<Func>(f)(i);
    }
}
template <typename T>
inline void scanpn(T& num) {
    int c;
    num = 0;
    c = getchar();
    // bool negative = false;
    // if (c == '-') {
    // 	negative = true;
    // 	c = getchar();
    // }
    for (; (c > 47 && c < 58); c = getchar()) num = num * 10 + c - 48;
    // if (negative)
    //     number = -number;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    string s;
    cin >> s;
    unordered_map<char, set<int>> mapping{{'R', set<int>{}}, {'G', set<int>{}}, {'B', set<int>{}}};
    for (int i = 0; i < n; i++) mapping[s[i]].insert(i);
    ll ans = mapping['R'].size() * mapping['G'].size() * mapping['B'].size();
    if (ans == 0) {
        cout << ans << endl;
        return 0;
    }
    int max_inv = (n & 1) ? n / 2 : n / 2 - 1;
    for (int inv = 1; inv <= max_inv; inv++) {
        for (int i = 0; i < n - 2 * inv; i++) {
            int a = i, b = i + inv, c = i + inv + inv;
            int r1 = (mapping['R'].count(a) + mapping['R'].count(b) + mapping['R'].count(c));
            int r2 = mapping['G'].count(a) + mapping['G'].count(b) + mapping['G'].count(c);
            int r3 = mapping['B'].count(a) + mapping['B'].count(b) + mapping['B'].count(c);
            // cout << !r1 << ' ' << !r2 << ' ' << !r3 << endl;
            if (r1 && r2 && r3) {
                ans--;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3804
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

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

    if(abs(x-a) > abs(x-b)) cout << "B" << endl;
    else cout << "A" << endl;
}

Measured memory_bytes: 256
import bisect
A, B, Q = map(int,input().split())
INF = 10**13

s = [int(input()) for _ in range(A)]
t = [int(input()) for _ in range(B)]

def get(x, s, t, ans_list):
  l_s = bisect.bisect_left(s, x)-1
  r_s = bisect.bisect_left(s, x)-1 + 1
  if l_s >= 0:
    y = s[l_s]
    l_t = bisect.bisect_left(t, y)-1
    r_t = bisect.bisect_left(t, y)-1 + 1
    if l_t >= 0:
      ans_list.append(abs(x-y) + abs(y-t[l_t]))
    if r_t <= len(t)-1:
      ans_list.append(abs(x-y) + abs(y-t[r_t]))
  if r_s <= len(s)-1:
    y = s[r_s]
    l_t = bisect.bisect_left(t, y)-1
    r_t = bisect.bisect_left(t, y)-1 + 1
    if l_t >= 0:
      ans_list.append(abs(x-y) + abs(y-t[l_t]))
    if r_t <= len(t)-1:
      ans_list.append(abs(x-y) + abs(y-t[r_t]))
  
  
for _ in range(Q):
  ans_list = []
  x = int(input())
  get(x, s, t, ans_list)
  get(x, t, s, ans_list)
  #print(x, ans_list)
  print(min(ans_list))


Measured memory_bytes: 88160
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		new Main().run();
	}
	private void run() throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		while (true) {
			StringTokenizer st = new StringTokenizer(reader.readLine());
			int n = Integer.parseInt(st.nextToken());
			int s = Integer.parseInt(st.nextToken());
			if (n == 0 && s == 0) {
				break;
			}
			int[] a = new int[n];
			for (int i = 0; i < n; i++) {
				a[i] = i+1;
			}
			System.out.println(subsetSum(n, a, s));
		}
		reader.close();
	}
	
	private int subsetSum(int n, int[] a, int s) {
		int count = 0;
		for (int i = 0; i < n; i++) {
			int r = s - a[i];
			int j = i + 1;
			int k = n - 1;
			while (j < k) {
				int tmp = a[j] + a[k];
				if (tmp < r) {
					j++;
				} else if (tmp > r) {
					k--;
				} else {
					count++;
					j++;
					k--;
				}
			}
		}
		return count;
	}
}




Measured memory_bytes: 24312
// WARNING: Add compile option "-std=c++11" for C++11 compile.

#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <regex>
#include <numeric>
using namespace std;

// Macro
#define rep(i, N) for(int i=0; i<(int)N; i++)
#define erep(i, N) for(int i=0; i<=(int)N; i++)
#define mp make_pair
#define pb push_back

// Type
typedef long long ll;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;

// Constants
const int MOD = (int)1e9 + 7;
int dy[] = {0, 1, -1, 0};
int dx[] = {1, 0, 0, -1};

/**
  型に合わせたINFを返す
  int: 214,748,364 (2.14 * 1e8)
  ll : 922,337,203,685,477,580 (9.22 * 1e17)
*/
template <typename T>
T getINF() {
  // NOTE: INF同士を足してもオーバーフロー起こさないように、10で割っている
  return numeric_limits<T>::max() / 10;
}

// Floating
const double EPS = 1e-11;
#define EQ0(x) (abs(x) < EPS)
#define EQ(x, y) (abs(a-b) < EPS)

struct Info {
  int id;
  string s;
  int p;

  Info(int id, string s, int p) :  id(id), s(s), p(p) {}

  bool operator<(const Info &another) const
    {
        if(s == another.s) {
          return p > another.p;
        }
        return s < another.s;
    };
};

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

  vector<Info> v;
  rep(i, n) {
    string s;
    int p;
    cin >> s >> p;
    v.pb(Info(i+1, s, p));
  }

  sort(v.begin(), v.end());

  rep(i, n) {
    // cout << v[i].id << ", " << v[i].s << ", " << v[i].p << endl;
    cout << v[i].id << endl;
  }

  return 0;
}

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

const int mxN = 1e5 + 5;
int N, M;
ll dp[mxN];
vector<int> adj[mxN];

ll rec(int u) {
	if (dp[u] != -1) {
		return dp[u];
	}
	ll ret = 0;
	for (int v : adj[u]) {
		ret = max(ret, 1 + rec(v));
	}
	return dp[u] = ret;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	cin >> N >> M;
	int x, y;
	for (int i = 1; i <= M; i++) {
		cin >> x >> y;
		x--;
		y--;
		adj[x].push_back(y);
	}
	ll ans = 0;
	memset(dp, -1, sizeof(dp));
	for (int i = 0; i < N; i++) {
		ans = max(ans, rec(i));
	}
	cout << ans;
	
	return 0;
}


Measured memory_bytes: 11844
#include <iostream>
#include <list>
#include <iterator>
#include <deque>

int main()
{
  int n;
  scanf("%d", &n);
  std::list<int> list;
  for (int i = 0; i < n; ++i)
  {
    int a;
    scanf("%d", &a);
    list.emplace_back(a);
  }
  std::deque<int> dq;
  while (list.size() > 0)
  {
    bool found = false;
    for (int i = list.size() - 1; i >= 0; --i)
    {
      if (*std::next(list.begin(), i) == i + 1)
      {
        list.erase(std::next(list.begin(), i));
        found = true;
        dq.emplace_front(i + 1);
        break;
      }
    }
    if (!found)
    {
      puts("-1");
      return 0;
    }
  }
  for (auto i : dq)
  {
    printf("%d\n", i);
  }
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long lli;
const int MAX_N = 65010;

int N;
lli P[MAX_N],J[MAX_N];
lli SJ[MAX_N];

void input(){
  for(int i = 0 ; i < N ; i++)cin >> P[i];
  for(int i = 0 ; i < N-1 ; i++)cin >> J[i];
}

void solve(){
  input();
  lli S = 0;
  for(int i = 0 ; i < N ; i++){
    S += P[i];
  }
  sort(J, J+N-1, greater<lli>());
  SJ[0] = 0;
  for(int i = 0; i < N-1; ++i) {
    SJ[i+1] = SJ[i] + J[i];
  }
  lli res = 0;
  for(int n = 1; n <= N; ++n) {
    int need = N-n;
    res = max(res, n * (S + SJ[need]));
  }
  cout << res << endl;
}

int main(){
  while(cin >> N,N){
    solve();
  }
  return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<ll> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    vector<ll> sum(n + 1);
    for (int i = 1; i <= n; ++i) {
        sum[i] = sum[i - 1] + a[i - 1];
    }
    map<ll, ll> mp;
    for (ll i : sum) mp[i]++;
    ll ans = 0;
    for (auto i : mp) if (i.second >= 2) ans += i.second * (i.second - 1) / 2;
    cout << ans << endl;
}


Measured memory_bytes: 15872
from collections import Counter
n = int(input())
v = list(map(int, input().split()))
l,r = Counter(v[0::2]).most_common(), Counter(v[1::2]).most_common()
l.append((0,0))
r.append((0,0))
if l[0][0] != r[0][0]:
  print(n-(l[0][1]+r[0][1]))
else:
  print(min(n-(l[1][1]+r[0][1]), n-(l[0][1]+r[1][1])))

Measured memory_bytes: 25180
import sys
from collections import deque
input = lambda: sys.stdin.readline().rstrip()


def solve():
    N = int(input())
    A = [deque for _ in range(N)]
    for i in range(N):
        A[i] = deque(list(map(lambda x: int(x) - 1, input().split())))

    days = 0
    ta = [i for i in range(N)]
    while True:
        ta2 = []
        aset = set()
        for i in ta:
            if len(A[i]) == 0 or i in aset:
                continue
            if i == A[A[i][0]][0]:
                ta2.append(i)
                ta2.append(A[i][0])
                aset |= set([i])
                aset |= set([A[i][0]])
        if len(ta2) > 0:
            for t in ta2:
                A[t].popleft()
            days += 1
            ta = ta2
        else:
            break

    empty = True
    for i in range(N):
        if len(A[i]) != 0:
            empty = False
            break

    if empty:
        print(days)
    else:
        print(-1)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 38056
#include<bits/stdc++.h>
#define fo(i,a,b) for((i)=(a);i<=(b);i++)
#define rfo(i,a,b) for((i)=(a);i>=(b);i--)
#define inrange(x,y,z) (((x)>=(y))&&((x)<=(z)))
#define ALL(vec) ((vec).begin(),(vec).end())
#define SOR(vec) sort(ALL(vec))
#define UNI(vec) (vec).erase(unique(ALL(vec)),(vec).end())
using namespace std;
typedef unsigned long long ull;
int n;
ull a[100100],x,bl;
ull umi(ull a,ull b){
	return (a<b)?a:b;
}
ull uma(ull a,ull b){
	return (a>b)?a:b;
}
int main(){
	#ifdef FILIN
		#ifndef LOCAL
			freopen(FILIN,"r",stdin);
			freopen(FILOUT,"w",stdout);
		#endif
	#endif
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		x^=a[i];
	}
	for(int i=0;i<n;i++)
		a[i]&=(~x);
	int rk=0,pos;
	for(int i=59;i>=0;i--){
		pos=-1;
		for(int j=rk;j<n;j++){if((a[j]>>i)&1){pos=j;break;}}
		if(pos==-1) continue;
		if(pos>rk) a[rk]^=a[pos];
		for(int j=rk+1;j<n;j++)
			a[j]=umi(a[j],a[j]^a[rk]);
		rk++;
	}
	for(int i=0;i<n;i++)
		bl=uma(bl,bl^a[i]);
	cout<<bl*2+x<<endl;
	return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<vector>

int main(){
    
    std::string w;
    std::vector<size_t> cnt('z' - 'a' + 1);

    std::cin >> w;

    for(const auto& e : w){
        cnt.at(e - 'a')++;
    }

    for(const auto& e : cnt){
        if(e % 2 != 0){
            std::cout << "No" << std::endl;
            return 0;
        }
    }

    std::cout << "Yes" << std::endl;
    
    return 0;
}


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


Measured memory_bytes: 60564
#include<bits/stdc++.h>
using namespace std;
#define P pair<int,int>


char s[100][100];

bool num(int i,int j){
  return ('0'<=s[i][j]&&s[i][j]<='9');
}



bool g(string a,string b){
  if(a.size()!=b.size()) return (a.size()<b.size());
  int i=0;
  while(a.size()!=i){
    if(a[i]!=b[i]) return (a[i]<b[i]);
    i++;
  }
  return true;
}



void f(int w,int h){
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      s[i][j]=0; 
    }
  }
  vector<vector<string>> dp(h,vector<string>(w));

  for(int i=0;i<h;i++){
    cin>>s[i];
  }

  string ans="";

  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(!num(i,j))continue;
      if(i==0&&j==0&&s[i][j]!='0') dp[i][j]=s[i][j];
      else if(i==0&&j>0&&!(dp[i][j-1]==""&&s[i][j]=='0')) dp[i][j]=dp[i][j-1]+s[i][j];
      else if(j==0&&i>0&&!(dp[i-1][j]==""&&s[i][j]=='0')) dp[i][j]=dp[i-1][j]+s[i][j];
      else if(i>0&&j>0){
        if(g(dp[i-1][j],dp[i][j-1])&&!(dp[i][j-1]==""&&s[i][j]=='0'))
          dp[i][j]=dp[i][j-1]+s[i][j];
        else if(!(dp[i-1][j]==""&&s[i][j]=='0'))
          dp[i][j]=dp[i-1][j]+s[i][j];
      }
      if(g(ans,dp[i][j]))
        ans=dp[i][j];
    }
  }


  cout<<ans<<endl;
}



int main(){
  int w,h;
  while(true){
    cin>>w>>h;
    if(w==0) break;
    f(w,h);
  }
}



Measured memory_bytes: 3272
#[allow(unused_macros)]
macro_rules ! read_value {($ next : expr , ($ ($ t : tt ) ,* ) ) => {($ (read_value ! ($ next , $ t ) ) ,* ) } ; ($ next : expr , [$ t : tt ; $ len : expr ] ) => {(0 ..$ len ) . map (| _ | read_value ! ($ next , $ t ) ) . collect ::< Vec < _ >> () } ; ($ next : expr , chars ) => {read_value ! ($ next , String ) . chars () . collect ::< Vec < char >> () } ; ($ next : expr , usize1 ) => {read_value ! ($ next , usize ) - 1 } ; ($ next : expr , $ t : ty ) => {$ next () . parse ::<$ t > () . expect ("Parse error" ) } ; }
#[allow(unused_macros)]
macro_rules ! input_inner {($ next : expr ) => {} ; ($ next : expr , ) => {} ; ($ next : expr , $ var : ident : $ t : tt $ ($ r : tt ) * ) => {let $ var = read_value ! ($ next , $ t ) ; input_inner ! {$ next $ ($ r ) * } } ; }
#[allow(unused_macros)]
macro_rules ! input {(source = $ s : expr , $ ($ r : tt ) * ) => {let mut iter = $ s . split_whitespace () ; let mut next = || {iter . next () . unwrap () } ; input_inner ! {next , $ ($ r ) * } } ; ($ ($ r : tt ) * ) => {let stdin = std :: io :: stdin () ; let mut bytes = std :: io :: Read :: bytes (std :: io :: BufReader :: new (stdin . lock () ) ) ; let mut next = move || -> String {bytes . by_ref () . map (| r | r . unwrap () as char ) . skip_while (| c | c . is_whitespace () ) . take_while (| c |! c . is_whitespace () ) . collect () } ; input_inner ! {next , $ ($ r ) * } } ; }

fn main() {
    input! {
        a: String,
        b: String,
    }
    if a == b.chars().rev().collect::<String>() {
        println!("YES");
    } else {
        println!("NO");
    }
}


Measured memory_bytes: 2148
// Author: HarshKumar

#include <bits/stdc++.h>
using namespace std;
#define ll int64_t
const ll N = 1e6 + 6, M = 1e9 + 7;
int main()
{
    ios::sync_with_stdio(false), cin.tie(nullptr);
    double l;
    cin >> l;
    cout << setprecision(20) << l * l * l / 27.0;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<math.h>
#include<string.h>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<deque>
using namespace std;

int main(){
	int a,b,c;
	cin >> a >> b >> c;
	vector<int> m(1000,0);
	for(int i=1;;i++){
		m[i]=a*i%b;
		if(i>0){
			if(m[i]==m[0])break;
		}
	}
	for(int i=0;i<m.size();i++){
		if(m[i]==c){
			cout << "YES" << endl;
			return 0;
		}
	}
	cout << "NO" << endl;
	return 0;
}


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

double g[1002][1002];

int main() {
    int xs, ys, xt, yt;
    cin >> xs >> ys >> xt >> yt;
    int n;
    cin >> n;
    vector<int> x(n + 2), y(n + 2), r(n + 2);
    for (int i = 0; i < n; i++) {
        cin >> x[i] >> y[i] >> r[i];
    }
    x[n] = xs;
    y[n] = ys;
    r[n] = 0;
    x[n + 1] = xt;
    y[n + 1] = yt;
    r[n + 1] = 0;
    n += 2;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            g[i][j] = max(0.0, hypot(x[j] - x[i], y[j] - y[i]) - (r[i] + r[j]));
        }
    }
    for (int k = 0; k < n; k++) {
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < n; j++) {
                g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
            }
        }
    }
    printf("%.20f\n", g[n - 2][n - 1]);
}


Measured memory_bytes: 8064
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;
long long int di[] = {-1, 0, 1, 0, -1, 1, 1, -1};
long long int dj[] = {0, 1, 0, -1, 1, 1, -1, -1};

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

int main() {
  
  int n; cin >> n;
  vector<string> s(n);
  vector<int> t(n);
  for(int i = 0; i < n; i++) cin >> s[i] >> t[i];
  string x; cin >> x;
  int ans = 0;
  int mode = 0;
  for(int i = 0; i < n; i++) {
    if(mode) ans += t[i];
    if(s[i] == x) mode = 1;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int n;
int cnt;

int get_digit(int n){
    int digit = 0;
    while(n != 0){
        n /= 10;
        digit++;
    }
    return digit;
}

bool check_753(string s){
    bool three_flag = false;
    bool five_flag = false;
    bool seven_flag = false;
    for(int i = 0; i < s.size(); i++){
        if(s[i] == '7')seven_flag = true;
        if(s[i] == '5')five_flag = true;
        if(s[i] == '3')three_flag = true;
    }
    if(seven_flag && five_flag && three_flag)return true;
    else return false;
}

void dfs(int depth, string str, int digit){
    if(depth >= 3){
        if(stoi(str) <= n && check_753(str)){
            cnt++;
        }
    }
    
    if(depth == digit){
        return;
    }

    for(int i = 0; i < 3; i++){
        if(i == 0)dfs(depth + 1, str + '7', digit);
        if(i == 1)dfs(depth + 1, str + '5', digit);
        if(i == 2)dfs(depth + 1, str + '3', digit);
    }
}

int main(){
    cin >> n;
    int digit = get_digit(n);
    dfs(0, "", digit);
    cout << cnt << endl;
}

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

adj = [None]
for i in range(n):
    adj_i = list(map(int, input().split()[2:]))
    adj.append(adj_i)

# searched or not, number of vertex, discovery time and finishing time.
sndf = [None]
for i in range(1, n + 1):
    sndf.append([False, i])

path = []

time = 0

def dfs(u):
    global time
    sndf[u][0] = True
    time += 1
    sndf[u].append(time)

    for v in adj[u]:
        if not sndf[v][0]:
            dfs(v)
    time += 1
    sndf[u].append(time)


for i in range(1, n + 1):
    if not sndf[i][0]:
        dfs(i)

for x in sndf[1:]:
    print(*x[1:])

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


int main (){
    int N;
    cin >> N;
    long int ans=0;
    for(int i=1;i<=N;i++){
        if(i%3!=0 && i%5!=0){
            ans+=i;
        }
    }
    cout << ans <<endl;
}


Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <cmath>


typedef long long ll;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define _GLIBCXX_DEBAC
/*map<Keyの型, Valueの型> 変数名;
queue<型> 変数名;
priority_queue<型> 変数名;
priority_queue<型, vector<型>, greater<型>> 変数名;*/
//copy(v1.begin(), v1.end(), back_inserter(v2));
using namespace std;

int gcd(int a, int b) {
	int c;
	if (a < b) {
		c = a; a = b; b = c;
	}
	while (b != 0) {
		c = a % b; a = b; b = c;
	}
	return a;
}

int sort_greater(int m,int n) {
	vector<int> a(m);
	for (int i = 0; i < m; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end(),greater<int>());
	for (int i = 0; i < n; i++) {
		cout << a[i];
	}
		return 0;
}

int bubblesort(int a[], int n) {
	int sw = 0;
	bool flag = 1;
	for (int i = 0; flag; i++) {
		flag = 0;
		for (int j = n - 1; j >= i + 1; j--) {
			if (a[j] < a[j - 1]) {
				swap(a[j], a[j - 1]);
				flag = 1;
				sw += 1;
			}
		}
	}
	return sw;
}

int a_z()
{
	for (int i = 0; i <= ('Z' - 'A'); i++) {
		cout << (char)('A' + i);
	}
	return 0;
}

int selecttionsort(int a[], int n) {
	int t,sw = 0, minj;
	for (int i = 0; i < n - 1; i++) {
		minj = i;
		for (int j = 0; j < n - 1; j++) {
			if (a[j] < a[minj]) {
				minj = j;
			}
		}
		t = a[i]; a[i] = a[minj]; a[minj] = t;
		if (i != minj) sw += 1;

	}
	return sw;
}

map<string, int> memo;


int main() {
	//sort(a.begin(),a.end());
	ll A, B, K;
	cin >> A >> B >> K;
	if (K <= A) cout << A - K << " " << B;
	else if (K <= A + B) cout << 0 << " " << A+B-K;
	else cout << 0 << " " << 0;
	return 0;
}









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

int main(){
    int n,k;
    cin>>n>>k;
    vector<int> d(n);
    vector<vector<int>> a(k,vector<int>(n));
    vector<bool> ch(n,false);
    int count=0;
    for(int i=0;i<n;i++){
        cin>>d[i];
        for(int j=0;j<d[i];j++){
            cin>>a.at(i).at(j);
            ch[a.at(i).at(j)-1]=true;
        }
    }
    for(int i=0;i<n;i++){
        if(ch[i]==false){
            count++;
        }
    }
    cout<<count<<endl;

}

Measured memory_bytes: 3640
#include <iostream>
#define llint long long

using namespace std;

llint h, w, n;

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> h >> w >> n;
	cout << (n+max(h, w)-1) / max(h, w) << endl;
	
	return 0;
}

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

const double pi = acos(-1.0);

signed main(void){

  double a,b,h,m; cin >> a >> b >> h >> m;
  
  double theta = h+((double)m/60.0);
  
  theta *= ((double)11.0/6.0);
  
  theta *= pi;
  
  int res =  floor(theta/(2.0*pi));
  
  theta -= 2.0*res*pi;
  
  if(false){ 
  printf("%.10f\n", 180*theta/pi);
  }
  
  double ans = sqrt(a*a+b*b-2.0*a*b*cos(theta));
  
  printf("%.20f\n", ans);
  
  return 0;
}


Measured memory_bytes: 4284
#include<bits/stdc++.h>
using namespace std;
set<int>s;
int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t,i,j,n,m,l=1,r;
    cin>>n;
    while(1)
    {
        if(s.find(n)!=s.end())
        {
            break;
        }
        s.insert(n);
        if(n%2==0)
        {
            n/=2;
        }
        else
        {
            n=3*n+1;
        }
        l++;
    }
    cout<<l<<"\n";
    return 0;
}

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

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

  vector<int> d(N);
  for(int i = 0;i < N;i++) {
    cin >> d.at(i);
  }

  int sum = 0;
  for(int i = 0;i < N-1;i++) {
    for(int j = i+1;j < N;j++) {
      sum += d.at(i) * d.at(j);
    }
  }

  cout << sum << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<n; ++i)
#define rep1(i, n) for (int i=1; i<=n; ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;

int main() {
    int n; cin >> n;
    vector<int> d(n);
    rep(i, n) cin >> d[i];
    int sum = 0;
    rep(i, n) {
        for (int j=i+1; j<n; ++j) {
            sum += d[i] * d[j];
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
from array import array


class SegmentTree(object):
    MAXV = 1000 * 10**5 + 1

    def __init__(self, n: int) -> None:
        size = 1
        while (size < n):
            size *= 2
        self.size = 2 * size - 1
        self.data = array('i', [0] * self.size)
        self.lazy = array('i', [0] * self.size)

    def add(self, l: int, h: int, v: int) -> None:
        def _add(r, i: int, j: int, lz: int) -> int:
            left, right = r * 2 + 1, r * 2 + 2
            if lazy[r]:
                lz += lazy[r]
                lazy[r] = 0

            if (l <= i and j <= h):  # noqa: E741
                lz += v
                if lz:
                    data[r] += lz
                    if (i < j):
                        lazy[left] += lz
                        lazy[right] += lz
            else:
                mid = (i + j) // 2
                if (mid >= l):
                    lv = _add(left, i, mid, lz)
                else:
                    lazy[left] += lz
                    lv = data[left] + lazy[left]

                if (mid < h):
                    rv = _add(right, mid + 1, j, lz)
                else:
                    lazy[right] += lz
                    rv = data[right] + lazy[right]

                if (lv < rv):
                    data[r] = lv
                else:
                    data[r] = rv

            return data[r]

        lazy = self.lazy
        data = self.data
        _add(0, 0, self.size // 2, 0)

    def min(self, l: int, h: int) -> int:
        def _min(r, i: int, j: int, lz: int) -> int:
            left, right = r * 2 + 1, r * 2 + 2
            if lazy[r]:
                lz += lazy[r]
                lazy[r] = 0
            if lz:
                data[r] += lz

            if (l <= i and j <= h):  # noqa: E741
                if lz and i < j:
                    lazy[left] += lz
                    lazy[right] += lz
                return data[r]
            else:
                mid = (i + j) // 2
                if (mid >= l):
                    lv = _min(left, i, mid, lz)
                else:
                    lazy[left] += lz
                    lv = self.MAXV

                if (mid < h):
                    rv = _min(right, mid + 1, j, lz)
                else:
                    lazy[right] += lz
                    rv = self.MAXV

                if (lv < rv):
                    return lv
                else:
                    return rv

        lazy = self.lazy
        data = self.data
        return _min(0, 0, self.size // 2, 0)


if __name__ == "__main__":
    n, q = map(lambda x: int(x), input().split())
    segtree = SegmentTree(n)

    ans = []
    for _ in range(q):
        com, *v = map(lambda x: int(x), input().split())
        if (0 == com):
            segtree.add(v[0], v[1], v[2])
        else:
            ans.append(segtree.min(v[0], v[1]))

    print("\n".join(map(str, ans)))



Measured memory_bytes: 19060
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<iomanip>
#include<math.h>
#include<bitset>
#include<cassert>
#include<random>
#include<time.h>
#include<functional>
using namespace std;
using ll=long long;
using ld=long double;
using pint=pair<int,int>;
using pll=pair<ll,ll>;
#define MOD 1000000007LL
#define INF 1000000000LL
#define EPS 1e-10
#define FOR(i,n,m) for(ll i=n;i<(ll)m;i++)
#define REP(i,n) FOR(i,0,n)
#define DUMP(a) REP(d,a.size()){cout<<a[d];if(d!=a.size()-1)cout<<" ";else cout<<endl;}
#define ALL(v) v.begin(),v.end()
#define UNIQUE(v)  sort(ALL(v));v.erase(unique(ALL(v)),v.end());
#define pb push_back


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, h, w;
	cin >> n >> h >> w;
	cout << (n - h + 1) * (n - w + 1) << endl;
	return 0;
}

/* --------------------------------------- */


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define vcout(v) rep(i,v.size()) cout << v[i] << " "; cout << endl
#define mcout(m) rep(j,m.size()){vcout(m[j]);}

void mainsolve(){


	ll n,m;
	cin >> n >> m;
	vector<ll> a(n);
	rep(i,n) cin >> a[i];
	sort(a.begin(), a.end());
	vector<ll> ss(n+1);
	rep(i,n) ss[i+1] = ss[i] + a[i];

	// x以上の幸福度を得られる握手がm通り以上あればtrue
	auto isOK = [&](ll x){
		ll cnt = n*n;
		rep(i,n){
			cnt -= lower_bound(a.begin(), a.end(), x-a[i]) - a.begin();
		}
		return cnt >= m;
	};

	auto binsearch = [&](){
		ll ok = 2*a[0]-1;
		ll ng = 2*a[n-1]+1;
		ll mid = (ng+ok)/2;
		while(abs(ng-ok)>1){
			if(isOK(mid)) ok = mid;
			else ng = mid;
			mid = (ng+ok)/2;
		}
		return ok;
	};

	ll c = binsearch();
	ll res = 0;

	// c+1まではまとめて数える
	rep(i,n){
			// 左手は固定
			ll left = a[i];
			ll j = lower_bound(a.begin(), a.end(), c+1-left) - a.begin();
			if(j <= n-1){
				res += (n-j)*left;
				res += ss[n]-ss[j];
				m -= n-j;
			}
			
	}
	
	// 残りは全部c
	res += m*c;
	cout << res << endl;
	return;
}

int main(){
	
	//ll TC;cin>>TC;rep(I,TC){cout<<"case:"<<I+1<<"---"<<endl; // comment out!
		mainsolve();
	//} // comment out!
	return 0;
}


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		while(true){
			int n = stdIn.nextInt();
			if(n==0){
				return;
			}
			int m = stdIn.nextInt();
			char[][] t = new char[n][8];
			int[] p = new int[n];		// price
			for(int i=0;i<n;i++){
				t[i] = stdIn.next().toCharArray();
				p[i] = stdIn.nextInt();
			}
			
			int pay = 0;
			for(int i=0;i<m;i++){			// paper
				char[] h = new char[8];
				h = stdIn.next().toCharArray();
				int idx = 8;
				int tmp = 0;
				for(int j=0;j<n;j++){		// target
					for(int k=7;k>=-1;k--){		// digit
						if(k==-1||t[j][k]=='*'){
							if(k<idx){
								idx = k;
								tmp = p[j];
							}
							break;
						}
						else if(h[k]!=t[j][k]){
							break;
						}
						else if(h[k]==t[j][k]){
							continue;
						}
					}
				}
				pay += tmp;
			}
			System.out.println(pay);
		}
	}
}

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

int main(){
    int n,m;
    int A[100][100],B[100],C[100];
    
    cin >> n >> m;
    for(int i=0; i<n; i++)
        for(int j=0; j<m; j++)
            cin >> A[i][j];
    for (int i=0; i<m; i++) cin >> B[i];
    
    for (int i=0; i<n; i++){
        C[i]=0;
        for (int j=0; j<m; j++){
            C[i]+=A[i][j]*B[j];
        }
        cout << C[i] << endl;
    }
}


Measured memory_bytes: 3124
#include <stdio.h>
 
int main(){
	int a,b,op;
	while (1){
		scanf("%d %c %d",&a,&op,&b);
		if(op=='?')break;
		if(op=='+'){
			printf("%d\n",a+b);
			}
			else if(op=='-'){
				printf("%d\n",a-b);
				}
				else if(op=='*'){
					printf("%d\n",a*b);
					}
					else if(op=='/'){
						printf("%d\n",a/b);
						}
						}
						
	
	return 0;
}
 

Measured memory_bytes: 600
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
struct Edge
{
  int to;
  int weight;
  Edge(int t, int w) : to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;
// using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N, K;
  cin >> N >> K;
  if (N % K == 0)
    cout << 0 << endl;
  else
    cout << 1 << endl;
  return 0;
}


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

using namespace std;

int main(void){
  string str;
  cin >> str;
  
  int check[26] = {0};
  
  for(int i = 0;str[i] != '\0';i++){
    check[str[i] - 'a'] = 1;
  }
  
  for(int i = 0;i < 26;i++){
    if(check[i] == 0){
      cout << (char)(i + 'a') << endl;
      return 0;
    }
  }
  
  cout << "None" << endl;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,m; 
  cin>>n>>m;
  vector<vector<int>> sw;
  vector<int> p;
  for(int i=0; i<m; i++){
    int k;
    cin>>k;
    vector<int> swit;
    for(int j=0; j<k; j++){
      int s;
      cin>>s;
      swit.push_back(s);
    }
    sw.push_back(swit);
  }
  for(int i=0; i<m; i++){
    int ptmp;
    cin>>ptmp;
    p.push_back(ptmp);
  }
  int ans=0;
  for(int i=0; i<(1<<n); i++){
    bitset<10> b(i);
    bool ok =true;
    for(int j=0; j<m; j++){//j個目の電球についてチェック
      int count=0;
      for(int k =0; k<sw.at(j).size(); k++){
        if(b.test(sw.at(j).at(k)-1)) count++;
      }
      if(count%2!=p.at(j)) ok=false;
    }
    if(ok) {
      ans++;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(ll i=0;i<n;i++)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define bFOR(i,n1,n2) for(ll i=n1;i>=n2;i--)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef long long int ll;
typedef pair<ll,ll> Pi;
typedef tuple<ll,ll,ll> Tu;
const int INF=(ll)(1LL<<30)-1;
const double INFd=100000000000.0;
const ll INFl=(ll)9223372036854775807/5;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
const ll tMOD=(ll)998244353;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a, b)*b;}
int dx[4]={0,-1,0,1},dy[4]={-1,0,1,0};
int mdx[8]={0,1,0,-1,1,1,-1,-1},mdy[8]={-1,0,1,0,1,-1,1,-1};


template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main(){
	int n;
	cin>>n;
	for(int i=1;i<=9;i++){
		for(int j=1;j<=9;j++){
			if(i*j==n){
				cout<<"Yes"<<endl;
				return 0;
			}
		}
	}
	cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<stack>
#include <cmath>
using namespace std;

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

int N;
int A[100005], B[100005], C[100005];
ll ans;
signed main() {
	cin >> N;
	
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	for (int i = 0; i < N; i++) {
		cin >> B[i];
	}
	for (int i = 0; i < N; i++) {
		cin >> C[i];
	}

	sort(A, A + N);
	sort(B, B + N);
	sort(C, C + N);

	int tmp1[100005], tmp2[100005];
	for (int i = 0; i < N; i++) {
		tmp1[i] = lower_bound(A, A + N, B[i]) - A;
		tmp2[i] = C + N - upper_bound(C, C + N, B[i]);
		//cout << tmp1[i] << " " << tmp2[i] << endl;
	}
	for (int i = 0; i < N; i++) ans += 1LL * tmp1[i] * tmp2[i];

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 2176
def color(s):
    col = 'black'
    if s == '.':
        col = 'white'
    return col


def main():
    h, w = map(int, input().split())
    s_lst = list(str(input()) for _ in range(h))
    sw_lst = []
    for i in range(h):
        tmp_lst = []
        s = s_lst[i]
        for j in range(w):
            tmp_lst.append(s[j])
        sw_lst.append(tmp_lst)

    flag = True
    black_count = 0

    for i in range(h):
        for j in range(w):

            surroundings = []
            if color(sw_lst[i][j]) == 'black':
                black_count += 1
                if i != 0:
                    surroundings.append(color(sw_lst[i - 1][j]))
                if i != h - 1:
                    surroundings.append(color(sw_lst[i + 1][j]))
                if j != 0:
                    surroundings.append(color(sw_lst[i][j - 1]))
                if j != w - 1:
                    surroundings.append(color(sw_lst[i][j + 1]))

                if 'black' not in surroundings:
                    flag = False

    if flag:
        print('Yes')
    else:
        print('No')


if __name__ == '__main__':
    main()

Measured memory_bytes: 9272
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <vector>
using namespace std;
const int Maxn = 100010;
vector <int> vec[Maxn];
int n, ans, K;
int md[Maxn];
int _max(int x, int y) { return x > y ? x : y; }
void dfs(int x) {
	int sz = vec[x].size();
	md[x] = 1;
	for(int i = 0; i < sz; i++){
		int y = vec[x][i];
		dfs(y);
		if(x != 1 && md[y] == K) ans++;
		else md[x] = _max(md[x], md[y]+1);
	}
}
int main() {
	int i, j, k;
	scanf("%d%d", &n, &K);
	int x;
	scanf("%d", &x);
	if(x != 1) ans = 1;
	for(i = 2; i <= n; i++){
		scanf("%d", &x);
		vec[x].push_back(i);
	}
	dfs(1);
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 12288
#include<iostream>
#include<vector>
using namespace std;
int main(){
    int n,m;
    cin>>n;
    vector<int>t(n);
    for(int i=0;i<n;i++)
    {
        cin>>t[i];
    }
    cin>>m;
    vector<int>p(m),x(m);
    for(int i=0;i<m;i++)
    {
        cin>>p[i]>>x[i];
    }
    int result=0;
    for(int i=0;i<n;i++)
    {
        result+=t[i];
    }
    for(int i=0;i<m;i++)
    {
        cout<<result-t[p[i]-1]+x[i]<<endl;
    }
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define int long long
#define INT_MAX INT64_MAX
#define INT_MIN INT64_MIN
#define PI 3.14159265358979323846
#define CLK clock_t clk = clock();//Start of main
#define OCLK cerr << "Time (in ms): " << (double)(clock() - clk) * 1000.0 / CLOCKS_PER_SEC << '\n';//End of main
#define MOD 1000000007
/* DEFINE cout */
#define pln cout << "===============================\n"
#define on cout<<"\n"
#define os cout<<" "
#define o2(a,b) cout<<a<<" "<<b
#define o(a) cout << a
#define bitcount __builtin_popcount
/* DEFINE cout */
#define endl "\n"
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);//fastio
using namespace std;
struct hash_pair { // use pair as key in unordered_map<pair<int,int>,int,hash_pair>;
    template <class T1, class T2>
    size_t operator()(const pair<T1, T2>& p) const
    {
        auto hash1 = hash<T1>{}(p.first);
        auto hash2 = hash<T2>{}(p.second);
        return hash1 ^ hash2;
    }
};
bool prime[10000001];
int P=MOD-2;
int factorial[10000001]={0};
int powerFunction(int x,int y){
    int res = 1;
    int p = MOD;
    x = x % p;
    while (y > 0){
        if (y & 1)
            res = (res*x) % p;
        y = y>>1;
        x = (x*x) % p;
    }
    return res;
}
void sieveFunction(int maxLimit){
    memset(prime, true, sizeof(prime));
    prime[0] = prime[1]=false;
    for(int i=2; maxLimit >= i ; i++){
        if(prime[i]){
            for(int j=2*i ; maxLimit >= j ; j+=i)
                prime[j]=false;
        }
    }
}
void factorialFunction(int maxLimit){
    factorial[0]=1;
    for(int i=1 ; i <= maxLimit ; i++)
        factorial[i]=(factorial[i-1]*i)%MOD;
    return;
}
int gcd(int a, int b){
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
signed main(){
    int n;
    cin >> n;
    map<string, int> mp;
    for(int i=0; n>i; i++){
        string str;
        cin >> str;
        mp[str]++;
    }
    cout << "AC x " << mp["AC"] << endl;
    cout << "WA x " << mp["WA"] << endl;
    cout << "TLE x " << mp["TLE"] << endl;
    cout << "RE x " << mp["RE"] << endl;
}






Measured memory_bytes: 3640