akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <math.h>
#include <vector>
using namespace std;

typedef long long ll;
const int MAXN = 1e5 + 10;
int N;
int fa[MAXN];
struct Node {
	int x, y, i;
} A[MAXN];
struct Edge {
	int x, y, d;
};
vector<Edge> E;
ll ans;

inline int gf(int x) {
	return x == fa[x] ? x : fa[x] = gf(fa[x]);
}

int main() {
	register int i;
	scanf("%d", &N);
	for(i = 1; i <= N; ++i)
		scanf("%d%d", &A[i].x, &A[i].y), A[i].i = i, fa[i] = i;
	sort(A + 1, A + N + 1, [&](Node x, Node y) {return x.x < y.x;});
	for(i = 1; i < N; ++i)
		E.emplace_back((Edge) {A[i].i, A[i + 1].i, A[i + 1].x - A[i].x});
	sort(A + 1, A + N + 1, [&](Node x, Node y) {return x.y < y.y;});
	for(i = 1; i < N; ++i)
		E.emplace_back((Edge) {A[i].i, A[i + 1].i, A[i + 1].y - A[i].y});
	sort(E.begin(), E.end(), [&](Edge x, Edge y) {return x.d < y.d;});
	for(auto e: E) {
		int x = gf(e.x), y = gf(e.y);
		if(x != y) ans += e.d, fa[x] = y;
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 6260
import std.stdio;
import std.algorithm;
import std.utf;
import std.string;

void main() {
  auto s = readln.chomp.toUTF32.dup;
  auto t = readln.chomp.toUTF32.dup;

  s.sort!"a < b";
  t.sort!"a > b";
  
  if (s < t) {
    writeln("Yes");
  } else {
    writeln("No");
  }
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,b,e) for(int i = (b); i <= (e); i++)

#define pr(x) do{cerr << (#x) << " = " << (x) << endl;}while(0)
#define pri(x,i) do{cerr << (#x) << "[" << i << "] = " << (x[i]) << endl;}while(0)

namespace std {
	template<class S, class T> pair<S, T> operator + (const pair<S, T> &a, const pair<S, T> &b) {return mp<S, T>(a.first + b.first, a.second + b.second);}
	template<class S, class T> pair<S, T> operator - (const pair<S, T> &a, const pair<S, T> &b) {return mp<S, T>(a.first - b.first, a.second - b.second);}
	template<class S, class T> pair<S, T>& operator += (pair<S, T> &a, const pair<S, T> &other) {return a = a + other;}
	template<class S, class T> pair<S, T>& operator -= (pair<S, T> &a, const pair<S, T> &other) {return a = a - other;}
	template<class S, class T> ostream& operator << (ostream& ost, pair<S, T> p) {ost << "(" << p.first << ", " << p.second << ")";return ost;}
	template<class T> ostream& print_iterable_container(ostream& ost, T& container) {
		for (auto&& iter = begin(container); iter != end(container); ++iter) ost << (iter == begin(container) ? " [ " : ", ") << (*iter);
		return ost << " ]";
	}
#	define APPLY_PRINT_ITERABLE_CONTAINER(container_type)\
	template<class T> ostream& operator << (ostream& ost, container_type<T>& container) {\
		return print_iterable_container(ost, container);\
	}
	APPLY_PRINT_ITERABLE_CONTAINER(vector);
	APPLY_PRINT_ITERABLE_CONTAINER(list);
	APPLY_PRINT_ITERABLE_CONTAINER(deque);
}

template<class T> inline bool CHMAX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool CHMIN(T &l,const T &r){return l>r?l=r,1:0;}

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vpii = vector<pii>;
using vpll = vector<pll>;

using ld = long double;

template<class T> using VV = vector<vector<T> >;
template<class T> using maxPQ = priority_queue<T>;
template<class T> using minPQ = priority_queue<T, vector<T>, greater<T> >;
template<class T, class U> using uomap = unordered_map<T, U>;
template<class T> using uoset = unordered_set<T>;

const ll INF = 1001001001;
const ll INFll = (ll)INF * INF;
const ll MOD = 1000000007;
const ll MOD_FFT = 998244353;
const ld EPS = 1e-15;

//function<void(int,int)> tensi_no_3p=[&](int v,int d){
//};

int main() {
	string S; cin >> S;
	ll ans = 0;
	ll nb = 0;
	rep(i, S.size()) {
		if (S[i] == 'B') {
			nb++;
		}
		else {
			ans += nb;
		}
	}
	cout << ans << endl;
	return 0;
}


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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define set0(k,n) for(int nn=0;nn<(n);nn++){ (k).push_back(0); }
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define vecsize(b,size) vector<int> (b)((size));
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsl(s) vector<pair<ll,ll>> (s);
#define pairss(s) vector<pair<string,string>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairspl(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsps(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define pairsREV(s) (s).push_back(make_pair(bb,aa));
#define pairslREV(s) (s).push_back(make_pair(bb,aa));
#define pairssREV(s) (s).push_back(make_pair(bb,aa));
#define MOD 1000000007

int main()
{
	int N;
	cin >> N;
	vecl(A)
	fx(N) {
		vecpl(A)
	}

	int B[100000];
	int C[100000];
	B[0] = 0;
	C[0] = 0;
	for (int n = 0; n < N;n++) {
		if (n % 2 == 0) {
			B[n + 1] = B[n] + A.at(n);
			C[n + 1] = C[n] - A.at(n);
		}
		else {
			B[n + 1] = B[n] - A.at(n);
			C[n + 1] = C[n] + A.at(n);
		}
	}
	fx(N) {
		if (x % 2 == 0) {
			cout << (B[N]- B[x] + C[x]);
		}
		else {
			cout << (C[N] - C[x] + B[x]);
		}

		if (x != N - 1) {
			cout << ' ';
		}
		else {
			cout << endl;
		}
	}
		
    return 0;
}



Measured memory_bytes: 3060
#include <stdio.h>
static char s[1001];
int main(void) {
    char *p;
    int sum;
    while (1) {
        scanf("%s", s);
        if (*s == '0') break;
        p = s;
        sum = 0;
        while (*p) sum += *p++ & 0x0f;
        printf("%d\n", sum);
    }
    return 0;
}

Measured memory_bytes: 536
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, _s, n) for(int i = _s, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
using namespace std;

#define repi(itr, ds) for(auto itr = ds.begin(); itr != ds.end(); itr++)
// vector
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for(T &x : vec) is >> x;
  return is;
}
// pair
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
  os << "(" << pair_var.first << ", " << pair_var.second << ")";
  return os;
}
// vector
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "{";
  for(int i = 0; i < vec.size(); i++) {
    os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
  }
  os << "}\n   ";
  return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
  os << "{";
  repi(itr, map_var) {
    os << *itr;
    itr++;
    if(itr != map_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}
// set
template <typename T>
ostream &operator<<(ostream &os, set<T> &set_var) {
  os << "{";
  repi(itr, set_var) {
    os << *itr;
    itr++;
    if(itr != set_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}

#define DUMPOUT cerr

void dump_func() { DUMPOUT << endl; }
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&... tail) {
  DUMPOUT << head;
  if(sizeof...(Tail) > 0) {
    DUMPOUT << ", ";
  }
  dump_func(std::move(tail)...);
}
#ifdef DEBUG_
#define DEB
#define dump(...)                                                             \
  DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                             \
          << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \
          << "    ",                                                          \
      dump_func(__VA_ARGS__)
#else
#define DEB if(false)
#define dump(...)
#endif

typedef long long int ll;
const int MOD = 1e9 + 7;
const int INF = 1e9;

int main() {
  string S;
  cin >> S;
  auto cnt = vector<int>(3, 0);
  for(auto c : S) {
    cnt[c - 'a']++;
  }
  int diff = max(cnt[0], max(cnt[1], cnt[2])) - min(cnt[0], min(cnt[1], cnt[2]));
  if(diff >= 2) {
    cout << "NO" << endl;
  } else {
    cout << "YES" << endl;
  }
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for (int (i) = 0; (i) < (n); i++)
#define ll long long
using namespace std;
int main() {
  string S; cin >> S;
  bool a = true;
  for(ll i = 0; i < S.size();i += 2){
    if(S[i] == 'L'){
      a = false;
    }
  }
  for(ll i = 1; i < S.size();i += 2){
    if(S[i] == 'R'){
      a = false;
    }
  }
  if(a){
    cout << "Yes";
  }
  else{
    cout << "No";
  }
}

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

using namespace std;

int N, t[1009], dp[1009], x[1009], ruk[5009], old[5009];
vector < int > v[1009];

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d", &N);
for (int i=2; i<=N; i++)
    scanf ("%d", &t[i]), v[t[i]].push_back (i);
for (int i=1; i<=N; i++)
    scanf ("%d", &x[i]);
for (int i=N; i>=1; i--)
{
    if (v[i].empty ())
    {
        dp[i] = 0;
        continue;
    }
    for (int j=1; j<=x[i]; j++)
        ruk[j] = 1 << 30;
    ruk[0] = 0;
    for (auto f : v[i])
    {
        ///choose between adding x[f] or dp[f]
        memcpy (old, ruk, sizeof (ruk));
        for (int j=0; j<=x[i]; j++)
        {
            ruk[j] = 1 << 30;
            if (j >= x[f] && old[j - x[f]] + dp[f] < ruk[j])
                ruk[j] = old[j - x[f]] + dp[f];
            if (j >= dp[f] && old[j - dp[f]] + x[f] < ruk[j])
                ruk[j] = old[j - dp[f]] + x[f];
        }
    }
    dp[i] = 1 << 30;
    for (int j=0; j<=x[i]; j++)
        if (ruk[j] < dp[i])
            dp[i] = ruk[j];
    if (dp[i] == (1 << 30))
    {
        printf ("IMPOSSIBLE\n");
        return 0;
    }
}
printf ("POSSIBLE\n");
return 0;
}


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

template <class T>
T Vec(T v) { return v; }

template <class T, class... Ts>
auto Vec(size_t l, Ts... ts) {
    return std::vector<decltype(Vec<T>(ts...))>(l, Vec<T>(ts...));
}

int main() {
    int H, W;
    std::cin >> H >> W;
    auto S = Vec<int>(H, W, 0);
    for (auto& s : S) {
        for (auto& c : s) std::cin >> c;
    }

    auto dp = Vec<int>(H, W, 0);
    for (int x = 0; x < H; ++x) {
        for (int y = 0; y < W; ++y) {
            if (x == 0 || y == 0 || S[x][y] == 1) {
                dp[x][y] = 1 - S[x][y];
                continue;
            }

            dp[x][y] = dp[x - 1][y] + 1;
            for (int dx = 0; dx < 2; ++dx) {
                dp[x][y] = std::min(dp[x][y], dp[x - dx][y - 1] + 1);
            }
        }
    }

    int ans = 0;
    for (auto& v : dp) {
        ans = std::max(ans,
                       *std::max_element(v.begin(), v.end()));
    }
    std::cout << ans * ans << std::endl;
    return 0;
}



Measured memory_bytes: 18096
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repf(i,a,b) for (int i = (a); i < (b); i++)
#define repi(i,a,b) for (int i = (a); i <= (b); i++)
#define repr(i,a,b) for (int i = (a); i >= (b); i--)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(all(x));
#define RSORT(x) sort(rall(x));
using namespace std;
using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vi>;
using vd = vector<double>;
using vb = vector<bool>;
using pii = pair<int, int>;
using vc = vector<char>;
using vvc = vector<vc>;
using vs = vector<string>;
using tiii = tuple<int, int, int>;
const ll inf = 1ll<<29;
const ll mod = 1000000007;
const double eps = 1e-9;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};

int main() {
  ll L, R; cin >> L >> R;

  R = min(R,L+673);
  ll ans = inf;
  for(ll i=L; i<=R-1; i++) {
    for(ll j=i+1; j<=R; j++) {
      ans = min(ans, (i*j)%2019);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
N = int(input())
K = int(input())
balls = [int(i) for i in input().split()]

def calcDist(ball):
    robot_A_dist = abs(0-ball)
    robot_B_dist = abs(K-ball)
    if robot_A_dist <= robot_B_dist:
        return robot_A_dist * 2
    else :
        return robot_B_dist * 2
    
cnt = 0    
for ball in balls:
    cnt += calcDist(ball)
    
print(cnt)

Measured memory_bytes: 3060
import java.util.Scanner;
class Main{
    static public void  main(String[] av){

        Scanner sc =new Scanner(System.in);
        int a =sc.nextInt();
        int b =sc.nextInt();
if( b >a){
    int t = a;
    a=b;
    b=t;
}
int sum=0;
        while (a%b!=0){
            int t;
t=a%b;
a=b;
b=t;
    }




System.out.println(b);       
    }
    
}


Measured memory_bytes: 26388
#include <bits/stdc++.h>
using namespace std;
int N;
string s, t;
int solve() {
  for (int i = 0; i < N; ++i) {
    if (s.substr(i) == t.substr(0, N-i)) return i + N;
  }
return N*2;
}

int main() {
  cin >> N >> s >> t;
  cout << solve() << endl;
}

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

class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String[] strs = br.readLine().split(" ");
    int A = Integer.parseInt(strs[0]);
    int B = Integer.parseInt(strs[1]);
    
    System.out.println((A-1)*(B-1));
  }
}

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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll INF = 1e18;
    
    ll v,e,r;
    cin >> v >> e >> r;

    vector<vector<pair<ll,ll>>> graph(v);
    for(i = 0;i < e;++i){
        ll s,t,d;
        cin >> s >> t >> d;
        graph.at(s).emplace_back(d, t);
        //graph.at(t).emplace_back(d, s);
    }

    priority_queue<pair<ll,ll>> pq;
    vector<ll> vdist(v,INF);
    ll top = r;
    vdist.at(top) = 0;
    pq.emplace(0, top);
    while(!pq.empty()){
        auto x = pq.top();
        pq.pop();
        ll now = x.second;
        ll dist = -x.first;
        if(vdist.at(now) < dist) continue;
        for(i = 0;i < graph.at(now).size();++i){
            ll next = graph.at(now).at(i).second;
            ll nd = dist + graph.at(now).at(i).first;
            if(vdist.at(next) > nd){
                vdist.at(next) = nd;
                pq.emplace(-nd, next);
            }
        }
    }
    for(i = 0;i < v;++i){
        if(vdist.at(i) == INF) cout << "INF" << endl;
        else cout << vdist.at(i) << endl;
    }

    return 0;
}


Measured memory_bytes: 19352
#include <cstdio>

void rec(int i, int j)
{
  if (j == 10) return;

  printf("%dx%d=%d\n", i, j, i * j);
  rec(i, j + 1);
}

signed main(void)
{
  for (int x = 1; x < 10; x++) rec(x, 1);
}

Measured memory_bytes: 2684
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define RS(x) rsort(x.begin(),x,end()))
#define REVE(x) reverse(x.begin(), x.end())
#define ALL(x) (x).begin(), (x).end()
int INF = 1e9 + 1;
int MOD = 1e9+7;
struct initon
{
    initon()
    {
        cin.tie(0);
        ios::sync_with_stdio(false);
    };
};
signed main(){
    string s,t,u;
    int a,b;
    
cin >> s >> t >> a >> b >>u;
if(s==u)cout << a-1 << ' ' <<b;
else cout << a << ' ' <<b-1;
}

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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)
#define mod 1000000007

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

    if(a+b==15){
        cout<<'+'<<endl;
    }
    else if (a*b==15) {
        cout<<'*'<<endl;
    }
    else {
        cout<<'x'<<endl;
    }

}



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

