akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>

using namespace std;

#define ll long long
#define rep(i, n) for(ll i = 0; i < n; i++)
#define P pair<ll, ll>

typedef vector<int> vec;
typedef vector<vec> mat;

vector<P> prime;
priority_queue<ll, vector<ll>, greater<ll> > que;

void factorize(ll n){
    ll num = n;
    for (ll i = 2; i * i <= n; i++){
        if(num % i == 0){
            ll m = 0;
            while(num % i == 0){
                num /= i;
                m++;
            }
            prime.push_back(P(i, m));
        }
        // cout << i << endl;
    }
    if(num != 1){
        prime.push_back(P(num, 1));
    }
}

void fact(ll num, ll m){
    if(m == prime.size()){
        if(num == 1) return;
        // cout << num << endl;
        que.push(num);
        return;
    }
    ll k = 1;
    rep(i, prime[m].second + 1){
        // cout << k << " " << k << endl;
        fact(num * k, m + 1);
        k *= prime[m].first;
    }
}

int main(){
    ll n;
    cin >> n;
    factorize(n);
    // rep(i, prime.size()){
    //     cout << prime[i].first << " " << prime[i].second << endl;
    // }
    // fact(1, 0);



    ll ans = 0;
    rep(i, prime.size()){
        ll num = 1;
        while(prime[i].second >= num){
            ans++;
            prime[i].second -= num;
            num++;
        }
    }
    

    cout << ans << endl;

}


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

int main() {
    string s, t;
    cin >> s >> t;
    sort(s.begin(), s.end());
    sort(t.rbegin(), t.rend());

    if (s < t) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


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

int simulate(vector<vector<int>> &garden, int x0, int x1, int y0, int y1) 
{
    // [x0,x1) [y0,y1) に池を作った時の最大容量
    // 内側のマスが外側のマスと同じ大きさがそれより大きい、もしくは外側のマスが内側より小さい時は-1を返す

    int inner_max = -1000000, outer_min = 1000000;
    for(int i = x0; i < x1; ++i) {
        for(int j = y0; j < y1; ++j) {
            if(x0 < i && i < x1-1 && y0 < j && j < y1-1) {
                inner_max = max(inner_max, garden[i][j]);
            } else {
                outer_min = min(outer_min, garden[i][j]);
            }
        }
    }
    /*
    cout << "x0:" << x0 << " x1:" << x1 << " y0:" << y0 << " y1:" << y1 << endl;
    cout << "inner_max:" << inner_max << " outer_min:" << outer_min << endl;
    */
    if(inner_max >= outer_min) return -1;
    int res = 0;
    for(int i = x0+1; i < x1-1; ++i) {
        for(int j = y0+1; j < y1-1; ++j) {
            res += outer_min - garden[i][j];
        }
    }
    return res;
}

bool solve()
{
    int d, w;
    cin >> d >> w;
    if(d == 0 && w == 0) return false;

    vector<vector<int>> garden(d, vector<int>(w, 0));
    for(int i = 0; i < d; ++i) {
        for(int j = 0; j < w; ++j) {
            cin >> garden[i][j];
        }
    }

    int res = 0;
    for(int x0 = 0; x0 < d; ++x0) {
        for(int x1 = x0+3; x1 <= d; ++x1) {
            for(int y0 = 0; y0 < w; ++y0) {
                for(int y1 = y0+3; y1 <= w; ++y1) {
                    res = max(res, simulate(garden, x0, x1, y0, y1));
                }
            }
        }
    }

    cout << res << endl;
    return true;
}

int main() {
    while(solve());
    return 0;
}


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

const double pi = acos(-1);
#define INF 999999999
int main ()
{
   int n;   cin >> n;
   vector<int>v(n);

   for(int i=0;i<n;i++){
       cin >> v.at(i);
   }
   
   reverse(v.begin(),v.end());

   for(int i=0;i<n-1;i++) cout << v.at(i) << " ";

   cout << v.at(n-1) <<endl;
    
}



Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
struct node
{
    int id,v;
    string s;
}a[105];
bool cmp(node &x,node &y)
{
    return x.s<y.s||(x.s==y.s&&x.v>y.v);
}
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        cin>>a[i].s>>a[i].v;
        a[i].id=i;
    }
    sort(a+1,a+1+n,cmp);
    for(int i=1;i<=n;i++)
    {
        printf("%d\n",a[i].id);
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
void solve() {
    int x, n;
    cin >> x >> n;
    set<int> s;
    for (int i = 0; i < n; ++i) {
        int v;
        cin >> v;
        s.insert(v);
    }
    vector<int> a;
    for (int i = -101; i <= 101; ++i) {
        if (s.find(i + x) == s.end()) {
            a.push_back(i + x);
        }
    }
    int pos = 0;
    for (int i = 1; i < a.size(); ++i) {
        if (abs(a[i] - x) < abs(a[pos] - x)) {
            pos = i;
        }
    }
    cout << a[pos] << "\n";
}
 
int main() {
    ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    int t = 1;
    while (t--) {
        solve();
    }
  //  cerr << fixed << setprecision(5) << double(clock()) * 1000 / CLOCKS_PER_SEC << " ms\n";
    return 0;
}

Measured memory_bytes: 3620
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long ll;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }
/////////////////////////////////////////////////////////////////////

int main()
{ int n;
	cin>>n;
	   vector <vector <ll>> dp(n,vector <ll>(n,0));
	for(int i =0;i<n;i++)
		{
		cin>>dp[i][i];
		}
// dp[i][j] denotes the maximum difference 
for(int d = 1;d<n;d++)
	for(int i = 0;i<n-d;i++)
		dp[i][i+d] = max(dp[i][i]- dp[i+1][i+d],dp[i+d][i+d]-dp[i][i+d-1]);
	cout<<dp[0][n-1];

    return 0;
}

