akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rp(i,n) for(int i=0; i<n; i++)
using namespace std;
using ll=long long;
using P=pair<int,int>;
#define INF 1000000000

int main(){
    int n,m;
    cin >> n >> m;
    map<int,int> mp;
    rp(i,1<<n) mp[i]=INF;
    
    rp(i,m){
        int a,b;
        cin >> a >> b;
        vector<int> c(b);
        rp(j,b) cin >> c.at(j);
        for(int ctr=1; ctr<(1<<b); ctr++){
            int p=0;
            int ct=ctr;
            rp(j,b){
                p+=((ct>>(b-1-j))%2)<<(c.at(j)-1);
            }
            mp[p]=min(mp[p],a);
        }
    }
    //cout << "Yes" << endl;
    for(int i=1; i<(1<<n); i++){
        for(int j=i+1; j<(1<<n); j++){
            mp[i|j]=min(mp[i|j],mp[i]+mp[j]);
        } 
    }
    //cout << "Yes" << endl;
    if(mp[(1<<n)-1]>=INF) cout << -1<< endl;
    else cout << mp[(1<<n)-1] << endl;
    return 0;
}

Measured memory_bytes: 384
#include <vector>
#include <iostream>
#include <stdio.h>
#include <functional>
#include <cassert>
#define INF 2000000000000000

using namespace std;

int main() {
	int v, e, s, t, d;
	cin >> v >> e;
	vector<vector<long long> > ans(v, vector<long long>(v, INF));
	
	for (int i = 0; i < e; ++i) {
		cin >> s >> t >> d;
		ans[s][t] = d;
	}
	for (int i = 0; i < v; ++i) {
		ans[i][i] = 0;
	}

	for (int k = 0; k < v; ++k) {
		for (int i = 0; i < v; ++i) {
			for (int j = 0; j < v; ++j) {
				if (ans[i][j] > ans[i][k] + ans[k][j] && ans[i][k] != INF && ans[k][j] != INF) {
					ans[i][j] = ans[i][k] + ans[k][j];
				}
			}
		}
	}
	bool flag = false;
	for (int i = 0; i < v; ++i) {
		if (ans[i][i] != 0) {
			flag = true;
		}
	}
	if (flag) {
		cout << "NEGATIVE CYCLE" << endl;
	}
	else {
		for (int i = 0; i < v; ++i) {
			for (int j = 0; j < v - 1; ++j) {
				if (ans[i][j] != INF) {
					cout << ans[i][j] << " ";
				}
				else {
					cout << "INF ";
				}
			}
			if (ans[i][v - 1] != INF) {
				cout << ans[i][v - 1] << endl;
			}
			else {
				cout << "INF" << endl;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 3240
fun main(array: Array<String>){
    val mod = (1e9+7).toLong()
    val (h, w) = readLine()!!.split(" ").map { it.toInt() }
    val a = Array(h){Array(w){""}}
    for (i in 0 until h){
        a[i] = readLine()!!.map { it.toString() }.toTypedArray()
    }

    val dp = Array(h){LongArray(w)}
    for (i in 0 until h){
        for (j in 0 until w){
            when {
                i == 0 && j == 0 -> {
                    dp[i][j] = 1
                }
                a[i][j] == "#" -> {
                    dp[i][j] = 0
                }
                i == 0 -> {
                    dp[i][j] = dp[i][j - 1]
                }
                j == 0 -> {
                    dp[i][j] = dp[i - 1][j]
                }
                else -> {
                    dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod
                }
            }
        }
    }

    println(dp[h-1][w-1])
}

Measured memory_bytes: 109072
//#include <bits/stdc++.h>
#include<iostream>
#include <iosfwd>
#include<limits.h>
#include <sstream>
#include <iomanip>
#include <iterator>
#include <algorithm>
#include <limits>
#include<stdio.h>
#include <queue>
#include <stack>
#include <math.h>
#include<string.h>
#include <unordered_map>
#include <map>
#include <unordered_set>
#include <set>
#include<vector>
#include <chrono>
#include <random>
using namespace std;
#define fr(i,j,n)   for(lli i=j;i<(n);++i)
#define bk(i,j,n)   for(lli i=j;i>=n&&j>=n;--i)
#define pb push_back
#define m_p make_pair
#define F first
#define S second
#define endl "\n"
#define MOD 1000000007
#define mem(p,v) memset(p,v,sizeof(p))
#define present(c,x)    ((c).find(x) != (c).end())
#define run ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ordered_set tree<lli, null_type,less<lli>, rb_tree_tag,tree_order_statistics_node_update>
#define debug1(x) cout<<#x<<" "<<x<<endl;
#define debug2(x,y) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<endl;
#define ub upper_bound
#define lb lower_bound
typedef long long int lli;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<lli> vl;
typedef pair<lli,lli> pl;
inline lli max(lli a,lli b){ return a>b?a:b;}
inline lli min(lli a,lli b){ return a<b?a:b;}
const long long inf = 9e18;
double pie = 2*acos(0.0);
void show(vector<lli> v){fr(i,0,v.size())cout<<v[i]<<" ";cout<<endl;}
void show(vector<int> v){fr(i,0,v.size())cout<<v[i]<<" ";cout<<endl;}
void show(int a[], int arraysize){for (int i = 0; i < arraysize; ++i)cout << a[i] << " ";cout<<endl;}
void show(lli a[], lli arraysize){for (lli i = 0; i < arraysize; ++i)cout << a[i] << " ";cout<<endl;}
void show(bool a[], lli arraysize){for (lli i = 0; i < arraysize; ++i)cout << a[i] << " ";cout<<endl;}
void show(set<int> s){for (auto it = s.begin(); it != s.end(); it++){cout << *it << " ";}cout<<endl;}
void show(map<lli,lli> mp){for (auto it = mp.begin(); it != mp.end(); it++){cout << it->first << " "<<it->second<<endl;}cout<<endl;}

lli modpow(lli x,lli n){lli res=1;while(n>0){if(n&1) res=((res%MOD)*(x%MOD))%MOD;x=((x%MOD)*(x%MOD))%MOD;n>>=1;}return res;}
lli power(lli x, lli n){lli res=1;while(n>0){if(n&1) res=res*x;x=x*x;n>>=1;}return res;}

/////// ------ Main code starts here ------ /////
void solve()
{
    lli n,k;
    cin>>n;
    lli a[n],b[n],c[n];
    fr(i,0,n)
    {
        cin>>a[i]>>b[i]>>c[i];
    }
    lli dp[n][3];
    dp[0][0]=a[0];
    dp[0][1]=b[0];
    dp[0][2]=c[0];
    fr(i,1,n)
    {
        dp[i][0]=max(dp[i-1][1],dp[i-1][2])+a[i];
        dp[i][1]=max(dp[i-1][0],dp[i-1][2])+b[i];
        dp[i][2]=max(dp[i-1][1],dp[i-1][0])+c[i];
    }
    cout<<max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]))<<endl;
}
int main()
{
    run;cout<<fixed<<setprecision(12);
    int t;
    t=1;
    while(t){solve();t--;}
    return 0;
}


Measured memory_bytes: 8296
#include<iostream>

using namespace std;

int main(int argc, char const *argv[]) {
  int A,B,C;
  cin >> A >> B >> C;
  if(A>B){
    cout << ((C>B&&C<A) ? "Yes":"No") << endl;
  }else{
    cout << ((C>A&&C<B) ? "Yes":"No") << endl;
  }
  return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vll> vvl;
typedef vector<bool> vb;
typedef vector<string> vs;
typedef vector<pair<ll, ll> > vp;
typedef pair<ll, ll> pr;
typedef tuple<ll, ll, ll> ti;

#define FOR(i, a, b) for (int i = (a), _b = (b); i < _b; i++)
#define FORD(i, b, a) for (int i = (b), _a = (a); i > _a; i--)
#define pb push_back

#define vout(v) do {					\
	for (auto i: v)	cout << i << ' ';	\
	cout << '\n';						\
} while (false)

#define matout(mat) do {					\
	for (auto i: mat) {						\
		for (auto j: i)	cout << j << ' ';	\
		cout << '\n';						\
	}										\
} while (false)