int main(void){
    string s;
    int n = 0;
    cin >> s;
    for(int i = 0;i < s.size();i++)if(s[i] == 'x')n++;
    if(n >= 8)cout << "NO";
    else cout << "YES";
}

Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, const char * argv[]) {
    char a[100],b[100],T;
    int i,I=0,J=0,count=0,t=0;
    
    
    
    while(1){
        scanf("%c",&a[I]);
        if(a[I]=='\n') break;
        I++;
    }
    
    while(1){
        scanf("%c",&b[J]);
        if(b[J]=='\n') break;
        J++;
    }
    
    while(count!=J){
        
        count=0;
        for(i=0;i<J;i++){
            if(a[i]==b[i]) count++;
            else count--;
        }
        
        if(count!=J){
            for(i=0;i<I;i++){
                if(i==0) T=a[0];
                a[i]=a[i+1];
                if(i==I-1)  a[I-1]=T;
            }
            
            t++;
            if(t==100) break;
            
        }
    }
    if(count==J) printf("Yes\n");
    else printf("No\n");
    
    
    return 0;
}


Measured memory_bytes: 2104
fun main(arr: Array<String>) {
    val (n,l) = readLine()!!.split(" ").map { it.toInt() }
    val apples = (0 until n).map { l + it }
    val total = apples.sum()
    val ans = total - apples.sortedBy { Math.abs(it) }.first()
    println(ans)
}