Measured memory_bytes: 73748
#include <bits/stdc++.h>
  
using namespace std;
  
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)((x).size()))
  
typedef pair<int, int> PII;
typedef vector<int> VI;
typedef long long int64;
typedef unsigned int uint;
typedef unsigned long long uint64;
  
#define gi(x) ((x) = F())
#define gii(x, y) (gi(x), gi(y))
#define giii(x, y, z) (gii(x, y), gi(z))
  
int F()
{
    char ch;
    int x, a;
    while (ch = getchar(), (ch < '0' || ch > '9') && ch != '-');
    if (ch == '-') ch = getchar(), a = -1;
    else a = 1;
    x = ch - '0';
    while (ch = getchar(), ch >= '0' && ch <= '9')
        x = (x << 1) + (x << 3) + ch - '0';
    return a * x;
}
  
const int N = 1e5 + 10;
  
int n, k, a[N];
  
int ans = 0;
  
int deg[N], dep[N];
  
int main()
{
    gii(n, k); --k;
    for (int i = 1; i <= n; ++i) gi(a[i]);
    if (a[1] != 1) ++ans, a[1] = 1;
    for (int i = 1; i <= n; ++i)
        ++deg[a[i]];
    static int q[N]; int l = 0, r = 0;
    for (int i = 1; i <= n; ++i)
    {
        if (!deg[i]) q[r++] = i;
    }
    while (l < r)
    {
        int u = q[l++];
        --deg[a[u]];
        if (!deg[a[u]]) q[r++] = a[u];
        if (dep[u] == k && a[u] != 1) a[u] = 1, ++ans;
        else dep[a[u]] = max(dep[a[u]], dep[u] + 1);
    }
    printf("%d\n", ans);
    return 0;
}

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

int main() {
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n; cin >> n;
	int k = (n + 1000 - 1) / 1000;
	cout << k * 1000 - n << endl;
}

Measured memory_bytes: 3644
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>
//#include <intrin.h>
//#include <chrono>
//#include <random>
//#include <unordered_map>

using namespace std;

typedef long long ll;

void solve() {
	int n;
	cin >> n;
	int t = n / 1000;
	cout << (1000 - (n - t * 1000)) % 1000;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int q = 1;
	//cin >> q;
	for (; q > 0; q--) {
		solve();
		cout << '\n';
	}
}

Measured memory_bytes: 3644
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<map>
#include<tuple>
#include<algorithm>
#include<cmath>
#include<limits>
#include<set>
#include<deque>
#include<queue>
#include<stack>
using namespace std;
#define int long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define dup(x,y) (((x)+(y)-1)/(y))
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7;
//const int MOD = 998244353;
const int INF = 1e18;
const long double PI = (acos(-1));

struct UnionFind {
	vector<int> d; // d[i]:iの親の番号　(例) d[3] = 2 : 3の親が2 d[3] = -3 : 3は根で、その連結成分のサイズは3

	UnionFind(int N) : d(N, -1) {} // 負なら根である 非負なら子である

	int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
		if (d[x] < 0) return x; //負なら根であるから根を返す
		return d[x] = root(d[x]);
	}

	bool unite(int x, int y) { // xとyの木を併合
		int rx = root(x); //xの根をrx
		int ry = root(y); //yの根をry
		if (rx == ry) return false; //xとyの根が同じ(=同じ木にある)時はそのまま
		if (d[rx] > d[ry])swap(rx, ry); //木のサイズが大きいほうにくっつける
		d[rx] += d[ry]; //サイズが上乗せされる
		d[ry] = rx; //yの根はxになる
		return true;
	}

	bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
		int rx = root(x);
		int ry = root(y);
		return rx == ry;
	}
	int size(int x) {
		return -d[root(x)];
	}
};

signed main() {
	int N, M;
	cin >> N >> M;
	UnionFind tree(N);
	rep(i, M) {
		int A, B;
		cin >> A >> B;
		A--; B--;
		if (tree.same(A, B) == false)tree.unite(A, B);
	}
	int ans = 0;
	rep(i, N) {
		ans = max(ans, tree.size(i));
	}
	cout << ans;
}

Measured memory_bytes: 4844
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#include <functional>
#include <map>
#include <set>
#include <cmath>
#include <string>
#define SIZE 200005
#define INF 1000000005LL

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int n;
char str[51][51];
int dp[51][51];
int t[51][51];

int main()
{
	int h,w;
	char ch;
	scanf("%d %d\n",&h,&w);
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			scanf("%c",&ch);
			t[i][j] = ch-'0';
		}
		scanf("%c",&ch);
	}
	for(int i=0;i<=h;i++)dp[i][0]=99999999;
	for(int i=0;i<=w;i++)dp[0][i]=99999999;
	for(int i=1;i<=h;i++){
		for(int j=1;j<=w;j++){
			if(i==1&&j==1){
				dp[i][j]=t[i][j];
				continue;
			}
			dp[i][j] = min(dp[i-1][j],dp[i][j-1])+t[i][j];
			//printf("%d ",dp[i][j]);
		}
	}
	printf("%d\n",dp[h][w]);
			
	return 0;
}



Measured memory_bytes: 2776
def full(n)
  if n==0
    1
  else
    2*full(n-1)+1
  end
end
def whole(n)
  if n==0
    1
  else
    2*whole(n-1)+3
  end
end