#define vin(v)  for (auto &i: v)    cin >> i

#define matin(mat) do {			\
	for (auto &i: mat)	vin(i);	\
} while (false)

ld pi = 3.141592653589793238;
ll M = 1e9 + 7;

ll gcd(ll a, ll b) {
    if (a == 0) return b;

    return gcd(b % a, a);
}

ll power(ll x, ll y) {
	if (y == 0)
		return 1;

	ll p = power(x, y / 2) % M;
	p = (p * p) % M;

	return y % 2 ? (x * p) % M : p;
}

bool is_prime(ll n) {
    if (n == 2) return true;
    if (n < 2) return false;
    if (n % 2 == 0) return false;

    for (int i = 3; i <= sqrt(n); i += 2) {
        if (n % i == 0) return false;
    }

    return true;
}

bool is_palindrome(string s) {
    return equal(s.rbegin(), s.rend(), s.begin());
}

ll factor(ll n) {
	if (n % 2 == 0)	return 2;
	for (int i = 3; i <= sqrt(n); i += 2) {
		if (n % i == 0)	return i;
	}
	return n;
}

int floor_index(vi& v, int l, int r, int k) {
	while (r - l > 1) {
		int m = l + (r - l) / 2;
		if (v[m] <= k)	l = m;
		else			r = m;
	}
	return l;
}

int ceil_index(vi& v, int l, int r, int k) {
	while (r - l > 1) {
		int m = l + (r - l) / 2;
		if (v[m] >= k)	r = m;
		else		l = m;
	}
	int ans = v[l] >= k ? l : r;

	if (ans < 0 || ans >= v.size())	return -1;
	return ans;
}

ll recur(vll& v, vll& dp, int idx) {
	if (idx == v.size())	return 0;
	if (idx == v.size() - 1)	return dp[idx] = 1;
	if (dp[idx] != -1)	return dp[idx];

	if (v[idx + 1] < v[idx])	return dp[idx] = 1;

	return dp[idx] = 1 + recur(v, dp, idx + 1);
}

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

    ll t, n, m, k, q, x, y;
    string s;
    bool flag;

	cin >> s;

	m = 0;

	for (auto i: s) {
		m += i - '0';
		if (m % 9 == 0)	m = 0;
	}

	if (m % 9 == 0)	cout << "Yes\n";
	else			cout << "No\n";

    return 0;
}

Measured memory_bytes: 3688
#include"bits/stdc++.h"
using namespace std;
 
#define MOD 1000000007
#define MAX 1000002
 
 
int n;
long long int k[MAX];
long long int ppow(long long int i,long long int j) {
	long long int res = 1;
	while (j) {
		if (j & 1LL) {
			res *= i;
			if (res >= MOD)res %= MOD;
		}
		i *= i;
		i %= MOD;
		j >>= 1LL;
	}
	return res;
}
long long int rv[MAX];
 
long long int C(int a, int b) {
	long long int w = k[a] ;
	long long int d = rv[b]*rv[a-b];
	d %= MOD;
	w *= d;
	w %= MOD;
	return w;
}
long long int p[MAX];
long long int dp[MAX][3];
 
 
int main() {
	cin >> n;
	dp[0][0] = 1;
	for (int i = 0; i+1 < MAX; i++) {
		for (int j = 0; j < 3; j++) {
			for (int k = 0; k < 3; k++) {
				if (j != k) {
					dp[i + 1][k] += dp[i][j];
					dp[i + 1][k] %= MOD;
				}
			}
		}
	}
	k[0] = 1;
	for (int i = 1; i < MAX; i++) {
		k[i] = k[i - 1] * i;
		k[i] %= MOD;
	}
	rv[0] = 1;
	for (int i = 1; i < MAX; i++) {
		rv[i] = ppow(k[i], MOD - 2);
	}
	long long int ALL = 1;
	for (int i = 1; i < n; i++) {
		ALL *= 3LL;
		ALL %= MOD;
	}
	ALL = ppow(ALL, MOD - 2);
	p[0] = 1;
	for (int i = 1; i < MAX; i++) {
		p[i] = p[i - 1];
		p[i] *= 2LL;
		p[i] %= MOD;
	}
	long long int WW = 0;
	for (int i = 1; i <= n; i++) {
		long long int way = C(n,i);
		way *= ALL;
		way %= MOD;
		way *= dp[i][1];
		way %= MOD;
		long long int E = ppow(3, MOD - 2);
		//E *= i;
		//E %= MOD;
		E *= ppow(n, MOD - 2);
		E %= MOD;
		//E *= ppow(i, MOD - 2);
		//E %= MOD;
		E *= ppow(i, MOD - 2);
		E %= MOD;
		way *= E;
		way %= MOD;
		WW += way;
		WW %= MOD;
	}
	printf("%lld\n", WW);
	return 0;
}