Measured memory_bytes: 39424
#import<cstdio>
int a,b,c,n,s,x,y,z;
main()
{
scanf("%d%d%d%d",&a,&b,&c,&n);
for(;x*a<=n;x++)for(y=0;x*a+y*b<=n;y++)s+=(n-x*a-y*b)%c<1;
printf("%d",s);
}

Measured memory_bytes: 128
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <cstring>
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>
#include <numeric>
#include <float.h>
using namespace std;
// repマクロの定義
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
// allマクロの定義
#define all(v) v.begin(), v.end()
typedef unsigned long long ll;
// 最大公約数求める関数
int my_gcd(int n , int m){
  if(n < m){
    int tmp = n;
    n = m;
    m = tmp;
  }
  int l  = n % m;
  while(l != 0){
    n = m;
    m = l;
    l = n % m;
}
return m;
}

//char⇒int関数
 int ctoi(char c) {
 	switch (c) {
		case '0': return 0;
		case '1': return 1;
		case '2': return 2;
		case '3': return 3;
		case '4': return 4;
		case '5': return 5;
		case '6': return 6;
		case '7': return 7;
		case '8': return 8;
		case '9': return 9;
		default: return 0;
	}
}



int main(){
string S,T; cin >> S >> T;
T.erase(T.size()-1);
if(S == T) cout <<"Yes" << endl;
else cout << "No" << endl;

}


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