def partial(n,x)
  if n==0
    return x
  end
  u=whole(n-1)
  if x<=u+1
    if x<=1
      return 0
    end
    return partial(n-1,x-1)
  end
  return full(n-1)+partial(n-1,[x-u-2,u].min)+1
end

n,x=gets.split.map &:to_i
puts partial(n,x)

Measured memory_bytes: 1916
import math
N = int(input())

dic = {}
zz = 0
az = 0
bz = 0

for i in range(N):

    A,B = map(int,input().split())

    if A == B == 0:
        zz += 1
    elif A == 0:
        az += 1
    elif B == 0:
        bz += 1
    else:

        g = math.gcd(A,B)
        A //= g
        B //= g

        if A*B > 0:
            now = (A,B)
            ind = 0
        else:
            now = (-1*B,A)
            ind = 1

        if now[0] < 0:
            now = (-1 * now[0] , -1 * now[1])
            

        if now not in dic:
            dic[now] = [0,0]
        dic[now][ind] += 1

mod = 10**9+7
ans = pow(2,az,mod) + pow(2,bz,mod) - 1

for i in dic:

    aa,bb = dic[i]
    now = pow(2,aa,mod) + pow(2,bb,mod) - 1
    ans *= now
    ans %= mod

print ((ans - 1 + zz) % mod)
        


Measured memory_bytes: 134604
#include <bits/stdc++.h>
 
using namespace std;
 
#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl;
#define DEBUG_MAT(v) cerr<<#v<<endl;for(int i=0;i<v.size();i++){for(int j=0;j<v[i].size();j++) {cerr<<v[i][j]<<" ";}cerr<<endl;}
typedef long long ll;
#define int ll
 
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
template<class S, class T> pair<S, T> operator+(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first + t.first, s.second + t.second); }
template<class S, class T> pair<S, T> operator-(const pair<S, T> &s, const pair<S, T> &t) { return pair<S, T>(s.first - t.first, s.second - t.second); }
template<class S, class T> ostream& operator<<(ostream& os, pair<S, T> p) { os << "(" << p.first << ", " << p.second << ")"; return os; }
#define X first
#define Y second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define rrep1(i,n) for(int i=(int)(n);i>0;i--)
#define REP(i,a,b) for(int i=a;i<b;i++)
#define in(x, a, b) (a <= x && x < b)
#define all(c) c.begin(),c.end()
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 UNIQUE(v) v.erase(std::unique(v.begin(), v.end()), v.end());
const ll inf = 1000000001;
const ll INF = (ll)1e18 + 1;
const long double pi = 3.1415926535897932384626433832795028841971L;
#define Sp(p) cout<<setprecision(25)<< fixed<<p<<endl;
// int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
// int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };
vi dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
vi dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };
#define fio() cin.tie(0); ios::sync_with_stdio(false);
const ll MOD = 1000000007;
// const ll MOD = 998244353;
// #define mp make_pair
//#define endl '\n'


signed main() {
	fio();
	ll n;
	cin >> n;
	string ans;
	while (n > 0) {
		n--;
		ans += 'a' + n % 26;
		n /= 26;
	}
	reverse(all(ans));
	cout << ans << endl;
}

Measured memory_bytes: 3652
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
	    Scanner sc = new Scanner(System.in);
	    long x = sc.nextLong();
	    long k = sc.nextLong();
	    long d = sc.nextLong();
	    if (x == d) {
	    	if (k % 2 == 0)  System.out.println(x);
	    	if (k % 2 == 1)  System.out.println(0);
	    } else {
	    	long wk = (long)Math.floor(Math.abs(x) / d);
	    	if (wk >= k) {
		    	if (x < 0) System.out.println(Math.abs(x + k*d));
		    	if (x >= 0) System.out.println(Math.abs(x - k*d));
	    	} else {
	    		if ((k - wk) % 2 == 0) {
	    			if (x < 0) System.out.println(Math.abs(x + wk*d));
			    	if (x >= 0) System.out.println(Math.abs(x - wk*d));
	    		} else {
	    			if (x < 0) System.out.println(Math.abs(x + (wk + 1)* d));
			    	if (x >= 0) System.out.println(Math.abs(x - (wk + 1)* d));
	    		}
	    	}
	    }
	}
}


Measured memory_bytes: 27064
"use strict";
// ネット上にあった素数判定アルゴリズムを拝借
function primeNumber(n) {
 if (n === 2) return true;
 for (let i = 2; i < n; i++) {
   if (n % i === 0) return false;
 }
 return true;
}

function Main(input) {
let n = input;
while(!(primeNumber(n))){
  n++;
}
 console.log(n);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8").trim());


Measured memory_bytes: 21064
def index(c):return ord(c)-ord('A')+1
s=' '+input()
m=10**9+7
dp=[[0]*4 for _ in range(len(s))]
dp[0][0]=1
for i in range(1,len(s)):
    for j in range(4):
        dp[i][j]=dp[i-1][j]
    if s[i]=='?':
        dp[i][0]=dp[i-1][0]*3%m
        for j in range(1,4):
            dp[i][j]=(dp[i-1][j-1]+dp[i-1][j]*3)%m
    else:
        k=index(s[i])
        dp[i][k]=(dp[i-1][k-1]+dp[i-1][k])%m
print(dp[-1][3])

Measured memory_bytes: 27636
#include<string>
#include<iostream>

using namespace std;

int main()
{
	for(string s1,s2;cin>>s1>>s2;){
		int len1=s1.length(),len2=s2.length();
		int lcslen=0;
		for(int i=-len2+1;i<len2;i++){
			int cnt=0;
			for(int j=0;j<len1;j++){
				if(0<=i+j && i+j<len2 && s1[j]==s2[i+j])	cnt++;
				else	lcslen=max(lcslen,cnt),cnt=0;
			}
			lcslen=max(lcslen,cnt);
		}
		cout<<lcslen<<endl;
	}

	return 0;
}

Measured memory_bytes: 936
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; i++)
#define PI 3.1415926535897932384626433832795028
#define INF (1<<29)
#define LINF (1LL<<60)
using namespace std;
using INT = long long;
using P = pair<int,int> ;