Measured memory_bytes: 47104
/******************************************************************************

                            Online Java Compiler.
                Code, Compile, Run and Debug java program online.
Write your code in this editor and press "Run" button to execute it.

*******************************************************************************/
import java.util.*;
public class Main
{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		String t = sc.nextLine();
		int n = s.length();
		int m = t.length();
		int i,p=0;
		for(i=0; i<n; i++)
		{
		    if(s.charAt(i) != t.charAt(i))
		    {
		        p = 1;
		        break;
		    }
    	}
    	if(n+1 != m)
    	    p = 1;
    	if(p == 1)
    	    System.out.println("No");
    	else
    	    System.out.println("Yes");
}
}

Measured memory_bytes: 35732
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <map>
#include <bitset>
#include <numeric>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[8]={ 0, 1, 0,-1, 1, 1,-1,-1}; // x軸方向への変位
ll dy[8]={ 1, 0,-1, 0, 1,-1, 1,-1}; // y軸方向への変位

int main(void) {
    ll n, m;
    cin >> n >> m;
    vector<vector<ll>> g(n+1);
    vector<p> vp;
    for(ll i = 0; i < m; i++){
        ll a, b;
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
        vp.push_back(p(a, b));
    }
    ll ans = 0;
    for(ll i = 0; i < m; i++){
        bool ok = false;
        ll a = vp[i].first, b = vp[i].second;
        vector<ll> dist(n+1, -1);
        queue<ll> que;
        dist[1] = 0;
        que.push(1);
        while(!que.empty()){
            ll v = que.front();
            que.pop();
            for(ll nv : g[v]){
                if(dist[nv]!=-1) continue;
                if(a==v && b==nv || a==nv && b==v) continue;
                dist[nv] = dist[v]++;
                que.push(nv);
            }
        }
        for(ll i = 1; i <= n; i++){
            if(dist[i]==-1) ok = true;
        }
        if(ok==true) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ff first
#define ss second
#define pb push_back
#define mp makepair
#define deb(x) cout<<x<<"\n";
#define deB(x,y) cout<<x<<" "<<y<<"\n";
#define Deb(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n" 
#define YES cout<<"YES\n";
#define Yes cout<<"Yes\n";
#define NO cout<<"NO\n";
#define No cout<<"No\n";
#define all(v) (v).begin(),(v).end()
int main()
{
  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  ll x,n,d;
  unordered_map<ll,ll> m;
  ll i=0;
  cin>>x>>n;
  while(n--)
  {
    cin>>d;
    m[d]++;
  }
  if(m[x]==0)
  {
    deb(x)
    return 0;
  }
  i=1;
  while(1)
  {
    if(m[x-i]==0)
    {
      deb(x-i)
      return 0;
    }
    if(m[x+i]==0)
    {
      deb(x+i)
      return 0;
    }
    i++;
  }
}

Measured memory_bytes: 3636
require 'pp'
$DEBUG ? define_method(:dpp){|e|pp e} : define_method(:dpp){|e|}

# 入力値を数値で返却する
def gets_i()
  gets.chomp.to_i
end

# 入力値を文字の配列で返却する
def gets_nsp_list()
  gets.chomp.split("")
end

N = gets_i

s = gets_nsp_list
ans = s.group_by(&:itself).map{|k,v| [k,v.count]}.to_h

(N - 1).times do
  s = gets_nsp_list
  count_hash = s.group_by(&:itself).map{|k,v| [k,v.count]}.to_h
  ans = (ans.keys & s).map do |k|
    [k, [ans[k], count_hash[k]].min]
  end.to_h
end

puts ans.map{|k,v| k * v}.join.chars.sort.join


Measured memory_bytes: 2556
#include<stdio.h>

#define MAX   20
#define M     200

int solve(int,int);

int n;
int A[MAX];

int main()
{
  int q,i,res;
  int B[M];

  scanf("%d",&n);

  for(i = 0;i < n;i++){
    scanf("%d",&A[i]);
  }

  scanf("%d",&q);

  for(i = 0;i < q;i++){
    scanf("%d",&B[i]);
  }

  for(i = 0;i < q;i++){
    res = solve(0,B[i]);
    if(res == 1){
      printf("yes\n");
    }
    else if(res == 0){
      printf("no\n");
    }
  }

  return 0;
}

int solve(int i,int m)
{
  int res;
  if(m == 0) return 1;
  if(i >= n) return 0;

  if(solve(i+1,m) == 1 || solve(i+1,m - A[i]) == 1){
    return 1;
  }
  return 0;
}



Measured memory_bytes: 2108
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;

void solve_A(); void solve_B(); void solve_C(); void solve_D();

int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    /*
     solve_A();
     //*/
    
    /*
     solve_B();
     //*/
    
    
    /*
     solve_C();
     //*/
    
    //*
    solve_D();
     //*/
	return 0;
}

void solve_A(){
    ll N; cin >> N;
    cout << N/3 << endl;
}

void solve_B(){
    ll N; cin >> N;
    vector<char> S(N);
    for(auto &in:S) cin >> in;
    bool f1,f2,f3,f4;
    f1 = f2 = f3 = f4 = false;
    for(int i = 0; i < N;i++){
        if(S[i] == 'P') f1 = true;
        if(S[i] == 'W') f2 = true;
        if(S[i] == 'G') f3 = true;
        if(S[i] == 'Y') f4 = true;
    }
    if(f4){
        cout << "Four" << endl;
    }else{
        cout << "Three" << endl;
    }
}

void solve_C(){
    ll N; cin >> N;
    vector<string> S(N);
    for(auto &in:S) cin >> in;
    ll MARCH[5] = {};
    char C[5] = {'M','A','R','C','H'};
    for(int i = 0 ;i < N;i++){
        for(int j = 0; j < 5;j++){
            if(S[i][0] == C[j]) MARCH[j]++;
        }
    }
    ll ans = 0;
    for(int i = 0; i < 5; i++){
        for(int j = i + 1; j < 5;j++){
            for(int k = j + 1; k < 5;k++){
                ans += MARCH[i] * MARCH[j] * MARCH[k];
            }
        }
    }
    cout << ans << endl;
}

#define MAX_V 100000
ll dist[MAX_V];
void solve_D(){
    ll H,W,D; cin >> H >> W >> D;
    vector<vector<ll>> A(H,vector<ll>(W));
    vector<pll> loc(H*W+1);
    for(int i = 0; i < H;i++){
        for(int j = 0; j < W;j++){
            cin >> A[i][j];
            loc[A[i][j]] = {i,j};
        }
    }
    
    for(int i = 1; i <= H*W; i++){
        if(i <= D){
            dist[i] = 0;
        }else{
            dist[i] = dist[i-D] + abs(loc[i-D].first - loc[i].first) + abs(loc[i-D].second - loc[i].second);
        }
    }
    
    ll Q; cin >> Q;
    for(int q = 0; q < Q; q++){
        ll L,R; cin >> L >> R;
        cout << dist[R] - dist[L] << endl;
    }
}


Measured memory_bytes: 3968
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>

#define REP(i,a,b) for(int i=int(a);i<int(b);i++)

using namespace std;

typedef long long int lli;

struct Data {
    int x, y, c;
    Data(int x, int y, int c) : x(x), y(y), c(c) {}
};

int main () {
    int H, W;
    cin >> H >> W;
    queue<Data> q;
    queue<Data> s;
    int gx, gy;
    vector<vector<char>> ml(H + 2, vector<char>(W + 2, '#'));
    REP (i, 1, H + 1) REP (j, 1, W + 1) {
        cin >> ml[i][j];
        if (ml[i][j] == '@') {
            q.emplace(j, i, 0);
        }
        else if (ml[i][j] == '%') {
            gy = i;
            gx = j;
        }
        else if (ml[i][j] == '$') {
            s.emplace(j, i, 0);
        }
    }
    const int inf = 1 << 30;
    const int dx[4] = {0, 1, 0, -1};
    const int dy[4] = {1, 0, -1, 0};
    vector<vector<int>> pml(H + 2, vector<int>(W + 2, inf / 2));
    vector<vector<int>> sml(H + 2, vector<int>(W + 2, inf));

    auto func = [&ml, &dx, &dy](vector<vector<int>> &ps, queue<Data> &q) -> void {
        while (q.size()) {
            auto d = q.front();
            q.pop();
            if (ps[d.y][d.x] <= d.c) continue;
            ps[d.y][d.x] = d.c;
            REP (k, 0, 4) {
                int nx = d.x + dx[k];
                int ny = d.y + dy[k];
                if (ml[ny][nx] == '#') continue;
                q.emplace(nx, ny, d.c + 1);
            }
        }
    };
    func(pml, q);
    func(sml, s);
    cout << (pml[gy][gx] < sml[gy][gx] ? "Yes" : "No") << endl;
    return 0;
}

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

using namespace std;
using ll = long long;

#define eb emplace_back
#define pb push_back
// #define mp make_pair
#define ff first
#define ss second

#ifdef LOCAL
    #include "debug.h"
#else
    #define debug(...) 42
#endif

void io(){
    ios_base::sync_with_stdio(false); cin.tie(NULL);     
    #ifdef LOCAL
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
}

// #include <ext/pb_ds/assoc_container.hpp> 
// #include <ext/pb_ds/tree_policy.hpp> 
// #include <ext/rope>
// using namespace __gnu_pbds; 
// using namespace __gnu_cxx;
// template<typename T> using oset = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update >;
// template<typename T> using MinPriorityQueue = priority_queue <T, vector <T>, greater <T> >;
// template<typename T> void done(T ans) {cout << ans << "\n"; exit(0);}


template <typename A>
istream& operator>>(istream& input,vector<A>& x) { for(auto& i:x) input>>i; return input; }
template<typename A>
ostream& operator<<(ostream& output,vector<A>& x) {  for(auto& i:x) output<<i<<' '; return output; }
template<typename T, typename U> 
istream& operator>>(istream& is, pair<T, U>& p){is >> p.first >> p.second;        return is;}
template<typename T, typename U> 
ostream& operator<<(ostream& os, pair<T, U>& p){os << p.first << ' ' << p.second; return os;}

const int mod = 1e9 + 7;
const int N = 1e6 + 5;


int a[N * 10];
int main () {
    io();
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++) {
        for(int j = i; j <= n; j += i) {
            a[j]++;
        }
    }
    ll ans = 0;
    for(int i = 1; i <= n; i++) {
        ans += (1LL * a[i] * i);
    }
    cout << ans;
    
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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 (a>b) { a=b; return 1; } return 0; }