constexpr int MOD = 1000000007;
// constexpr int MOD = 998244353;
constexpr int MAX = 2000000;

vector<long> fact(MAX), finv(MAX), inve(MAX);

void init() {
  fact.at(0) = fact.at(1) = 1;
  finv.at(0) = finv.at(1) = 1;
  inve.at(1) = 1;
  for (int i = 2; i < MAX; i++) {
    fact.at(i) = fact.at(i - 1) * i % MOD;
    inve.at(i) = MOD - inve.at(MOD % i) * (MOD / i) % MOD;
    finv.at(i) = finv.at(i - 1) * inve.at(i) % MOD;
  }
}

long com(long n, long r) {
  if (n < r || n < 0 || r < 0) return 0;
  return fact.at(n) * (finv.at(r) * finv.at(n - r) % MOD) % MOD;
}

long mpow(long a, long b) {
  long res = 1;
  while (b > 0) {
    if (b & 1) res = res * a % MOD;
    a = a * a % MOD;
    b >>= 1;
  }
  return res;
}

int main() {
  init();
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int K;
  string S;
  cin >> K >> S;
  int N = S.size();
  K += N;
  long ans = 0;
  for (int i = N; i <= K; i++) {
    long tmp = com(i - 1, N - 1);
    (tmp *= mpow(25, i - N)) %= MOD;
    (tmp *= mpow(26, K - i)) %= MOD;
    (ans += tmp) %= MOD;
  }
  cout << ans << "\n";
}

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

template <int mod = (int)(998244353)>
struct ModInt {
  int x;
  ModInt() : x(0) {}
  ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
  ModInt &operator+=(const ModInt &p) {
    if ((x += p.x) >= mod) x -= mod;
    return *this;
  }
  ModInt &operator-=(const ModInt &p) {
    if ((x += mod - p.x) >= mod) x -= mod;
    return *this;
  }
  ModInt &operator*=(const ModInt &p) {
    x = (int)(1LL * x * p.x % mod);
    return *this;
  }
  ModInt &operator/=(const ModInt &p) {
    *this *= p.inverse();
    return *this;
  }
  ModInt operator-() const { return ModInt(-x); }
  ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
  ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
  ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
  ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
  bool operator==(const ModInt &p) const { return x == p.x; }
  bool operator!=(const ModInt &p) const { return x != p.x; }
  ModInt inverse() const {
    int a = x, b = mod, u = 1, v = 0, t;
    while (b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }
  ModInt pow(int64_t n) const {
    ModInt res(1), mul(x);
    while (n) {
      if (n & 1) res *= mul;
      mul *= mul;
      n >>= 1;
    }
    return res;
  }
  friend ostream &operator<<(ostream &os, const ModInt &p) { return os << p.x; }
  friend istream &operator>>(istream &is, ModInt &a) {
    int64_t t;
    is >> t;
    a = ModInt<mod>(t);
    return (is);
  }
  static int get_mod() { return mod; }
};

struct Combination {
  vector<ModInt<>> _fact, _rfact, _inv;
  Combination(long long nsize = 5000000)
      : _fact(nsize + 1), _rfact(nsize + 1), _inv(nsize + 1) {
    _fact[0] = _rfact[nsize] = _inv[0] = 1;
    for (int i = 1; i <= nsize; i++) _fact[i] = _fact[i - 1] * i;
    _rfact[nsize] /= _fact[nsize];
    for (int i = nsize - 1; i >= 0; i--) _rfact[i] = _rfact[i + 1] * (i + 1);
    for (int i = 1; i <= nsize; i++) _inv[i] = _rfact[i] * _fact[i - 1];
  }
  inline ModInt<> fact(int k) const { return _fact[k]; }