int main(){
    int n,m,ans=0;
    cin >> n >> m;
    vector<vector<int>> r;
    r.resize(n);
    int ex[n];
    rep(i,n){
        cin >> ex[i];
    }
    
    rep(i,m){
        int a,b;
        cin >> a >> b;
        r[a-1].push_back(b-1);
        r[b-1].push_back(a-1);
    }
    rep(i,n){
        int tmp = r[i].size();
        int num = 0;
        rep(j,r[i].size()){
            if(ex[i]>ex[r[i][j]]) num++;
        }
        if(num==tmp) ans++;
        
    }
    cout << ans << endl;
	return 0;
}



Measured memory_bytes: 8800
ans,A,N,K = 0,0,0,0

def a():
    global ans,A,N,K
    N,K = map(int,input().split())
    A = list(map(int,input().split()))

    if K == 0:
        return max(A)

    def dividable(x):
        global ans,A,N,K
        ans = 0
        for a in A:
            if a % x == 0:
                ans += a // x - 1
            else:
                ans += a // x
        return ans <= K

    ng = 0
    ok = 10 ** 9 + 1
    mid = 0
    while abs(ng-ok) > 1:
        mid = (ok + ng) // 2
        if dividable(mid):
            ok = mid
        else:
            ng = mid
    return ok

print(a())

Measured memory_bytes: 93776
#include <cstdio>
#include <algorithm>
using namespace std;

long long n, k;
inline long long calc(long long x) { return x * x * x; }

int main() {
    scanf("%lld%lld", &n, &k);
    if (k & 1) {
        printf("%lld\n", calc(n / k));
    } else {
        printf("%lld\n", calc(n / k) + calc(n / k + (n % k >= k / 2)));
    }
    return 0;
}

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

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

  if (a > b) cout << "a > b" << endl;
  if (a < b) cout << "a < b" << endl;
  if (a == b) cout << "a == b" << endl;
}