#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

vector<vector<pll> > adj;
vll dist;

void dfs(int v, int p)
{
    for(auto e:adj[v]){
        ll u,c;
        tie(u,c) = e;
        if (u==p) continue;
        dist[u]=dist[v]+c;
        dfs(u,v);
    }
}

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin>>n;
    adj.resize(n);
    dist.resize(n,0);
    rep(i,n-1){
        int a,b,c; cin>>a>>b>>c; a--; b--;
        adj[a].emplace_back(b,c);
        adj[b].emplace_back(a,c);
    }
    int q,k; cin>>q>>k; k--;
    dfs(k,-1);
    while(q--){
        int a,b; cin>>a>>b; a--; b--;
        cout<<dist[a]+dist[b]<<endl;
    }
    return 0;
}


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

int r, n;
int h1[40];//x[0]:-20?-19, x[39]:19?20
int h2[41];//判定用
const double EPS=1E-5;

bool a(double t){
  complex<double> c;
  c.real()=0.0, c.imag()=t-r;
  for(int i=0; i<41; i++){
    complex<double> d;
    d.real()=i-20; d.imag()=h2[i];
    //printf("(%f, %f)->%f\n", d.real(), d.imag(), abs(c-d));
    if(abs(c-d)<r-EPS)return true;//含む
  }
  return false;//含まない
}

double solve(){
  double ret=0;
  while(true){
    //cout<<"ret="<<ret<<endl;
    if(a(ret))break;
    ret+=0.001;
  }
  return ret-0.001;
}

int main(){
  while(true){
    cin>>r>>n;
    if(r==0 && n==0)break;
    memset(h1, 0, sizeof(h1));
    memset(h2, 0, sizeof(h2));
    for(int i=0; i<n; i++){
      int xl, xr, h;
      cin>>xl>>xr>>h;
      xl+=20; xr+=20;
      for(int j=xl; j<xr; j++)
        if(h1[j]<h)h1[j]=h;
    }
    for(int i=1; i<40; i++)
      h2[i]=min(h1[i-1], h1[i]);
    /*
    for(int i=0; i<41; i++)
      cout<<h2[i]<<' ';
      cout<<endl;*/
    printf("%.8f\n", solve());
  }

  return 0;
}

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