  inline ModInt<> rfact(int k) const { return _rfact[k]; }

  inline ModInt<> inv(int k) const { return _inv[k]; }

  ModInt<> P(int n, int r) const {
    if (r < 0 || n < r) return 0;
    return fact(n) * rfact(n - r);
  }

  ModInt<> C(int p, int q) const {
    if (q < 0 || p < q) return 0;
    return fact(p) * rfact(q) * rfact(p - q);
  }
  // n types,choose r
  ModInt<> H(int n, int r) const {
    if (n < 0 || r < 0) return (0);
    return r == 0 ? 1 : C(n + r - 1, r);
  }
};

long long n, m, k;
Combination com;

ModInt<> solve();

int main() {
  cin >> n >> m >> k;
  cout << solve() << endl;
  return 0;
}

ModInt<> solve() {
  ModInt<> res = 0;
  for (int i = 0; i <= k; ++i) {
    ModInt<> now = m;
    now *= ModInt<>(m - 1).pow(n - 1 - i) * com.C(n - 1, i);
    res += now;
  }
  return res;
}

Measured memory_bytes: 61676
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int p = sc.nextInt();
        int ans = (a * 3 + p) / 2;
        System.out.println(ans);
        sc.close();
    }
}

Measured memory_bytes: 23252
N = int(input())
array = list(map(int, input().split()))
cnt = 0 
for i in range(N):
	minij = i 
	for j in range(i, N):
		if array[j] < array[minij]:
			minij = j 
	if minij != i:
		array[i], array[minij] = array[minij], array[i]
		cnt += 1

print(' '.join(map(str, array)))
print( "%d" % (cnt))



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

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

const int INF = 1001001001;
const vector<int> di = {-1,  0, 1, 0};
const vector<int> dj = { 0, -1, 0, 1};

void chmin(int &a, int b) { if (a > b) a = b; }