Measured memory_bytes: 1160
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(int i = m, i##_len = (n); i < i##_len; ++i)
#define reprev(i, n) for(int i = (n-1LL); i >= 0; --i)
#define all(x) (x).begin(), (x).end()
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 <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> p(n), q(n), r(n);
    rep (i, n) r[i] = i + 1;
    rep (i, n) cin >> p[i];
    rep (i, n) cin >> q[i];
    int a = 0, b = 0;
    while (true) {
        bool c = true;
        rep (i, n) if (p[i] != r[i]) c = false;
        if (c) break;
        a++;
        next_permutation(all(r));
    }
    rep (i, n) r[i] = i + 1;
    while (true) {
        bool c = true;
        rep (i, n) if (q[i] != r[i]) c = false;
        if (c) break;
        b++;
        next_permutation(all(r));
    }
    cout << abs(a - b) << "\n";
    return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc076/tasks/abc076_b
#include <bits/stdc++.h>
using namespace std;

int main(void)
{
  int N, K;
  cin >> N >> K;
  int num = 1;

  for (int i = 0; i < N; i++){
    if (num < K){
      num += num;
    }else{
      num += K;
    }
  }

  cout << num << endl;
}

Measured memory_bytes: 256
"""
task statement
==============

長さ N の整数の列 A_1,A_2,\ldots,A_N であって以下の条件をすべて満たすものはいくつありますか。

0 \leq A_i \leq 9
A_i=0 なる i が存在する。
A_i=9 なる i が存在する。

ただし、答えはとても大きくなる可能性があるので、10^9+7 で割った余りを出力してください。

io_style
-------
N
"""
import sys
# sys.setrecursionlimit(100000)


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


def input_int():
    return int(input())


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


def main():
    n = input_int()
    if n == 1:
        print(0)
        return
    MOD = 10**9 + 7
    ans = pow(10, n, MOD) - pow(9, n, MOD) - pow(9, n, MOD) + pow(8, n, MOD)
    print(ans % MOD)
    return


if __name__ == "__main__":
    main()


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



struct UnionFind{
    vector<int> par;
    UnionFind(int n) : par(n, -1){};    //初期化、rankとしても扱う
    
    //根を求める
    int root(int x){
        if(par[x]<0) return x;
        return par[x] = root(par[x]);
    }
    //縮合する
    void unite(int a, int b){
        int x = root(a), y = root(b);
        if(x==y) return; 
        if(par[x]>par[y])   swap(x, y);
        par[x] += par[y];
        par[y] = x;
    }
    bool same(int a, int b){
        return root(a) == root(b);
    }
    int size(int x){
        return -par[root(x)];
    }
};

int main(){
    int n, k, l;    cin >> n >>  k >> l;
    UnionFind road(n), train(n);
    for(int i=0; i<k; i++){
        int a, b;   cin >> a >> b;
        a--; b--;
        road.unite(a, b);
    }
    for(int i=0; i<l; i++){
        int a, b;   cin >> a >> b;
        a--; b--;
        train.unite(a, b);
    }
    using p = pair<int, int>;
    map<p, int> mc;
    for(int i=0; i<n; i++){
        p key(train.root(i), road.root(i));
        mc[key] += 1;
    }
    for(int i=0; i<n; i++){
        p key(train.root(i), road.root(i));
        cout << mc[key] << ' ';
    }

}

Measured memory_bytes: 13568
use proconio::*;

fn run() {
    input! {
        n: usize,
        m: usize,
        k: i64,
        a: [i64; n],
        b: [i64; m],
    }
    let mut p = 0;
    let mut sum = 0;
    while p < m && sum + b[p] <= k {
        sum += b[p];
        p += 1;
    }
    let mut ans = p;
    for (i, a) in a.into_iter().enumerate() {
        sum += a;
        while p > 0 && sum > k {
            p -= 1;
            sum -= b[p];
        }
        if sum <= k {
            ans = std::cmp::max(ans, p + i + 1);
        }
    }
    println!("{}", ans);
}

fn main() {
    run();
}


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

using namespace std;

int main()
{
	int a, b, c, d, e, f, x = 0, w = 0, v[3001] = {}, y;
	cin >> a >> b >> c >> d >> e >> f;
	
	for (int i = 0; i <= f; i += c)
		for (int j = 0; j <= f; j += d)
			if (i+j <= min(f, e*(f-i-j)/100))
				v[i+j] = 1;
	
	for (int i = 0; 100*i <= f; i += a)
		for (int j = 0; j*100 <= f; j += b)
			for (int k = 0; k < 3001; k++)
				if (100*i+100*j+k > f)
					break;
				else if (v[k] && k <= e*(i+j))
				{
					if (x*(100*i+100*j+k) <= w*k)
					{
						x = k;
						w = 100*i+100*j+k;
					}
				}
						
	cout << w << " " << x;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	int A,B,C;
	cin >> A >> B >> C;
	cout << A * B / 2<< endl;
	return 0;
}

Measured memory_bytes: 256
// +build ignore
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []byte {
	return []byte(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

func gcd(x, y int) int {
	if x%y != 0 {
		return gcd(y, x%y)
	}
	return y
}

func run(input io.Reader, output io.Writer) int {
	sc := NewScanner()
	K := sc.nextInt()
	S := sc.nextStr()

	if len(S) <= K {
		fmt.Println(S)
	} else {
		fmt.Printf("%s...\n", S[:K])
	}
	return 0
}

func main() {
	os.Exit(run(os.Stdin, os.Stdout))
}


Measured memory_bytes: 1760
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
using Graph = vector<vector<int> >;
// MOD
const int MOD = 1000000007;

long long INF = 1<<30;
long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}

int H, W;
int field[100][100];

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const double PI=3.14159265358979323846;
bool seen[100][100];


string N[100];

bool memo[110];
bool flag;
Graph G;

int dist[100][100];

bool compare_f(pair<int, int> &x, pair<int, int> &y) {
  return x.second< y.second;
}

int dp[100000];

struct Unionfind{
    vector<int> par;

    Unionfind(int n) : par(n, -1){}

    int root(int x){
        if(par[x] < 0) return x;
        else return par[x] = root(par[x]);
    } 

    bool issame(int x, int y){
        return root(x) == root(y);
    }

    bool merge(int x, int y){
        x = root(x); y = root(y);
        if(x == y) return false;
        if(par[x]>par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    int size(int x){
        return -par[root(x)];
    }
};

bool A[105];

int main() {
    int N, K; cin >> N >> K;
    int d;
    int res = 0;

    for(int k=0; k<K; k++){
        cin >> d;
        for(int i=0; i<d; i++){
            int a; cin >> a; a--;
            A[a] = true;
        }
    }
    for(int i=0; i<N; i++){
        if(A[i] == false) res++;
    }
    cout << res <<endl;
}

Measured memory_bytes: 3148
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdint.h>
#include<malloc.h>
#include<math.h>
#include<x86intrin.h>


int my_gets(char *buf,int nBuf,FILE *fp){
    int ch;

    while(--nBuf >0){
        ch=getc(fp);
        if(ch==EOF || ch=='\n')
            break;
        *(buf++)=(char)ch;
    }
    *(buf)='\0';

    return nBuf;
}

void InputIntAry(int *a,int nDigit,int N){      //nDigitは想定される最大桁数
    char *buf,*ptr;

    buf=(char*)malloc( (N*(nDigit+2)) * sizeof(char) );
    my_gets(buf,N*(nDigit+2),stdin);

    ptr=strtok(buf," ");
    while(ptr!=NULL && N-->0){
        *(a++)=atoi(ptr);
        ptr=strtok(NULL," ");
    }
    free(buf);
}

int CmpInt(const void *a, const void *b){        //b-aを返す(qsortなら4321)
    return *((int*)b)- *((int*)a);
}

int main(){
    int A,B;

    scanf("%d %d%*c",&A,&B);
    printf("%d\n", (B + (A-3))/(A-1) );
} 

Measured memory_bytes: 128
//It doesn't matter how slow you go, Unless you don't stop.
#include<iostream>
#include<algorithm>
#include<bitset>
 
#include<cmath>
#include<cstring>
#include<climits>
 
#include<deque>
#include<queue>
#include<vector>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
 
#include<fstream>
#include<chrono>
using namespace std;
 
typedef long long LL;
typedef pair<LL,LL> p64;
typedef vector<LL> v64;
typedef map<LL,LL> mp64;
 
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define rep(i,s,e) for(long long i=s;i<=e;i++)
#define brep(i,s,e) for(long long i=s;i>=e;i--)
#define all(x) x.begin(),x.end()
#define mem(x,y) memset(x,y,sizeof(x))
#define DANGER std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
 
void solve()
{
     LL n,m;
     cin>>n>>m;
     if(n%m == 0)
     {
         cout<<"0"<<endl;
         return;
     }
     else
     {
         LL dummy = n%m;
         set<LL> s;
         while(true)
         {
             dummy = abs(dummy - m);
             int size = s.size();
             s.insert(dummy);
             if(size == s.size())
             {
                 break;
             }
         }
         cout<<*s.begin()<<endl;
     }
     
     
}
 
int main()
{
    DANGER;
    ofstream out("output.txt");
 
    auto start = chrono::high_resolution_clock::now();
    
    LL t = 1;
    // cin>>t;
    rep(test,1,t)
    {
        solve();
    }
    
    auto stop = chrono::high_resolution_clock::now();
    // auto duration = chrono::duration_cast<chrono::milliseconds>(stop - start); 
    // cout << "Time taken by function: " << duration.count() << " milliseconds" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
const int mod=1e9+7;
// Not for Rating """"""""""I'm in Love with Experience :)""""""""""""""""""
void solve()
{
    ll N;cin>>N;
    if(N%2==0){cout<<"-1";return;}
    ll rem=0;
    for(ll i=1;i<=1000000;++i)
    {
        rem = (rem*10 + 7)%N;
        if(rem==0)
        {
            cout<<i;return;
        }
    }
    cout<<"-1";
}
int main(void)
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
    int T=1;while(T--){solve();}return 0;
}/*Solved By:- RITIK AGARWAL*/

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

int main() {
    ios::sync_with_stdio(false);
    int n, a, b, c; cin >> n >> a >> b >> c;
    map<char, int> val;
    val['A'] = a;
    val['B'] = b;
    val['C'] = c;
    
    vector<string> queries;
    for(int i = 0; i < n; i++) {    
        string s; cin >> s;
        queries.push_back(s);
    }
    vector<char> ans;
    for(int i = 0; i < n; i++) {
        string s = queries[i];
        int& val1 = val[s[0]];
        int& val2 = val[s[1]];
        if(val1 == 0 and val2 == 0) {
            cout << "No\n";
            exit(0);
        }
        if(val1 == 0) {
            val1++;
            val2--;
            ans.push_back(s[0]);
            continue;
        }
        if(val2 == 0) {
            val1--;
            val2++;
            ans.push_back(s[1]);
            continue;
        }
        if(i == n - 1) {
            ans.push_back(s[0]);
        }
        else {
            if(queries[i + 1] == s) {
                ans.push_back(s[0]);
                ans.push_back(s[1]);
                i++;
            }
            else {
                if(s[0] == queries[i + 1][0] or s[0] == queries[i + 1][1]) {
                    val1++;
                    val2--;
                    ans.push_back(s[0]);
                }
                else {
                    val1--;
                    val2++;
                    ans.push_back(s[1]);
                }
            }
        }
    }
    cout << "Yes\n";
    for(char ch : ans) cout << ch << "\n";
    

    return 0;
}

Measured memory_bytes: 7500
n, k = gets.split.map(&:to_i)

ps = (1..n).map do |i|
  if i >= k
    1
  else
    p = 1r
    while i < k
      i *= 2
      p /= 2
    end
    p
  end
end

p((ps.reduce(:+) / n).to_f)


Measured memory_bytes: 2684
#[allow(unused_macros)]
macro_rules! scan {
    () => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().to_string()
        }
    };
    (;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().split_whitespace().map(|s| s.to_string()).collect::<Vec<String>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty;;) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty;;$n:expr) => {
        (0..$n).map(|_| scan!($t;;)).collect::<Vec<_>>()
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    scan!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    scan!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let (n, m) = scan!(i64, i64);
    println!("{}", (n + m) % 24);
}


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

typedef long long ll;
 
using tpl = tuple<int, int, int>;
typedef pair<int,int> pii;

void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}

const int mod = 1000000000 + 7;
ll N, M;
ll X[100010];
ll Y[100010];

int main(){

    cin >> N >> M;
    for(int i = 0; i < N; i++) cin >> X[i];
    for(int i = 0; i < M; i++) cin >> Y[i];
    ll base = 0;
    for(int i = 1; i < N; i++){
        (base += (((X[i] - X[i-1]) * i) % mod) * (N - i)) %= mod;
    }
    ll ans = 0;
    for(int i = 1; i < M; i++){
        (ans += ((((base * i) % mod) * (M - i)) % mod) * (Y[i] - Y[i-1])) %= mod;
    }

    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 1792
import java.util.*;

public class Main {
    public static Scanner scanner = new Scanner(System.in);

    public static void main(String[] args) {
        int n = scanner.nextInt();
        int dp[][] = new int[n+1][4];
        int activity[][] = new int[n+1][4];
        for(int i = 1 ; i<=n ; i++){
            for(int j = 1 ; j<=3 ; j++){
                activity[i][j] = scanner.nextInt();
            }
        }
        System.out.println(solve(n,activity,dp));
    }
  public static int solve(int n , int[][] activity , int[][] dp){
        dp[1][1] = activity[1][1];
        dp[1][2] = activity[1][2];
        dp[1][3] = activity[1][3];
        for(int i = 2 ; i<= n ; i++){
            dp[i][1] = activity[i][1] + Math.max(dp[i-1][2] ,dp[i-1][3]);
            dp[i][2] = activity[i][2] + Math.max(dp[i-1][1] , dp[i-1][3]);
            dp[i][3] = activity[i][3] + Math.max(dp[i-1][2] ,dp[i-1][1]);
        }
      return Math.max(Math.max(dp[n][1],dp[n][2]),dp[n][3]);
  }
}




Measured memory_bytes: 102288
#include<iostream>
using namespace std;
int main(){
  int a[5] = {},loss[5]={};
  int i;
  int largeloss = 0,number;
  int sum=0;
  for(i=0;i<5;i++){
    cin >> a[i];
    if(a[i]%10 != 0){
      loss[i] = 10 - a[i]%10;
    }else{
      loss[i] = 0;
    }
    if(largeloss < loss[i]){
      largeloss= loss[i];
      number = i;
    }
  }
  for (i=0;i<5;i++){
    if(i==number){
      sum=sum+a[i];
    }else{
      sum=sum+a[i]+loss[i];
    }
  }
  cout << sum << endl;
  return 0;
}


Measured memory_bytes: 256
//tt89 ;)
#include<bits/stdc++.h>
using namespace std;
//typedef long long ll;
#define int long long
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL);
void testcase(int t) { cout<<"Case #"<<t<<": "; }
void online() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif //ONLINE_JUDGE
}
const int mod= 1e9+7;