int n;

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n;
	for (int i = 1; i <= 9; i++)
		for (int j = 1; j <= 9; j++)
			if (i * j == n) {
				cout << "Yes";
				return 0;
			}
	cout << "No";
}


Measured memory_bytes: 256
n = int( input() )
a = list( map( int, input().split() ) )

MOD = 10 ** 9 + 7

sum_a = 0
for a_i in a:
    sum_a = ( sum_a + a_i ) % MOD

ans = 0
for i in range( n ):
    sum_a = ( sum_a - a[ i ] ) % MOD
    ans = ( ans + a[ i ] * sum_a % MOD ) % MOD

print( ans ) 

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

int main(void) {

    string S;
    cin >> S;

    int ans = 0;
    for(unsigned int i=0;i<S.length()/2;++i) {
//      cout << i << " " << S[i] << " " << S[S.length()-1-i] << endl;
        if (S[i] != S[S.length()-1-i]) {
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = acos(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	//const ll p = 1e9 + 7;
	//const ll p = 998244353;

	ll n;
	cin >> n;
	vector<string> s(n);
	for (ll i = 0; i < n; i++) cin >> s[i];

	ll ans = 0;
	ll x_a = 0, b_x = 0, b_a = 0;
	for (ll i = 0; i < n; i++) {
		for (ll j = 0; j < s[i].size() - 1; j++) {
			if (s[i].substr(j, 2) == "AB") ans++;
		}
		if (s[i].front() == 'B' && s[i].back() == 'A') b_a++;
		else if (s[i].front() == 'B') b_x++;
		else if (s[i].back() == 'A') x_a++;
	}

	if (b_a) {
		ans += b_a - 1;
		if (x_a) {
			ans++;
			x_a--;
		}
		if (b_x) {
			ans++;
			b_x--;
		}
	}
	ans += min(x_a, b_x);
	cout << ans << endl;
}


Measured memory_bytes: 768
import math
N, H = map(int, input().split())
A, B = [], []
for _ in range(N):
    a, b = map(int, input().split())
    A.append(a)
    B.append(b)
max_a = max(A)
B_filtered = [b for b in B if b > max_a]
B_filtered.sort(reverse=True)
cnt = 0
for b in B_filtered:
    H -= b
    cnt += 1
    if H <= 0:
        break
if 0 < H:
    cnt += math.ceil(H / max_a)
print(cnt)

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

const int M=1000001;

int main(){
    int n;cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;++i)cin>>a[i];
    vector<int> cnt(M);
    for(int x:a){
        if(cnt[x]!=0){
            cnt[x]=2;
            continue;
        }
        for(int i=x;i<M;i+=x)cnt[i]++;
    }
    //sort(a.begin(),a.end());
    int ans=0;
    for(int x:a){
        if(cnt[x]==1)ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 7968
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> 
//#include <ext/pb_ds/tree_policy.hpp>
//#include <functional> // for less
//using namespace __gnu_pbds;
using namespace std;
typedef long long  L;
L n;
void solve(){
    string s="",ss;
    while(n){
        char s1=('a'+(n-1)%26);
        ss=s1;
        s=(ss+s);
        n=(n-1)/26;
    }
    cout<<s<<endl;
}
int main()
{
    scanf("%lld",&n);
    solve();
    return 0;
}
/// empty() lld I64d push_back() top() pop() insert() upper_bound() lower_bound() memset() max() min() scanf continue


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

typedef long long ll;

int main(){
  ll x;
  int i,j;
  scanf("%lld", &x);
  int flag = 0;

  for(i = -118;i <= 119;i++){
    for(j = -118;j <= 119;j++){
      if(pow(i,5) - pow(j,5) == x){
        printf("%d %d\n", i, j);
        flag = 1;
        break;
      }
    }

    if(flag == 1) break;
  }

  return 0;
}


Measured memory_bytes: 2492
N,K=map(int,input().split())
S=[int(i) for i in input()]
ans,r,l,k=0,0,0,K
while r<N:
  while k>0:
    while l<N and S[l]==1:
      l+=1
    while l<N and S[l]==0:
      l+=1
    k-=1
  while l<N and S[l]==1:
    l+=1
  ans=max(ans,l-r)
  while r<N and S[r]==1:
    r+=1
  while r<N and S[r]==0:
    r+=1
  k=1
print(ans)

Measured memory_bytes: 9916
#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() // 昇順ソート
#define rall(v)(v).rbegin(), (v).rend() // 降順ソート
#define INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair < ll, ll >
#define F first
#define S second
const int MOD = 1000000007;
template < class T > bool chmax(T & a,const T & b) { if (a < b) { a = b; return true; } return false; }
template < class T > bool chmin(T & a,const T & b) { if (a > b) { a = b; return true; } return false; }
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main() {
    int X,Y,Z;cin >> X >> Y >> Z;
    int tmp = X;
    X = Y;
    Y = tmp;
    tmp = X;
    X = Z;
    Z = tmp;
    cout << X  << " " << Y << " " << Z << endl;
}

Measured memory_bytes: 256
def main():
  
    ss = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    ss_rev = dict()
    for i in range(len(ss)):
      ss_rev[ss[i]] = i
 
    N = input()
    N = int(N)
    S = input()
    ans = ""
    for i in range(len(S)):
      ans += ss[(ss_rev[S[i]]+N)%26]
    print(ans)
    
 
if __name__ == '__main__':
  main()

Measured memory_bytes: 3060
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>

using namespace std;

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

long long int INF = 1e18;
long long int MOD = 1e9 + 7;
int const TREE_SIZE = (1 << 20);
long long int seg_tree[TREE_SIZE];

// 1-indexed

void change(int a, long long int w){
	
	// a番目にwを足す O(log N)
	
	a += TREE_SIZE / 2;
	
	seg_tree[a] += w;
	
	for(int x = a / 2; x > 0; x /= 2){
		seg_tree[x] = max(seg_tree[2 * x], seg_tree[2 * x + 1]);
	}
}

long long int query(int a, int b, int index, int l, int r){
	
	// 区間 [a, b) の最小値を求める O(log N)
	// query(a, b, 1, 0, TREE_SIZE / 2) のように呼ぶ
	
	if(r <= a || b <= l){
		return -INF;
	}
	if(a <= l && r <= b){
		return seg_tree[index];
	}
	
	return max(query(a, b, index * 2, l, (l + r) / 2), query(a, b, index * 2 + 1, (l + r) / 2, r));
}

long long int S[110000] = {};

int main(){
    long long int N, R, L;
    cin >> N >> R >> L;
	for(int i = 0; i < TREE_SIZE; i++){
		seg_tree[i] = 0;
	}
	for(int i = 1; i <= N; i++){
		change(i, N - i + 1);
	}
    long long int t_pre = 0, MUL = 1000000, id;
    for(int i = 0; i < R; i++){
        long long int d, t, x;
        cin >> d >> t >> x;
        id = N - (query(1, N + 1, 1, 0, TREE_SIZE / 2) % MUL + MUL) % MUL + 1;
        S[id] += t - t_pre;
        t_pre = t;
		change(d, x * MUL);
    }
    id = N - (query(1, N + 1, 1, 0, TREE_SIZE / 2) % MUL + MUL) % MUL + 1;
    S[id] += L - t_pre;
    long long int ans, SS = 0;
    for(int i = 1; i <= N; i++){
        if(SS < S[i]){
            SS = S[i];
            ans = i;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 12060
#include<iostream>
#include<vector>
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)

using namespace std;

int main() {
  int m, f, r;
  vector<char> res;
  while (cin >> m >> f >> r) {
    if (m == -1 && f == -1 && r == -1) break;
    if (m == -1 || f == -1) {
      res.push_back('F');
      continue;
    }
    int mf = m + f;
    if (mf >= 80) res.push_back('A');
    else if (mf >= 65) res.push_back('B');
    else if (mf >= 50) res.push_back('C');
    else if (mf >= 30 && r >= 50) res.push_back('C');
    else if (mf >= 30) res.push_back('D');
    else res.push_back('F');
  }
  REP(i, res.size()) {
    cout << res[i] << endl;
  }
}


Measured memory_bytes: 3140
import java.util.*;
import java.lang.*;

class Main {
	public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int Q = sc.nextInt();
        int A[] = new int[Q];
        for(int i = 0; i < Q; i++){
        A[i] = sc.nextInt();
        }
        int person[] = new int[N];
        for(int i = 0; i < N; i++){
            person[i] = K - Q;
        }
        for(int i = 0; i < Q; i++){
            person[A[i]-1] ++;
        }
        for(int i = 0; i < N; i++){
            if(person[i] > 0){
                System.out.println("Yes");
            } else {
                System.out.println("No");

            }
        }





    }
}






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

int main(){
    string s;
    cin >> s;

    long long start;
    long long count = 0;
    long long i = 0;
    while(i +2 < s.size()){
        if(s[i] != 'A'){
            start = i+1;
        }
        else if(s[i] == 'A' and s[i+1] == 'B' and s[i+2] == 'C'){
            
            count += i - start+1;
            s[start] = 'B';
            s[start+1] = 'C';
            long long cnt = 0;
            for(long long j = i + 2; j >= start+2; j--){
                s[j] = 'A';
                cnt++;
                if(cnt >= 3){
                    break;
                }
            }
            start += 2;
        }
        i++;
    }
    cout << count << endl;
    return 0;
}

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

void print(deque<int> &ans) {
    for (int i = 0; i < ans.size(); i++) {
        if (i) cout << " ";
        cout << ans[i];
    }
    cout << endl;
}

void moveback(deque<int> &ans, int &k, int &n) {
    while (true) {  
        ans.back()--;
        if (ans.back() == 0) {
            ans.pop_back();
            return;
        }
        else {
            while (ans.size() != n) {
                ans.emplace_back(k);
            }
            return;
        }
    }
}

int main() {
    int n, k; cin >> k >> n;
    deque<int> ans;
    if (k % 2 == 0) {
        ans.assign(n, k);
        ans[0] = k/2;
    } else {
        ans.assign(n, k/2+1);
        int back = ((n-1)+1) / 2;
        while (back--) {
            moveback(ans, k, n);
        }
    }
    print(ans);
    return 0;
}

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

int main(){
  int A, B, C;
  cin >> A >> B;
  C=A*B;
  if(C%2==0){
    cout << "Even"<<endl;
  }else{
    cout << "Odd" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {
	// 1行目がinput[0], 2行目がinput[1], …に入る
	input = input.split(" ");
	//文字列から10進数に変換するときはparseIntを使います
	var A  = parseInt(input[0], 10);
    var op = input[1];
    var B  = parseInt(input[2], 10);
	//出力
    if (op == '+') {
      console.log(A+B);
    } else {
      console.log(A-B);
    }
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 29564
import java.util.Arrays
import java.util.ArrayList

const val MOD: Long = (1e9+7).toLong()
fun Double.format(digits: Int) = String.format("%.${digits}f", this)
fun <T : Comparable<T>> Iterable<T>.argmax(): Int? = withIndex().maxBy{it.value}?.index
fun <T : Comparable<T>> Iterable<T>.argmin(): Int? = withIndex().minBy{it.value}?.index

fun main(args: Array<String>) {
    val reader = System.`in`.bufferedReader()
    val s = reader.readLine()!!

    val p = s.slice(0..1).toInt()
    val q = s.slice(2..3).toInt()
    if (p == 0) { // p is year
        if (q == 0) {
            println("NA")
        } else if (q <= 12) {
            println("YYMM")
        } else {
            println("NA")
        }
    } else if (p <= 12) {
        if (q == 0) {
            println("MMYY")
        } else if (q <= 12) {
            println("AMBIGUOUS")
        } else {
            println("MMYY")
        }
    } else {
        if (q == 0) {
            println("NA")
        } else if (q <= 12) {
            println("YYMM")
        } else {
            println("NA")
        }
    }
}


Measured memory_bytes: 31404
# -*- coding: utf-8 -*-
"""
Created on Tue Aug  7 23:17:21 2018

@author: Yuki
"""


def check_good(S, w, h, W, H):
    upper_flag = True
    down_flag = True
    left_flag = True
    right_flag = True
    if w == 0:
        left_flag = False
    if w == W - 1:
        right_flag = False
    if h == 0:
        upper_flag = False
    if h == H - 1:
        down_flag = False
    tmp = []
    if left_flag:
        tmp.append(S[h][w-1] == '#')
    if right_flag:
        tmp.append(S[h][w+1] == '#')
    if upper_flag:
        tmp.append(S[h-1][w] == '#')
    if down_flag:
        tmp.append(S[h+1][w] == '#')
    return sum(tmp)
def main():
    H, W = map(int, input().split())
    S = []
    for i in range(H):
        S.append(input())
    
    Yes_flag = True
    for w in range(W):
        for h in range(H):
            if S[h][w] == '#':
                res = check_good(S, w, h, W, H)
                if res == 0:
                    Yes_flag = False
#                    print(w, h)
            if Yes_flag == False:
                break
        if Yes_flag == False:
            break
    if Yes_flag:
        print('Yes')
    else:
        print('No')

if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<vector>
#include<numeric>
#include<set>
#include<algorithm>

#define PI 3.14159265358979323846

using namespace std;

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

    cout << 2 * R * PI << endl;
    return 0;
}

Measured memory_bytes: 3780
h, w = map(int, input().split())
a = [input() for _ in range(h)]
a = [x for x in a if not all([i == '.' for i in x])]
b = [[x[i] for x in a] for i in range(w)]
b = ["".join(x) for x in b]
b = [x for x in b if not all([i == '.' for i in x])]
c = [[x[i] for x in b] for i in range(len(b[0]))]
c = ["".join(x) for x in c]
print(*c, sep="\n")

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define int ll
#define FOR(i,a,b) for(int i=int(a);i<int(b);i++)	
#define REP(i,b) FOR(i,0,b)
int read(){
	int i;
	scanf("%lld",&i);
	return i;
}
using vi=vector<int>;
#define PB push_back
#define ALL(x) x.begin(),x.end()

int gcd(int a,int b){
	return b?gcd(b,a%b):a;
}

signed main(){
	int n=read(),k=read();
	vi a(n);
	REP(i,n)a[i]=read();
	int mx=*max_element(ALL(a));
	FOR(i,1,n)
		a[0]=gcd(a[0],a[i]);
	if(k%a[0]==0&&k<=mx)
		cout<<"POSSIBLE"<<endl;
	else
		cout<<"IMPOSSIBLE"<<endl;
}


Measured memory_bytes: 1024
k, a, b = map(int, input().split())
if a + 1 >= b:
    print(k + 1)
elif k <= a - 1:
    print(k + 1)
else:
    remain = k - (a - 1)
    d, m = divmod(remain, 2)
    ans = a + (b - a) * d + m
    print(ans)


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

int main() {
    string S; cin >> S;
    string out = "AC";
 
    if (S[0] != 'A')
        out = "WA";
 
    int cnt = 0, length = S.size();
    for (int i = 1; i < length; i++) {
        if (isupper(S[i])) {
            if (i == 1 || i == length - 1 || S[i] != 'C')
                out = "WA";
            cnt++;
        }
    }
 
    if (cnt != 1)
        out = "WA";
 
    cout << out << endl;
 
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define For(i,x,y) for (register int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (register int i=(x);i<(y);i++)
#define Dow(i,x,y) for (register int i=(x);i>=(y);i--)
#define Debug(v) for (auto i:v) printf("%lld ",i);puts("")
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ep emplace_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define fil(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pa;
typedef pair<ll,ll> PA;
typedef vector<int> poly;
inline ll read(){
    ll x=0,f=1;char c=getchar();
    while ((c<'0'||c>'9')&&(c!='-')) c=getchar();
    if (c=='-') f=-1,c=getchar();
    while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    return x*f;
}

const int N = 1e5+10;
int n;

int main(){
	n=read();
	int p=1;
	while (p<n) p<<=1;
	if (p==n) return puts("No"),0;
	puts("Yes");
	for (int i=2;i+1<=n;i+=2){
		printf("%d %d\n",1,i),printf("%d %d\n",i,i+1);
		printf("%d %d\n",1,n+i+1),printf("%d %d\n",n+i+1,n+i);
	}
	printf("%d %d\n",3,n+1);
	if (n%2==0){
		int p=0;
		For(i,1,20) if ((1<<i)&n){
			p=i;break;
		}
		printf("%d %d\n",n,(1<<p)+1+n);
		printf("%d %d\n",2*n,(n^(1<<p)));
	}
}

Measured memory_bytes: 3752
n = int(input())
s = input()
x = 0
dp = [0] * (n+1)
for i in range(n):
    if s[i] == "I":
        x += 1
    elif s[i] == "D":
        x -= 1
    dp[i+1] = max(dp[i], x)
print(dp[n])

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

int main() {
    // 制約見て！！！デカかったらlong longにすること！
    string s;
    cin >> s;

    int l = 0;
    rep(i, s.size()) {
        if(s[i] == 'A') {
            l = i;
            break;
        }
    }

    int r = 0;
    rep(i, s.size()) {
        if(s[s.size() - 1 - i] == 'Z') {
            r = s.size() - 1 - i;
            break;
        }
    }
    cout << r - l + 1 << endl;
}

Measured memory_bytes: 3740
class ModComb:
    def __init__(self, MAX, mod=10 ** 9 + 7):
        fac = [1, 1]
        finv = [1, 1]
        inv = [0, 1]
        for i in range(2, MAX):
            fac.append(fac[i - 1] * i % mod)
            inv.append(mod - inv[mod % i] * (mod // i) % mod)
            finv.append(finv[i - 1] * inv[i] % mod)
        self.fac, self.finv, self.mod = fac, finv, mod

    def nCk(self, n, k):
        if n < k or n < 0 or k < 0:
            return 0
        fac, finv, mod = self.fac, self.finv, self.mod
        return fac[n] * (finv[k] * finv[n - k] % mod) % mod

mod = 10 ** 9 + 7
mc = ModComb(3 * 10 ** 6, mod)

X, Y = map(int, input().split())
if (2 * X - Y) % 3 != 0 or (X - 2 * Y) % 3 != 0:
    print(0)
    quit()

b = (2 * X - Y) // 3
a = (-X + 2 * Y) // 3

print(mc.nCk(a + b, a))

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

int const N = 200000;
int x[N], y[N];

int main(){
	int n;
	scanf("%d", &n);
	f(i, 0, n)scanf("%d%d", x + i, y + i);
	bool easy = true;
	f(i, 0, n)if (x[i] != y[i]) { easy = false; break; }
	if (easy) { printf("0\n"); return 0; }
	ll an = 0;
	int mn = 1e9;
	f(i, 0, n){
		an += y[i];
		if (x[i] > y[i])mn = min(mn, y[i]);
	}
	an -= mn;
	printf("%lld\n", an);
}

Measured memory_bytes: 384
#define _USE_MATH_DEFINES
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<iomanip>
#include<cassert>

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

	int n;//都市の数
	int initial_position;
	int temporary_x;
	int temporary_maxi;
	int mini;
	int maxi;

	std::cin >> n >> initial_position;
	std::vector<int> distance(n);//initial_positionからの距離
	for (int i = 0; i < n; i++){
		std::cin >> temporary_x;
		distance[i] = abs(initial_position - temporary_x);
	}

	if (n == 1){//都市の数が1の場合以下の処理は行わない
		maxi = distance[0];
	}
	else{//都市の数が1ではないとき以下の処理を行う

		std::sort(distance.begin(), distance.end());

		//各distanceの最大公約数を求める（互除法）
		for (int i = 0; i < n - 1; i++){

			//miniとmaxiに代入
			if (i == 0){
				mini = distance[0];//miniの初期値
				maxi = distance[1];//maxiの初期値
			}
			else{
				mini = maxi;//miniを更新
				maxi = distance[i + 1];//maxiを更新
			}

			//互除法
			while (mini > 0){
				temporary_maxi = maxi;
				maxi = mini;//maxiを更新
				mini = temporary_maxi % mini;//miniを更新
			}
		}

	}

	std::cout << maxi << '\n';

	return 0;
}

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

using namespace std;

int a[3000][3000];
int indices[3000];

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

  for (int i = 0;i < n; ++i) {
    for (int j = 0; j < n - 1; ++j) {
      cin >> a[i][j];
      a[i][j] -= 1;
    }
    indices[i] = 0;
  }

  bool updated = true;
  int cnt = 0;
  while(updated) {
    updated = false;
    std::vector<int> pops;
    for (int i =0; i < n; ++i) {
      if (indices[i] == n - 1) {
        continue;
      }
      if (i == a[a[i][indices[i]]][indices[a[i][indices[i]]]]) {
        pops.push_back(i);
        updated = true;
      }
    }
    if (updated) {
      cnt += 1;
    }
    for (int i =0; i < pops.size(); ++i) {
      indices[pops[i]] += 1;
    }
  }
  bool valid = true;
  for (int i=0;i < n; ++i) {
    if (indices[i] != n -1) {
      valid = false;
      break;
    }
  }
  if (valid) {
    std::cout << cnt << std::endl;
  } else {
    std::cout << -1 << std::endl;
  }

  return 0;
}



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

int main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
  int a, b, k;
  cin >> k;
  cin >> a >> b;
  bool can = false;
  for (int i = a; i <= b; i++) {
    if (i % k == 0){
      can = true;
      break;
    }
  }
  cout << (can? "OK\n" : "NG\n" );
  return 0;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    int a[100005];
    cin>>n;
    for(int i=0;i<n;i++)
        cin>>a[i];
    int flag=0;
    for(int i=0;i<n;i++)
    {
        if(a[i]%4==0)
            flag++;
    }
    if(flag>=n/2)
        cout<<"Yes"<<endl;
    else
    {
        flag*=2;
        for(int i=0;i<n;i++)
        {
            if(a[i]%2==0&&a[i]%4!=0)
                flag++;
        }
        if(flag>=n)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }

    return 0;
}


Measured memory_bytes: 640
from heapq import heappush, heappop, heapify
from collections import deque, defaultdict, Counter
import itertools
from itertools import permutations, combinations, accumulate
import sys
import bisect
import string
import math
import time


def I(): return int(input())


def S(): return input()


def MI(): return map(int, input().split())


def MS(): return map(str, input().split())


def LI(): return [int(i) for i in input().split()]


def LI_(): return [int(i)-1 for i in input().split()]


def StoI(): return [ord(i)-97 for i in input()]


def ItoS(nn): return chr(nn+97)


def input(): return sys.stdin.readline().rstrip()


def show(*inp, end='\n'):
    if show_flg:
        print(*inp, end=end)


def print_matrix(mat):
    for i in range(len(mat)):
        print(*mat[i])


yn = {False: 'No', True: 'Yes'}
YN = {False: 'NO', True: 'YES'}
MOD = 10**9+7
inf = float('inf')
IINF = 10**10
l_alp = string.ascii_lowercase
u_alp = string.ascii_uppercase
ts = time.time()
sys.setrecursionlimit(10**6)
nums = ['1', '2', '3', '4', '5', '6', '7', '8', '9', '10']

show_flg = False
# show_flg = True


def main():
    N, K = MI()
    a = []
    cur = K
    half = []
    zero = []

    dic = defaultdict(int)

    for i in range(1, N+1):
        if K % 2 == 1 and i % K == 0:
            zero.append(i)
        if K % 2 == 0 and i % K == K//2:
            half.append(i)
        if K % 2 == 0 and i % K == 0:
            zero.append(i)

    a = len(zero)
    b = len(half)

    print(a ** 3 + b ** 3)


if __name__ == '__main__':
    main()


Measured memory_bytes: 52460
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　  |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/






int A, B;
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> A >> B;

    if (B % A == 0) cout << A + B << endl;
    else cout << B - A << endl;
}


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

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define rep(i,n) for(int i=0; i<n; i++)
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> P;
typedef map<int,int> mp;

const int MOD = 1e9 + 7;


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

    ll w, h, x, y;
    cin >> w >> h >> x >> y;

    cout << w * h / 2.0 << " " << (2 * x == w && 2 * y == h) << endl;


    return 0;
}



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

bool fun( string word , string  word_1 )
{
    if( word < word_1 )
        return 1 ;
    else
        return 0 ;
}

int main()
{
    int num;
    cin>>num;
    map<string,int> map_1;
    for(int i=0 ; i<num ; i++)
    {
        string word;
        cin>>word;
        map_1[word]++;
    }
    int max_1=0;
    for( auto it : map_1 )
    {
        max_1=max( max_1  , it.second );
    }
    vector<string> word_1;
    for( auto it : map_1)
    {
        if( it.second == max_1 )
            word_1.push_back( it.first );
    }
    sort( word_1.begin() , word_1.end() , fun );
    for(int i=0 ; i<word_1.size() ; i++)
    {
        cout<<word_1[i]<<endl;
    }
    return 0;
}


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

const int INF = INT_MAX / 2;

int main(){
    int A, B; cin >> A >> B;
    int ans = -INF;
    ans = max(ans,A+B);
    ans = max(ans,A-B);
    ans = max(ans,A*B);
    cout << ans << endl;
}


Measured memory_bytes: 256