ll GCD(ll a, ll b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
ll LCM(ll a, ll b) { return a * b / GCD(a, b); }


int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    int cnt = 0;
    int zeros = 0;
    rep(i, N) {
        int a;
        cin >> a;
        if (a == 0) zeros++;
        if (a < 0) cnt++;
        A[i] = abs(a);
    }
    ll ans = 0;
    if (cnt % 2 == 0 || zeros > 0) {
        rep(i, N) ans += A[i];
    } else {
        sort(all(A));
        for (int i=1;i<N;i++) ans += A[i];
        ans -= A[0];
    }

    cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
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;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

int D, contests[370];
lint c[30], s[370][30];
set<int> held_days[30];

lint get_score(int dd){
    For(i, 1, 27){
        held_days[i].clear();
        held_days[i].insert(0);
        held_days[i].insert(D+1);
    }
    lint ret = 0;
    For(day, 1, dd+1){
        For(i, 1, 27){
            if(contests[day] == i){
                ret += s[day][i];
                held_days[i].insert(day);
            }
            else ret -= c[i] * (day - *next(held_days[i].rbegin()));
        }
    }
    return ret;
}

lint fsum(int n){
    return n*(n+1)/2;
}

lint score_diff(int day, int idx){
    lint ret = 0;
    int prev_id = contests[day];
    contests[day] = idx;

    ret += s[day][idx];
    auto r = held_days[idx].lower_bound(day), l = prev(r);
    ret += c[idx] * fsum(*r-1-*l);
    ret -= c[idx] * (fsum(day-1-*l) + fsum(*r-1-day));
    held_days[idx].insert(day);

    ret -= s[day][prev_id];
    auto m = held_days[prev_id].find(day);
    r = next(m); l = prev(m);
    ret += c[prev_id] * (fsum(day-1-*l) + fsum(*r-1-day));
    ret -= c[prev_id] * fsum(*r-1-*l);
    held_days[prev_id].erase(day);

    return ret;
}

void input(){
    scanf("%d", &D);
    For(i, 1, 27) scanf("%lld", &c[i]);
    For(i, 1, D+1)For(j, 1, 27) scanf("%lld", &s[i][j]);
}

void output(){
    For(i, 1, D+1) printf("%d\n", contests[i]);
}

int main(){
    input();

    For(i, 1, D+1) contests[i] = 1;
    lint score = get_score(D);

    output();
}

Measured memory_bytes: 3920
#include <stdio.h>

int main(void){
	int a[10],t,i,b[5],l;

	while(1){
		scanf("%d %d",&a[0],&a[5]);
		if((a[0]==0)&&(a[5]==0)){
			return 0;
		}
		for(t=1;t<5;t++){
			scanf("%d %d",&a[t],&a[5+t]);
		}
		for(t=0;t<5;t++){
			a[t]+=a[t+5];
			b[t]=t;
		}
		for(t=0;t<4;t++){
			for(i=1;i<5-t;i++){
				if(a[i-1]<a[i]){
					l=a[i-1];
					a[i-1]=a[i];
					a[i]=l;
					l=b[i-1];
					b[i-1]=b[i];
					b[i]=l;
				}
			}
		}
		if(b[0]==0){
			printf("A ");
		}
		if(b[0]==1){
			printf("B ");
		}
		if(b[0]==2){
			printf("C ");
		}
		if(b[0]==3){
			printf("D ");
		}
		if(b[0]==4){
			printf("E ");
		}
		printf("%d\n",a[0]);
	}
}

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

int main() {
	char c1[4], c2[4]; cin >> c1 >> c2;

	if (c1[0] == c2[2] && c1[2] == c2[0] && c1[1] == c2[1]) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.Map.Entry;

import java.util.PriorityQueue;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {
	
	public static void main(String[] args) throws IOException {
		try(final Scanner sc = new Scanner(System.in)){
			final int N = sc.nextInt();
			
			int cnt = 0;
			for(int i = 1; i <= N; i++) {
				cnt += (i + "").length() % 2;
			}
			
			System.out.println(cnt);
			
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}

Measured memory_bytes: 34516
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()

using namespace std;

int main() {
  string S;
  cin >> S;
  int ret = 0, tmp = 0;
  for (char c : S) {
    if (c == 'A' || c == 'C' || c == 'G' || c == 'T') tmp++;
    else {
      ret = max(ret, tmp);
      tmp = 0;
    }
  }
  cout << max(ret, tmp) << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
/*
using ll = long long;
using P = pair<int, int>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
*/

int to[105][105];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<vector<int> > G(n);
    rep(i,n){
        int u, k;
        cin >> u >> k;
        u--;
        rep(j,k){
            int v;
            cin >> v;
            v--;
            to[u][v] = 1;
        }
    }
    vector<int> dist(n, -1);
    queue<int> que;
    dist[0] = 0;
    que.push(0);
    while(!que.empty()){
        int v = que.front();
        que.pop();
        rep(nv,n){
            if(!to[v][nv]) continue;
            if(dist[nv] != -1) continue;
            dist[nv] = dist[v] + 1;
            que.push(nv);
        }
    }
    rep(i,n) cout << i+1 << " " << dist[i] << endl;
    return 0;
}


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

int main(){
  int n,a,flag=1;
  cin >> n;
  
  for(int i=0; i<n; i++){
    cin >>a;
    if(a%2==0 && (a%3!=0 && a%5!=0)){
      flag=0;
      break;
    }
  }
  if(flag)
    cout << "APPROVED" << endl;
  else 
    cout << "DENIED" << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using u32 = unsigned int;
using u64 = unsigned long long;
using u128 = __uint128_t;

template<class Int, class ModMul>
bool is_prime_impl(const Int &n, const Int *witness, ModMul modmul) {
    if (n == 2) return true;
    if (n < 2 || n % 2 == 0) return false;
    const Int m = n - 1, d = m / (m & -m);
    auto modpow = [&](Int a, Int b) {
        Int res = 1;
        for (; b; b /= 2) {
            if (b & 1) res = modmul(res, a);
            a = modmul(a, a);
        }
        return res;
    };
    auto suspect = [&](Int a, Int t) {
        a = modpow(a, t);
        while (t != n - 1 && a != 1 && a != n - 1) {
            a = modmul(a, a);
            t = modmul(t, 2);
        }
        return a == n - 1 || t % 2 == 1;
    };
    for (const Int *w = witness; *w < n && *w; w++) {
        if (!suspect(*w, d)) return false;
    }
    return true;
}

bool is_prime(const u128 &n){
    if(n < 1ULL << 32){
        // n < 2^32
        constexpr u64 witness[] = {2, 7, 61, 0};
        auto modmul = [&](u64 a, u64 b) {
            return a * b % n;
        };
        return is_prime_impl<u64>(n, witness, modmul);
    } else {
        // n < 2^64
        constexpr u128 witness[] = {2, 325, 9375, 28178, 450775, 9780504, 1795265022, 0};
        auto modmul = [&](u128 a, u128 b) {
            return a * b % n;
        };
        auto slow_modmul = [&](u64 a, u64 b){
            u64 res = 0;
            for (; b; b /= 2) {
                if(b&1) res = (res+a)%n;
                a = (a+a)%n;
            }
            return res;
        };
        return is_prime_impl<u128>(n, witness, modmul);
    }
}

using namespace std;
#define rep(i,b) for(int i = 0; i < (int)(n); i++)
typedef long long ll;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    int ans = 0;
    rep(i,n){
        ll x;
        cin >> x;
        ans += is_prime(x);
    }
    cout << ans << endl;
}

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

using namespace std;

int main() {
	int N, T, A, H[1000];
	cin >> N >> T >> A;
	double ans = 1e18;
	for (int i = 0; i < N; i++) {
		cin >> H[i];
		ans = min(ans, abs(A - (T - H[i] * 0.006)));
	}
	for (int i = 0; i < N; i++) {
		if (ans == abs(A - (T - H[i] * 0.006))) {
			cout << i + 1 << endl;
			return 0;
		}
	}
}


Measured memory_bytes: 256
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main(){
    let n = read::<i64>();
    let mut v = vec![];
    for _ in 0..n{
        v.push(read::<i64>());
    } 
    let ans = v.into_iter().fold( None,|y,x| Some(match y{
        None => x,
        Some(y) => lcm(y,x),
    })).unwrap();
    println!("{}",ans);
}
fn gcd(x:i64,y:i64) -> i64{
    if x % y == 0 {
        y
    } else {
        gcd(y,x%y)
    }
}
fn lcm(x:i64,y:i64)-> i64{
    x / gcd(x, y) * y
}

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

using namespace std;

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

    while (M--) {
        int a;
        cin >> a;
        N -= a;
    }

    if (N < 0) N = -1;
    cout << N << endl;
    return 0;
}


Measured memory_bytes: 3632
def getlist():
	return list(map(int, input().split()))

#受け取り
H, W = getlist()
L = []
for i in range(H):
	l = getlist()
	L.append(l)

#処理
N = 0
ans = []
for i in range(H):
	for j in range(W):
		if L[i][j] % 2 != 0:
			if j != W - 1:
				ans.append(" ".join(list(map(str, [i + 1, j + 1, i + 1, j + 2]))))
				L[i][j + 1] += 1
				N += 1
			elif i != H - 1:
				ans.append(" ".join(list(map(str, [i + 1, j + 1, i + 2, j + 1]))))
				L[i + 1][j] += 1
				N += 1
			else:
				pass

print(N)
for i in ans:
	print(i)

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

int main(){
	cin.tie(NULL);
	ios_base::sync_with_stdio(false);
	string s;
	cin>>s;
	for(int i = 0; i< s.size(); i++){
		if(s[i] == '1') cout<<'9';
		else if(s[i] == '9') cout<<'1';
		else cout<< s[i];
	}
	cout<<'\n';
}


Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskD solver = new TaskD();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskD {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int W = in.nextInt();
            long[] dp = new long[W + 1];
            Arrays.fill(dp, Long.MIN_VALUE);
            dp[0] = 0;
            for (int i = 0; i < n; i++) {
                int w = in.nextInt();
                long v = in.nextInt();
                for (int j = W; j >= w; j--)
                    dp[j] = Math.max(dp[j], dp[j - w] + v);
            }
            long max = 0;
            for (long el : dp)
                max = Math.max(max, el);
            out.println(max);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}

Measured memory_bytes: 23252
i = list(map(int, input().split()))
x=(abs(i[0]))

if x>=i[1]*i[2]:
    print(x-i[1]*i[2])
else:
    if (i[1]-x//i[2])%2 == 0:
        print(x%i[2])
    else:
        print(i[2]-x%i[2])

Measured memory_bytes: 8996
n=int(input())
t=[]
for i in range(1,int(n**0.5)+1):
  if n%i==0:
    t.append(i)
hantei=10**12+1
for i in t:
  if hantei>((i-1)+n//i-1):
    hantei=((i-1)+(n//i)-1)
print(hantei)

Measured memory_bytes: 3188
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt(), m = scanner.nextInt();
			UnionFindTree uft = new UnionFindTree(n);
			IntStream.range(0, m).forEach(i -> {
				int a = scanner.nextInt() - 1, b = scanner.nextInt() - 1;
				uft.union(a, b);
			});
			Map<Integer, Integer> map = new HashMap<>();
			IntStream.range(0, n).forEach(i -> {
				int root = uft.find(i);
				map.put(root, map.getOrDefault(root, 0) + 1);
			});
			System.out.println(map.values().stream().mapToInt(Integer::intValue).max().getAsInt());
		}
	}

	/**
	 * Union Find Treeの実装<br/>
	 * https://atcoder.jp/contests/abc040/submissions/4708654 を参考に作成
	 */
	private static class UnionFindTree {
		int[] parent;
		int[] count;

		UnionFindTree(int size) {
			parent = new int[size];
			IntStream.range(0, size).forEach(i -> parent[i] = i);
			count = new int[size];
			Arrays.fill(count, 1);
		}

		int find(int x) {
			if (parent[x] == x) {
				return x;
			} else {
				int v = find(parent[x]);
				parent[x] = v;
				return v;
			}
		}

		/**
		 * @param x
		 * @param y
		 * @return xとyがつながっているかどうか
		 */
		@SuppressWarnings("unused")
		boolean same(int x, int y) {
			return find(x) == find(y);
		}

		/**
		 * xとyを結合する
		 * 
		 * @param x
		 * @param y
		 */
		void union(int x, int y) {
			int rootX = find(x);
			int rootY = find(y);
			if (rootX == rootY) {
				return;
			}
			parent[rootX] = rootY;
			parent[x] = rootY;
			count[rootY] += count[rootX];
		}

		/**
		 * @param x
		 * @return xと結ぶ都市の数
		 */
		public int count(int x) {
			return count[find(x)];
		}
	}
}


Measured memory_bytes: 70848
import math
A,B,X=map(int,input().split())
if X!=A**2*B:
  if B>=A:
    X/=A
    if X<=(A*B/2):
      tan=B**2/(2*X)
      print(math.degrees(math.atan(tan)))
    else:
      X=A*B-X
      tan=2*X/A**2
      print(math.degrees(math.atan(tan)))    
  elif B<A:
    X/=A
    if X<=(A*B/2):
      tan=B**2/(2*X)
      print(math.degrees(math.atan(tan)))
    else:
      X=A*B-X
      tan=2*X/A**2
      print(math.degrees(math.atan(tan)))
else:
  print(0)

Measured memory_bytes: 3064
N, K = map(int,input().split())
H = list(map(int,input().split()))

dp = [1e9]*N
dp[0] = 0
for i, b in enumerate(H):
  if i != 0:
    x = max(0, i-K)
    dp[i] = min([abs(b-d)+p for d, p in zip(H[x:i], dp[x:i])])
print(dp[-1])

Measured memory_bytes: 13980
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

a = [inp() for _ in range(5)]
mi = 10
ind = -1
for i,t in enumerate(a):
    tmp = int(str(t)[-1])
    if tmp < mi and tmp:
        mi = tmp
        ind = i
a[ind], a[4] = a[4], a[ind]
now = 0
for i in a:
    if now%10:
        now += 10-now%10
    now += i
print(now)

Measured memory_bytes: 5084
#include<bits/stdc++.h>
using namespace std;
 
//setbase - cout << setbase (16); cout << 100 << endl; Prints 64
//setfill -   cout << setfill ('x') << setw (5); cout << 77 << endl; prints xxx77
//setprecision - cout << setprecision (14) << f << endl; Prints x.xxxx
//cout.precision(x)  cout<<fixed<<val;  // prints x digits after decimal in val

#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define repa(i,arr,n) for(int i=arr;i<=n;i++)
#define repd(i,arr,n) for(int i=arr;i>=n;i--)
#define trav(arr,x) for(auto& arr:x)
#define all(c) c.begin(), c.end()
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz(arr) arr.size()
#define pi 3.14159265358979323846
#define MAX (1000*1000*1000+7)
#define vi vector<int>
#define pii pair<int,int>
#define pqueue priority_queue<int>
#define pdqueue priority_queue<int,vi,greater<int> >

int parent[100005],size[100005];
void make_set(int v) {
    parent[v] = v;
    size[v] = 1;
}

int find_set(int v) {
    if (v == parent[v])
        return v;
    return find_set(parent[v]);
}
void union_sets(int a, int b) {
    a = find_set(a);
    b = find_set(b);
    if (a != b) {
        if (size[a] < size[b])
            swap(a, b);
        parent[b] = a;
        size[a] += size[b];
    }
}


int32_t main()
{
    fast;
    rep(i,100005)
    make_set(i);
    std::vector<pii> v;
    vi ans;
    int n,m,x,y,curr,sx,sy,val;
    cin>>n>>m;

    rep(i,m)
    {
        cin>>x>>y;
        v.pb({x,y});
    }

    curr=(n*(n-1))/2;
    ans.pb(curr);

    repd(i,m-1,1)
    {
        x=v[i].ff;y=v[i].ss;
        
        sx=size[find_set(x)];sy=size[find_set(y)];
        //cout<<sx<<" "<<sy<<endl;
        if(curr==0)
        {
            ans.pb(curr);
            continue;
        }
        if(find_set(x)!=find_set(y)){
        curr+=((sx*(sx-1))/2);
        curr+=((sy*(sy-1))/2);
        val=sx+sy;
        curr-=((val*(val-1))/2);
        ans.pb(curr);
        
        union_sets(x,y);}
      else{ans.pb(curr);}
        //cout<<find_set(x)<<" "<<find_set(y)<<endl;
    }

    repd(i,m-1,0)
    cout<<ans[i]<<endl;
    return 0;
}


Measured memory_bytes: 6256
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;



public class Main implements Runnable{
	@Override
	public void run(){
		new Main().solver();

	}
	// Template
	public static void main(String[] args) {
		new Thread(null, new Main(), "", 16 * 1024 * 1024).start(); 
	}

	void solver() {
		Scanner sc = new Scanner(System.in);
		int V = sc.nextInt();
		int E = sc.nextInt();
		@SuppressWarnings("unchecked")
		ArrayList<Integer>[] e = new ArrayList[V];
		for (int i = 0; i < V; i++)
			e[i] = new ArrayList<>();
		for (int i = 0; i < E; i++) {
			int s = sc.nextInt();
			int t = sc.nextInt();
			e[s].add(t);
		}
		int Q = sc.nextInt();
		int[] scc = stronglyConnectedComponents(e);
		for (int i = 0; i < Q; i++) {
			int u = sc.nextInt();
			int v = sc.nextInt();
			if (scc[u]==scc[v]) {
				System.out.println(1);
			} else {
				System.out.println(0);
			}
		}

	}

	int[] dfsnum;
	int[] low;
	ArrayDeque<Integer> S = new ArrayDeque<>();
	ArrayList<Integer> T = new ArrayList<>();
	int N = 0;
	boolean[] used;
	int[] ret;

	int[] stronglyConnectedComponents(ArrayList<Integer> e[]) {
		int n = e.length;
		dfsnum = new int[n];
		low = new int[n];
		used = new boolean[n];
		ret = new int[n];

		for (int i = 0; i < n; i++) {
			if (used[i])
				continue;
			if (dfsnum[i] == 0) {
				dfs(e, i);
			}
		}
		return ret;
	}

	int NOW = 0;

	void dfs(ArrayList<Integer>[] e, int i) {
		S.addFirst(i);
		dfsnum[i] = N;
		N++;
		low[i] = dfsnum[i];
		for (int j : e[i]) {
			if (used[j])
				continue;
			if (!T.contains(j)) {
				T.add(j);
				dfs(e, j);
				low[i] = Math.min(low[i], low[j]);
			} else {
				low[i] = Math.min(dfsnum[j], low[i]);
			}
		}

		if (low[i] == dfsnum[i]) {
			int v;
			do {
				v = S.removeFirst();
				ret[v] = NOW;
				used[v] = true;
			} while (v != i);
			NOW++;
		}
		return;
	}
}

Measured memory_bytes: 101380