signed main() {
    fastIO;
    int n; cin>>n;
    int arr[n];
    for(int i=0;i<n;i++) cin>>arr[i];
    int ans=0,mx=arr[0];

    for(int i=1;i<n;i++) {
        if(mx>arr[i]) ans+= mx-arr[i];
        mx= max(mx,arr[i]);
    }
    cout<<ans;

    return 0;
}

Measured memory_bytes: 5164
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcount
#define ll long long
#define mp make_pair
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define Time (double)clock()/CLOCKS_PER_SEC
const int N = 501;
int ans[N * N];
ii a[N];
signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif         
    for (int i = 0; i < N * N; ++i) ans[i] = -1;
    int n; cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i].f; a[i].s = i;
        --a[i].f; ans[a[i].f] = i + 1;
    }   
    sort(a, a + n);
    int ptr = 0;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < a[i].s; ++j) {
            while (ans[ptr] != -1) ++ptr;
            if (ptr > a[i].f) {
                cout << "No\n";
                exit(0);
            }
            ans[ptr] = a[i].s + 1;
        }   
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n - a[i].s - 1; ++j) {
            while (ans[ptr] != -1) ++ptr;
            if (ptr < a[i].f) {
                cout << "No\n";
                exit(0);
            }
            ans[ptr] = a[i].s + 1;
        }   
    }   
    cout << "Yes\n";
    for (int i = 0; i < n * n; ++i) cout << ans[i] << ' '; cout << '\n';    
}

Measured memory_bytes: 3200
from collections import deque
n, m = map(int, input().split())
dat = deque([])
dat2 = deque([])
dat_finish = [False] * (n + 1)

for i in range(m):
    a, b = map(int, input().split())
    dat.append((a, b))
    dat2.append((a, b))

for i in range(m):
    a, b = dat.pop()
    if b == n:
        dat_finish[a] = True

c = False
for i in range(m):
    a, b = dat2.pop()
    if a == 1:
        if dat_finish[b]:
            c = True

print("POSSIBLE" if c else "IMPOSSIBLE")


Measured memory_bytes: 61144
// #pragma GCC optimize(3, "Ofast", "inline")
#include <bits/stdc++.h>
#define String std::string
#define fir first
#define sec second
#define mp std::make_pair
#define Pair std::pair<int, int>
#define Map std::map< int, int >
#define Vector std::vector<int>

typedef long long ll;
typedef unsigned long long ull;

const int N = 300 + 5;
const int MOD = 1e9 + 7;
const int dx[] = { 0, 1, -1, 0, 1, -1, 1, -1 };
const int dy[] = { 1, 0, 0, -1, 1, -1, -1, 1 };

inline int read() {
    int res = 0, f = 1;
    char ch = getchar();
    for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
    for (; isdigit(ch); ch = getchar()) res = (res << 1) + (res << 3) + ch - '0';
    return res * f;
}

int n, m, L;
ll dist[N][N], ans[N][N];

inline void floyd1() {
    for (int k = 1; k <= n; k++) {
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                ll tmp = 0;
                if (dist[i][k] == LLONG_MAX || dist[k][j] == LLONG_MAX) tmp = LLONG_MAX;
                else tmp = dist[i][k] + dist[k][j];
                dist[i][j] = std::min(dist[i][j], tmp);
            }
        }
    }
}

inline void floyd2() {
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            if (dist[i][j] <= L) ans[i][j] = 1;
            else ans[i][j] = LLONG_MAX;
        }
        ans[i][i] = 0;
    }

    for (int k = 1; k <= n; k++) {
        for (int i = 1; i <= n; i++) {
            for (int j = 1; j <= n; j++) {
                ll tmp = 0;
                if (ans[i][k] == LLONG_MAX || ans[k][j] == LLONG_MAX) tmp = LLONG_MAX;
                else tmp = ans[i][k] + ans[k][j];
                ans[i][j] = std::min(ans[i][j], tmp);
            }
        }
    }
}

int main() {
    std::cin >> n >> m >> L;
    for (int i = 1; i <= n; i++) {
        for (int j = 1; j <= n; j++) {
            dist[i][j] = LLONG_MAX;
        }
        dist[i][i] = 0;
    }
    for (int i = 1; i <= m; i++) {
        int a, b, c;
        scanf("%d %d %d", &a, &b, &c);
        dist[a][b] = dist[b][a] = c;
    }
    floyd1();
    floyd2();
    // int q = read();
    int q;
    scanf("%d", &q);
    while (q--) {
        int s, t;
        scanf("%d %d", &s, &t);
        // printf("%d\n", ans[s][t] == LLONG_MAX ? -1 : ans[s][t] - 1);
        if (ans[s][t] == LLONG_MAX) puts("-1");
        else printf("%lld\n", ans[s][t] - 1);
    }
    return 0;
}

Measured memory_bytes: 1920
#include <stdio.h>

int main(void)
{
	int m;
	int f;
	int r;
	int sum;

	while(1)
	{
		m = 0;
		f = 0;
		r = 0;
		sum = 0;
		scanf("%d %d %d", &m, &f, &r);
		if(m == -1 && f == -1 && r == -1)
		{
			break;
		}
		
		sum = m + f;
		
		if(m == -1 || f == -1)
		{
			printf("F\n");
		}
		else if(sum >= 80)
		{
			printf("A\n");
		}
		else if(sum >= 65 && sum < 80)
		{
			printf("B\n");
		}
		else if(sum >= 50 && sum < 65)
		{
			printf("C\n");
		}
		else if(sum >= 30 && sum < 50)
		{
			if(r >= 50)
			{
				printf("C\n");
			}
			else
			{
				printf("D\n");
			}
		}
		else if(sum < 30)
		{
			printf("F\n");
		}
	}

	return 0;
}

Measured memory_bytes: 584
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()


using namespace std;

typedef long long ll;

static const long long MOD = 1000000007;

int ans;
int N, M;


int main(void) {
    scanf("%d %d", &N, &M);
   

  
    if (N == M) puts("Yes");
    else puts("No");

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
    int a,b;
    char op;

while(1){
    scanf("%d %c %d",&a,&op,&b);
    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); 
    }else if(op=='?'){
      break; 
    }
}
    return 0 ;
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

int main(void)
{
    IOS
    int n; cin >> n;
    map<int,int> m;
    REP(i,n) {
        int x;
        cin >> x;
        m[x]++;
    }

    priority_queue<int> pq;
    for(auto p:m) {
        // cerr << p.second << endl;
        pq.push(p.second);
    }
    // cerr << endl;
    while(pq.top() != 1) {
        int t = pq.top(); pq.pop();
        // cerr << t << endl;
        if (t > 2) {
             t = t % 2 == 0 ? 2 : 1;
            pq.push(t);
        } else { 
            int s = pq.top(); pq.pop();
            if (s == 2) { // 2 2 -> 1 1
                REP(i,2) pq.push(1);
            } else pq.push(1); // 2 1 -> 0 1
        }
    }

    cout << pq.size() << endl;

    return 0;
}

Measured memory_bytes: 5632
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
using namespace std;
const double PI = acos(-1.0);
const string alp = "abcdefghijklmnopqrstuvwxyz";
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define REP1(i,n) FOR(i,1,n+1)
#define SUM(c) accumulate((c).begin(),(c).end(),0)
#define UNIQ(c) (c).erase(unique((c).begin(), (c).end()), (c).end());
#define Yn(b) puts(b?"Yes":"No")
#define YN(b) puts(b?"YES":"NO")

bool isprime(int p) {
  if (p==1) return false;
    FOR(i,2,p) {
      if (p%i==0) return false;
    }
  return true;
}

int main(){
  int n,m,t,a[100010];
  cin >> n;
  m=0;
  t=0;
  a[0]=0;
  REP1(i,n){
    cin >> a[i];
    t+=abs(m-a[i]);
    m=a[i];
  }
  a[n+1]=0;
  t+=abs(m);
  REP1(i,n){
    cout << t-abs(a[i-1]-a[i])-abs(a[i]-a[i+1])+abs(a[i-1]-a[i+1]) << endl;
  }
  return 0;
}

Measured memory_bytes: 1664
#include<iostream>
    using namespace std;
    int main(){
    int c[9],i;
    for(i=0;i<9;i++){
     cin>>c[i];
    }
    if((c[1]-c[0]==c[4]-c[3])&&(c[4]-c[3]==c[7]-c[6])&&(c[2]-c[0]==c[5]-c[3])&&(c[5]-c[3]==c[8]-c[6])&&(c[2]-c[1]==c[5]-c[4])&&(c[5]-c[4]==c[8]-c[7])&&(c[0]-c[3]==c[1]-c[4])&&(c[1]-c[4]==c[2]-c[5])&&(c[0]-c[6]==c[1]-c[7])&&(c[1]-c[7]==c[2]-c[8])&&(c[3]-c[6]==c[4]-c[7])&&(c[4]-c[7]==c[5]-c[8])) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
    }

Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <numeric>
#include <algorithm>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

typedef pair<int, int> P;

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

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

    if(n == 3){
        cout << "2 5 63" << endl;
        return 0;
    }
    if(n == 4){
        cout << "2 5 20 63" << endl;
        return 0;
    }
    if(n == 5){
        cout << "2 5 20 30 63" << endl;
        return 0;
    }

    vector<int> ans;
    int i;
    for(i = 0; i < 5000; i++){
        ans.push_back(6 * i + 2);
        ans.push_back(6 * i + 3);
        ans.push_back(6 * i + 4);
        ans.push_back(6 * i + 6);
    }

    ans.erase(ans.begin()+n, ans.end());

    int sum = 0;
    rep(i, (int)ans.size()) sum += ans[i];

    //2 3 4 6 8 9 10 12
    if(sum % 6 == 2){
        ans.erase(ans.begin() + 4);
        ans.push_back(30000);
    }
    if(sum % 6 == 3){
        ans.erase(ans.begin() + 5);
        ans.push_back(30000);
    }
    if(sum % 6 == 5){
        ans.erase(ans.begin() + 5);
        ans.push_back(29998);
    }

    for(int i = 0; i < (int)ans.size() - 1; i++){
        cout << ans[i] << " ";
    }
    cout << ans[ans.size()-1] << endl;

    return 0;
}


Measured memory_bytes: 640