akhauriyash/Code-Regression huggingface dataset:
/*Bismillahir Rahmanir Rahim*///{
#include <bits/stdc++.h>
#include <ext/numeric>
using namespace std; using __gnu_cxx::power;
using ll = long long; using ull = unsigned long long; using ld = long double;
const ll llinf = (1ll<<61)-1; const double eps = 1e-6, ldeps = 1e-9;
struct Dbg { static constexpr auto &os = cout;   // replace by cerr in interactive.
template<class C> static auto o(C *x)->decltype(os << *x, 0);
template<class C> static char o(...);
template<class C> typename enable_if<sizeof o<C>(0)!=1,Dbg&>::type operator<<(const C &x) {os<<x; return *this;}
template<class C> Dbg &dump(C b, C e) {
    for (struct{C i;int j;} i={(*this<<"\n[",b),0}; i.i!=e and i.j<26; i.i++, i.j++) *this<<", "+2*(i.i==b)<<*i.i;
    return *this << ']';
}
template<class C> typename enable_if<sizeof o<C>(0)==1, Dbg&>::type operator<<(const C &x) {
    return dump(begin(x), end(x));
}
template<class C, size_t X> typename enable_if<!is_same<C, const char>::value, Dbg&>::type operator<<(C (&x)[X]) {
    return dump(begin(x), end(x));
}
template<class B, class C> Dbg &operator<<(const pair<B, C> &x) {return *this<<'{'<<x.first<<", "<<x.second<<'}';}
Dbg &operator<<(ostream&(*x)(std::ostream&)) { os << x; return *this; }
} dbg;
void err(istringstream *iss) { delete iss; }
template<class C, class... Args> void err(istringstream *iss, const C &val, const Args &... args) {
    string name; *iss >> name; if (name.back()==',') name.pop_back();
    dbg << name << " = " << val << "; ", err(iss, args...);
}
#define bug(args...) dbg << __LINE__ << ": ", err(new istringstream(#args), args), dbg << endl
#define cbug(a, args...) if (a) bug(args);
#define ASSERT(a, o, b, args...) if (!((a)o(b))) bug(a, b, ##args), assert((a)o(b));
#define sl(a) int(strlen(a))
#define sz(a) int(a.size())
int T, Q, cn;//}
const int inf = 1000000007, mxn = -1;

signed main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); cout.precision(11), cout.setf(ios::fixed);
    string s;
    cin >> s;
    cout << s.substr(0, 3) << '\n';
}	

Measured memory_bytes: 3624
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <ios>
#include <iostream>
#include <numeric>
#include <string>
#include <vector>
using namespace std;

int main()
{
    char c;
    cin >> c;
    if (c == 'a' || c == 'i' || c == 'u' || c == 'e' || c == 'o') {
        cout << "vowel\n";
    } else {
        cout << "consonant\n";
    }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scan  = new Scanner(System.in);
		while(true) {
		int H =scan.nextInt();
		int W =scan.nextInt();
			if (H== 0 && W== 0) break;
			for (int i = 0; i < H ; i++) {
				for (int k = 0; k < W; k++) {
					System.out.print("#");
				}
				System.out.println();	      
			}
			System.out.println();
		}
	}
}


Measured memory_bytes: 37248
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
#include <list>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
long long gcd(long long x, long long y){
    if(y==0) return x;
    else return gcd(y,x%y);
}
//最小公倍数
long long lcm(long long x, long long y){
    return x / gcd(x, y) * y;
}
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    string S; cin >> S;
    if(S[0]==S[1] || S[1]==S[2] || S[2]==S[3]) cout << "Bad" << endl;
    else cout << "Good" << endl;
    return 0;
}


Measured memory_bytes: 3568
#include <bits/stdc++.h>
#define range(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i, a) range(i, 0, a)
using namespace std;

int main() {
    int N, M;
    cin >> N >> M;
    vector <int> P(M), Y(M);
    vector <vector <int>> numToY(N);
    rep (i, M) {
        cin >> P[i] >> Y[i];
        numToY[P[i]-1].push_back(Y[i]);
    }

    rep (i, N) sort(numToY[i].begin(), numToY[i].end());

    rep (i, M) {
        int num = lower_bound(numToY[P[i]-1].begin(), numToY[P[i]-1].end(), Y[i]) - numToY[P[i]-1].begin() + 1;
        string pre = to_string(P[i]), post = to_string(num);
        range (j, (int)pre.size(), 6) pre = "0" + pre;
        range (j, (int)post.size(), 6) post = "0" + post;
        cout << pre + post << endl;
    }
    return 0;
}


Measured memory_bytes: 7808
#include <bits/stdtr1c++.h>
#include <time.h>
#define stat akjcjalsjcjalscj
#define hash ajkscjlsjclajsc
#define next ackjalscjaowjico
#define prev ajcsoua0wucckjsl
//#define y1 alkscj9u20cjeijc
#define left lajcljascjljl
//#define right aucouasocjolkjl
#define y0 u9cqu3jioajc

using namespace std;
#define TASK "solve"

const int QQ = 3e5 + 10;
const int N = 2e5 + 10;
//const long long Base = 500000004;
const int module = 987654319;
mt19937 rnd(chrono::system_clock::now().time_since_epoch().count());

long long rand(long long l, long long r){
    return 1LL * (1LL * rnd() * RAND_MAX + rnd()) % (r - l + 1) + l;
}

void doc() {
    //freopen(TASK ".inp","r",stdin);
    //freopen(TASK ".out","w",stdout);

}
typedef pair<int,int> i2;
void solve() {
    int n;
    cin >> n;
    int Deg[n + 1], u[n + 1], v[n + 1];
    vector <int> adj[n + 1];
    memset(Deg, 0, sizeof(Deg));
    for (int i = 1; i < n; i++) {
        cin >> u[i] >> v[i];
        adj[u[i]].push_back(v[i]);
        adj[v[i]].push_back(u[i]);
        Deg[u[i]]++;
        Deg[v[i]]++;
    }
    int a[n + 1];
    int H[n + 1], Pos[n + 1];
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        H[i] = i;
        Pos[i] = i;
    }
    sort(H + 1, H + 1 + n, [&](int i,int j){
        return a[i] < a[j];
    });
    sort(Pos + 1, Pos + 1 + n, [&](int i,int j){
        return Deg[i] > Deg[j];
    });
    int Res[n + 1];
    for (int i = 1; i <= n; i++) Res[i] = 0;
    priority_queue <i2, vector<i2>, greater<i2> > Q;
    for (int i = 1; i <= n; i++) Q.push(i2(Deg[i], i));
    int L = 0;
    while (Q.size() != 0) {
        i2 A = Q.top(); Q.pop();
        int u = A.second;
        int du = A.first;
        if (Deg[u] != du) continue;
        Res[u] = a[H[++L]];
        for (int v : adj[u]) {
            if (Res[v] == 0) {
                Deg[v]--;
                Q.push(i2(Deg[v], v));
            }
        }
    }
    //for (int i = 1; i <= n; i++) Res[Pos[i]] = a[H[i]];
    int KQ = 0;
    for (int i = 1; i < n; i++)
        KQ += min(Res[u[i]], Res[v[i]]);
    cout << KQ << '\n';
    for (int i = 1; i <= n; i++) cout << Res[i] << ' ';
}
int main(int argc,char *argv[]) {
    srand(time(nullptr));
    ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr);
    doc();
    solve();
}


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

Measured memory_bytes: 256
program Project1;

{$APPTYPE CONSOLE}

uses
  SysUtils;
var
  a,h,w,i,j,count,x,y,sw,m,n,b,c,soeji,sum,max,k:Integer;
  l:array of Integer;
  s,s123,s1,s2,s3:string;
  al:string = 'abcdefghijklmnopqrstuvwxyz';
  tf,tfl,tfr:Boolean;
begin
  try
    { TODO -oUser -cConsole メイン : ここにコードを記述してください }
    Readln(n);
    Readln(s);
    count:=0;
    max  :=0;

    for i:=1 to n do begin //区切り位置変更

      for k:=1 to 26 do begin
        tfl:=false;
        tfr:=false;
        for j:=1 to i do begin //左
            if al[k]=s[j]then
              tfl:=true;
        end;
        for j:=i+1 to n do begin //右
            if al[k]=s[j]then
              tfr:=true;
        end;
        if tfl and tfr then
          inc(count);
      end;

      max:=(count+max+abs(count-max))div 2;
      count:=0;
    end;

    Writeln(max);
    Readln;
  except
    on E: Exception do
      Writeln(E.ClassName, ': ', E.Message);
  end;
end.


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int X;
    cin >> X;
    int n = X/200;
    cout << 10-n << "\n";
}

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

int main()
{
    int n, m;
    cin >> n >> m;
    int s = 0, a[n + 1];
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        s += a[i];
    }
    sort(a+1,a+n+1,greater<int>());
    if(a[m]*4*m<s)
        cout<<"No";
    else 
        cout<<"Yes";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
const double EPS = 1e-10;
using namespace std;
class Edge{
public:
    int from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};

int main(){
    int N;cin >> N;
    vector<int> vec;
    bool f1 = false;
    bool f2 = false;
    for(int a = 0;a < N;a++){
        int b;cin >> b;
        vec.push_back(b);
        if(b > 0)f1 = true;
        if(b < 0)f2 = true;
    }
    sort(vec.begin(),vec.end());
    if(N == 2){
        cout<<vec.back()-vec.front()<<endl;
        cout<<vec.back()<<" "<<vec.front()<<endl;
        return 0;
    }
    if(!f1 && !f2){
        cout<<0<<endl;
        for(int a = 0;a < N-1;a++)cout<<0<<" "<<0<<endl;
    }else
    if(f1 && !f2){
        vector<pair<int,int>> q;
        //cout<<vec.front()<<" "<<vec.at(1)<<endl;
        q.push_back({vec.front(),vec.at(1)});
        int b = vec.front()-vec.at(1);
        for(int a = 2;a < N-1;a++){
            //cout<<b<<" "<<vec.at(a)<<endl;
            q.push_back({b, vec.at(a)});
            b -= vec.at(a);
        }
        q.push_back({vec.back(),b});
        vec.back() -= b;
        cout<<vec.back()<<endl;
        for(int a = 0;a < q.size();a++)
            cout<<q.at(a).first<<" "<<q.at(a).second<<endl;
    }else
        if(!f1 && f2){
         //   abort();
            vector<pair<int,int>> q;
            //cout<<vec.front()<<" "<<vec.at(1)<<endl;
            q.push_back({vec.back(),vec.at(N-2)});
            int b = vec.back()-vec.at(N-2);
            for(int a = 0;a < N-2;a++){
                //cout<<b<<" "<<vec.at(a)<<endl;
                q.push_back({b, vec.at(a)});
                b -= vec.at(a);
            }
            cout<<b<<endl;
            for(int a = 0;a < q.size();a++)
                cout<<q.at(a).first<<" "<<q.at(a).second<<endl;
        }else if(f1&& f2){
        //    abort();
            LL ans = 0;
            for(int a = 0;a < N;a++)ans += abs(vec.at(a));
            cout<<ans<<endl;
            for(int i = 1;i < N-1;i++){
                if(vec.at(i) > 0){
                    cout<<vec.front()<<" "<<vec.at(i)<<endl;
                    vec.front() -= vec.at(i);
                }else if(vec.at(i) < 0){
                    cout<<vec.back()<<" "<<vec.at(i)<<endl;
                    vec.back() -= vec.at(i);
                }else{
                    cout<<vec.back()<<" "<<vec.at(i)<<endl;
                }

            }
            cout<<vec.back()<<" "<<vec.front()<<endl;

        }
}


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define Mp make_pair
#define pb push_back

using ll = long long;
using db = double;
using pii = pair<int, int>;
using vi = vector<int>;
mt19937 mrand(time(0));
ll get(ll r) { return ((ll)mrand() * mrand() % r + r) % r; }
ll get(ll l, ll r) { return get(r - l + 1) + l; }

signed main() {
	ios::sync_with_stdio(false);
	int n; cin >> n; vi a(n);
	for(int &i : a) cin >> i;
	ll ans = 0;
	for(int i = 1; i < a.size(); i++)
		ans += max(0, a[i - 1] - a[i]), a[i] = max(a[i], a[i - 1]);
	cout << ans << endl;
	fprintf(stderr, "time=%.4f\n", (db)clock()/CLOCKS_PER_SEC);
	return 0;
	/* 取模直接除，爆零两行泪
	 * 不开ll见祖宗
	 */
}

Measured memory_bytes: 3948
import sys
import math
import string
import fractions
import random
from operator import itemgetter
import itertools
from collections import deque
import copy
import heapq
import bisect

MOD = 10 ** 9 + 7
INF = float('inf')
input = lambda: sys.stdin.readline().strip()

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


def dictionary(info, n):
    if n == 1:
        return info
    MAX = max(info[0])
    info2 = []
    for i in range(MAX+1):
        for l in info:
            p = copy.deepcopy(l)
            p.insert(i, MAX+1)
            info2.append(p)
    return dictionary(info2, n - 1)


ans = sorted(dictionary([[1]], N))
print(abs(ans.index(P) - ans.index(Q)))


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

int main() {
  int K, S;
  int res = 0;

  cin >> K >> S;
  for (int i = 0; i <= K; i++) {
    for (int j = 0; j <= K; j++) {
	     if (S - i - j <= K && S - i - j  >= 0)  {
         res += 1;
       }
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const double eps = 1e-8;

#ifdef DEBUG
#include "inc/debug.hpp"
#else
#define debug(...) 42
#endif

int pow(int a, int k) {
    int ret = 1;
    for (int i=0; i<k; ++i) ret *= a;
    return ret;
}

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> s(M), c(M);
    for (int i=0; i<M; ++i) cin >> s[i] >> c[i];

    int l2 = pow(10, N);
    int l1 = (l2 == 10) ? 0 : l2/10;
    for (int i=l1; i<l2; ++i) {
        bool ok = true;
        for (int j=0; j<M; ++j) {
            string t = to_string(i);
            if (t[s[j]-1] - '0' != c[j]) {
                ok = false;
                break;
            }
        }
        if (ok) {
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
program prob3
    implicit none
    integer::n, m, i, j
    integer(8)::t, ans
    integer(8), allocatable::a(:,:)
    read(*,*) n, m
    allocate(a(n,2))
    do i = 1, n
        read(*,*) a(i,1), a(i,2)
    end do
    call hsort(n,2,1,a)
    ans = 0
    do i = 1, n
        if(m >= a(i,2)) then
            ans = ans + a(i,1) * a(i,2)
            m = m - a(i,2)
        else
            ans = ans + m * a(i,1)
            exit
        end if
    end do
    write(*,*) ans
    stop
contains
    ! n行m列の配列をp列目でsort
    ! 1次元配列ならm=p=1
    subroutine hsort(n,m,p,array)
        implicit none
        integer,intent(in)::n, m, p
        integer(8),intent(inout)::array(n,m)

        integer ::i,k,j,l
        integer::t(m)

        if(n.le.0)then
        write(6,*)"Error, at heapsort"; stop
        end if
        if(n.eq.1)return

        l=n/2+1
        k=n
        do while(k.ne.1)
        if(l.gt.1)then
            l=l-1
            t=array(L,:)
        else
            t=array(k,:)
            array(k,:)=array(1,:)
            k=k-1
            if(k.eq.1) then
                array(1,:)=t
                exit
            end if
        end if
        i=l
        j=l+l
        do while(j.le.k)
            if(j.lt.k)then
                if(array(j,p).lt.array(j+1,p))j=j+1
            end if
            if (t(p).lt.array(j,p))then
                array(i,:)=array(j,:)
                i=j
                j=j+j
            else
                j=k+1
            end if
        end do
        array(i,:)=t
        end do

        return
    end subroutine hsort
end program

Measured memory_bytes: 4432
N=int(input())
A=list(map(int,input().split()))
Alist=[]
for i in range(N):
  Alist.append((A[i],i+1))
Alist=sorted(Alist,key=lambda x: x[0])
for i in range(N):
  print(Alist[i][1],end=" ")
  

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

int N;
vector<double> p;

double dp[3100][3100];

int main() {
    cin >> N;
    p.resize(N);
    for (int i = 0; i < N; ++i) cin >> p[i];

    dp[0][0] = 1.0;

    for (int i = 0; i < N; ++i) {
        for (int j = 0; j <= i; ++j) {
            dp[i+1][j+1] += dp[i][j] * p[i];
            dp[i+1][j] += dp[i][j] * (1.0 - p[i]);
        }
    }

    double res = 0.0;
    for (int j = (N+1)/2; j <= N; ++j) res += dp[N][j];
    cout << fixed << setprecision(10) << res << endl;
}


Measured memory_bytes: 72320
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
using ll = long long;
using p = pair<int,int>;
int main(int argc, const char * argv[]) {



    cin.tie(0);
    ios::sync_with_stdio(false);

    int n,A=0,W=0,T=0,R=0;
    cin>>n;
    string s;
    rep(i,n){
        cin>>s;
        if(s=="AC")A++;
        else if(s=="WA")W++;
        else if(s=="TLE")T++;
        else if(s=="RE")R++;
    }
    cout<<"AC x "<<A<<endl;
    cout<<"WA x "<<W<<endl;
    cout<<"TLE x "<<T<<endl;
    cout<<"RE x "<<R<<endl;

    return 0;
}


Measured memory_bytes: 3656
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cfloat>
#include<climits>
#include<cmath>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

using namespace std;

typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;


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


#define ARRAY_MAX 100005
const int INF = INT32_MAX / 3;
const ll MOD = 1e9 + 7;

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


/******************************************************************************************/


//xのn乗をmで余りを取る
ll mod_pow(ll x, ll n, ll m) {
	if (n == 0) {
		return 1LL;
	}
	else if (n % 2 == 0) {
		return mod_pow(x * x % m, n / 2, m);
	}
	else {
		return (x * mod_pow(x, n - 1, m)) % m;
	}
}

struct Combination {

	vector<ll> fact, rfact;

	Combination(ll sz) : fact(sz + 1), rfact(sz + 1) {

		fact[0] = 1;
		for (ll i = 1; i < fact.size(); i++) {
			fact[i] = fact[i - 1] * i % MOD;
		}
		//逆元
		rfact[sz] = inv(fact[sz]);
		for (ll i = sz - 1; i >= 0; i--) {
			rfact[i] = rfact[i + 1] * (i + 1) % MOD;
		}
	}

	ll inv(ll x) {
		return pow(x, MOD - 2);
	}
	ll pow(ll x, ll n) {
		ll ret = 1;
		while (n > 0) {
			if (n & 1) (ret *= x) %= MOD;
			(x *= x) %= MOD;
			n >>= 1;
		}
		return (ret);
	}
	ll P(ll n, ll r) {
		if (r < 0 || n < r) return (0);
		return (fact[n] * rfact[n - r] % MOD);
	}

	ll C(ll p, ll q) {
		if (q < 0 || p < q) return (0);
		return (fact[p] * rfact[q] % MOD * rfact[p - q] % MOD);
	}

	ll H(ll n, ll r) {
		if (n < 0 || r < 0) return (0);
		return (r == 0 ? 1 : C(n + r - 1, r));
	}
};


ll comb[1005][1005];


int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);

	int n, k;
	cin >> n >> k;
	int ans = 0;

	Combination comb(k + 10);

	for (int i = 1; i <= k; i++)
	{
		int rest = k - i;
		ll val = comb.C(k,i) * mod_pow(rest, n, MOD);
		if (i % 2) {
			ans = (ans + val) % MOD;
		}
		else
		{
			ans = (ans - val + MOD) % MOD;
		}
	}
	
	ans = (mod_pow(k, n, MOD) - ans + MOD) % MOD;

	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define ss second
#define ff first
#define N 200005
#define inf 1000000009
#define ll long long
#define pii pair<int,int>
#define sz(a) int(a.size())
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}

int n,a[N],ans,b[1000006],num[1000006],mx;
set <int> s;

int main(){
	scanf("%d",&n);
	for(int i = 1;i <= n;i++){
		scanf("%d",&a[i]);
		num[a[i]]++;
		mx = max(a[i],mx);
		s.insert(a[i]);
	}
	for(auto i : s){
		for(int j = i;j <= mx;j += i) b[j] += num[i]; 
	}
	for(int i = 1;i <= n;i++) if(b[a[i]] == 1) ans++;
	printf("%d",ans);
}


Measured memory_bytes: 20788
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pii;
#define fi first
#define se second
#define mod 1000000007
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
ll dist[200005];
bool vis[200005];
vector<ll> adj[200005];
ll pos,val,n,k;
void dfs(ll u,ll dist1)
{
	vis[u]=true;
	dist[u]=dist1;
	if(dist1==k)
	{
		cout<<u<<endl;
		exit(0);
	}
	for(auto it=adj[u].begin();it!=adj[u].end();it++)
	{
		if(!vis[*it])
			dfs(*it,dist1+1);
		else
		{
			pos=*it;
			val=dist1+1;
			return;
		}
	}
}
int main()
{
	ios;
	ll i,x,len;
	cin>>n>>k;
	for(i=1;i<=n;i++)
	{
		cin>>x;
		adj[i].push_back(x);
	}
	dfs(1,0);
	k-=dist[pos];
	len=val-dist[pos];
	k=k%len;
	//cout<<k<<" "<<len<<" "<<pos<<" "<<dist[pos]<<" "<<val<<endl;
	memset(vis,false,sizeof(vis));
	dfs(pos,0);
}


Measured memory_bytes: 23816
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
#define ALL(x) (x).begin(), (x).end()
#define OUT(x) cout << (x) << endl
typedef long long ll;

int main() {
    int a, b, k;
    cin >> a >> b >> k;
    bool flag = true;
    while (k) {
        if (flag) {
            if (a % 2) {
                a--;
            }
            b += a / 2;
            a /= 2;
            flag = false;
        } else {
            if (b % 2) {
                b--;
            }
            a += b / 2;
            b /= 2;
            flag = true;
        }
        k--;
    }
    cout << a << " " << b << endl;
}


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

const int mod = 1000000007;

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A[i];

    int ans = 0;
    int x = 0;

    rep(i, N) {
        ans = (ans + (ll)A[i] * x) % mod;
        x = (x + A[i]) % mod;
    }
    
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3976
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)for(int i=0;i<(n);i++)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define pb push_back
using ll = long long;
using P = pair<int, int>;

int main(){
    int x; cin >> x;
    if(x == 1) cout << 0 << endl;
    else cout << 1 << endl;
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#define sz(arr) (int)arr.size()
#define all(arr) arr.begin(), arr.end()

using namespace std;
typedef long long ll;

void _cin() {}
template <class Head, class... Tail>
void _cin(Head&& head, Tail&&... tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}

#define Cin(T, ...) \
  T __VA_ARGS__;    \
  _cin(__VA_ARGS__)

void Main() {
  Cin(int, n);
  vector<int> vi(n);
  for (auto& e : vi) cin >> e;
  sort(all(vi));
  vi.back() /= 2;
  cout << accumulate(all(vi), 0) << endl;
  return;
}

int main() {
  cout << fixed << setprecision(15);
  Main();
  return 0;
}

Measured memory_bytes: 636
#include<iostream>
#include<iomanip>
#include<cstdio>

#include<vector>
#include<queue>
#include<set>
#include<map>
#include<string>

#include<algorithm>
#include<cmath>
#include<numeric>

using namespace std;
typedef long long ll;
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;}
const ll INF = 1e18+1;

/*
そこまでの　A数とAB数を記録する?
AB数...以前のAB数 + もしそこがBなら 1*以前のA数
ABC数...以前のABC数+ もしそこがCなら 1*以前のC数

ここに?の概念を追加できるか

A数は以前のは単純に3倍 + 1　かなあ
AB数...以前のAB数*3 + もしそこがBなら以前のA数
ABC数...以前のABC数*3 + もしそこがCなら以前のAB数
*/

ll dp[100000][4];

int main() {
    string S;
    cin >> S;
    ll D = 1e9 + 7;
    dp[0][0] = 1;

    for (int i = 1; i <= S.length(); i++) {
        for (int j = 0; j < 4; j++) {
            if (S[i-1] == '?') dp[i][j] = (dp[i-1][j]) * 3 % D;
            else dp[i][j] = dp[i-1][j]% D;
        }
        if (S[i-1] == 'A' || S[i-1] == '?') dp[i][1] = (dp[i][1] + dp[i-1][0]) % D;
        if (S[i-1] == 'B' || S[i-1] == '?') dp[i][2] = (dp[i][2] + dp[i-1][1]) % D;
        if (S[i-1] == 'C' || S[i-1] == '?') dp[i][3] = (dp[i][3] + dp[i-1][2]) % D;
    }

    cout << dp[S.length()][3] % D << endl;    
}

Measured memory_bytes: 3712
// A - Round One
#include <bits/stdc++.h>
using namespace std;

int main(){
	int A,B; cin>>A>>B;
	if(A>B) swap(A,B);
	int ans;
	if(A==1 && B==2) ans = 3;
	if(A==1 && B==3) ans = 2;
	if(A==2 && B==3) ans = 1;
	cout<< ans <<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <stdlib.h>
#include <assert.h>
#include <math.h>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <algorithm>
#include <functional>

#define mp make_pair
#define pb push_back
#define mes(a,b) memset(a,b,sizeof(a))
#define mes0(a) memset(a,0,sizeof(a))
#define lson l,mid,pos<<1
#define rson mid+1,r,pos<<1|1
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define fi first
#define se second
#define sss(a) a::iterator
#define all(a) a.begin(),a.end()

using namespace std;

typedef double DB;
typedef long long LL;
typedef pair<int,int> pii;
typedef pair<long long ,int> pli;
typedef pair<int,long long > pil;
typedef pair<string,int> psi;
typedef pair<long long ,long long > pll;

const int inf = 0x3f3f3f3f;
const long long INF = 0x3f3f3f3f3f3f3f3f;
const double pi = acos(-1.0);
const int maxn = 100000+10;
const int mod = 1e9+7;
LL dp[60];
char st[123456];
int aa[1234];
int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);

    int n;
    scanf("%d",&n);
    scanf("%s",st+1);
    int t=0;
    for (int i=1;i<=n;i++){
        if (st[i]!=st[i-1]){
            aa[++t]++;
        }else {
            aa[t]++;
        }
    }
    if (aa[1]==1)dp[1]=3;
    else dp[1]=6;
    for (int i=2;i<=t;i++){
        if (aa[i-1]==2&&aa[i]==1)dp[i]=dp[i-1];
        if (aa[i-1]==2&&aa[i]==2)dp[i]=dp[i-1]*3%mod;
        if (aa[i-1]==1&&aa[i]==1)dp[i]=dp[i-1]*2%mod;
        if (aa[i-1]==1&&aa[i]==2)dp[i]=dp[i-1]*2%mod;
    }
    cout<<dp[t];
    return 0;
}


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

int ansTime;
int dx[] = {-1, 1};
int n, l;
int d[22], p[22];

void solve(){
  int ansAnt = -1;
  int rem = n;
  int tm = 1;

  while(rem > 0){
    int nd[22], np[22];

    for(int i = 0; i < n; i++){
      if(p[i] == 0 || p[i] == l){
        nd[i] = d[i];
        np[i] = p[i];
        continue;
      }

      bool flg = false;

      for(int j = 0; j < n; j++){
        if(i == j) continue;
        if(p[i] == p[j]){
          flg = true;
          break;
        }
      }

      nd[i] = flg ? !d[i] : d[i];
      np[i] = p[i] + dx[nd[i]];

      if(np[i] == 0 || np[i] == l){
        rem--;
        if(tm != ansTime || np[i] == l && ansAnt != -1) continue;
        ansAnt = i + 1;
      }
    }

    for(int i = 0; i < n; i++){
      d[i] = nd[i];
      p[i] = np[i];
    }

    tm++;
  }

  cout << ansTime << " " << ansAnt << endl;
}

int main(){
  while(cin >> n >> l){
    if(n == 0) break;

    ansTime = 0;

    for(int i = 0; i < n; i++){
      char dir;
      cin >> dir >> p[i];

      if(dir == 'L'){
        d[i] = 0;
        ansTime = max(ansTime, p[i]);
      }
      else{
        d[i] = 1;
        ansTime = max(ansTime, l - p[i]);
      }
    }

    solve();
  }
}

Measured memory_bytes: 1160
N = int(input())

min_num = float('inf')
for i in range(1, N):
    j = N - i
    A_sum = sum(map(int, list(str(i))))
    B_sum = sum(map(int, list(str(j))))
    if A_sum + B_sum < min_num:
        min_num = A_sum + B_sum
print(min_num)


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

using namespace std;

#define MAX_N 105
int N;
int A[MAX_N];

void input()
{
  cin >> N;
  for (size_t i = 0; i < N; i++) {
    scanf("%d", &A[i]);
  }
}

string No = "Impossible";
string Yes = "Possible";

map<int, int> MAP;

string solve()
{
  sort(A, A+N, greater<int>());
  if(A[0] >= N){
    return No;
  }

  if(A[0] != A[1]){
    return No;
  }
  for (size_t i = 0; i < N-1; i++) {
    if(A[i] - A[i+1] > 1){
      return No;
    }
  }

  int Len = A[0];
  int Min = (Len+1)/2, MinCnt = 1 + (Len%2 == 1);

  int pos = 0;
  int tmp = A[0];
  int tmpCnt = 0;

  for (pos = 0; pos < N && A[pos] != Min; pos++) {
    if(tmp == A[pos]){
      tmpCnt++;
    }
    else{
      if(tmpCnt >= 2){
        tmp--;
        pos--;
        tmpCnt = 0;
      }
      else{
        return No;
      }
    }
  }
  if(N-pos == MinCnt){
    return Yes;
  }
  else{
    return No;
  }

}

int main()
{
  input();

  cout << solve() << endl;

  return 0;
}


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

double solve(int N, int T, const set<int>& l, const set<int>& b) {

	// dp[i][j] := i?????????????????????????????£?????¶???????????????, ???????????????j?????\????¢????
	vector<vector<double>> dp(T + 2, vector<double>(N + 1, 0.0));
	dp[0][0] = 1.0; // ?????????????¨????
	for (int i = 0; i < T; ++i) { // i?????????????????????
		for (int j = 0; j < N; ++j) { // j?????????
			// if (dp[i][j] == 0) continue;
			for (int k = 1; k <= 6; ++k) { // ??????????????°

				int next;
				if (j + k > N) next = N - (j + k - N);
				else next = j + k;

				if (l.count(next)) {
					dp[i + 2][next] += dp[i][j] / 6.0; // 1???skip
				} else if (b.count(next)) {
					dp[i + 1][0] += dp[i][j] / 6.0; // ?????????????????????
				} else {
					dp[i + 1][next] += dp[i][j] / 6.0; // ??????
				}

			}
		}
	}

	double ret = 0;
	// i???????????§?????´?????????????????????????????????????¢???????????¨?????¶????
	for (int i = 0; i <= T; ++i) ret += dp[i][N];
	return ret;

}

int main(void) {

	while(1) {
		int N, T, L, B;
		cin >> N >> T >> L >> B;
		if (N == 0 && T == 0 && L == 0 && B == 0) break;
		set<int> l, b;
		for (int i = 0; i < L; ++i) {
			int t; cin >> t;
			l.insert(t);
		}
		for (int i = 0; i < B; ++i) {
			int t; cin >> t;
			b.insert(t);
		}
		printf("%.9lf\n", solve(N, T, l, b));
	}
	return 0;

}

Measured memory_bytes: 3300
s = int(input())
def f(n):
    if n % 2 == 0:
        return (n / 2)
    else:
        return (3 * n + 1)
if s <= 2:
    print(4)
    exit()

count = 4
while (s != 4):
    s = f(s)
    count += 1
print(count)

Measured memory_bytes: 2940
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<queue>
#include<algorithm>
#include<complex>
#include<cstdlib>
#include<cctype>

#define REP(i,n) for(int i = 0;i < (n);i++)
#define PB push_back
#define MP make_pair
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cout << v[i] << ' ';cout << endl << endl;}
#define SHOW2d(v,i,j) {for(int a = 0;a < i;a++){for(int b = 0;b < j;b++)cout << v[a][b] << ' ';cout << endl;}cout << endl;}
#define ALL(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> ivv;


int main()
{
	int d,e;
	
	while(cin >> d >> e,d|e)
	{
		double ret = 10000000;
		REP(i,d/2 + 1)
		{
			ret = min(ret , abs(sqrt(i*i + (d-i)*(d-i)) - e));
		}
		
		printf("%.10f\n",ret);
		
	}
	
	
	return 0;
}

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

for i in range(n):
    if a[i] == 0:
        print(0)
        exit()
ans = 1
for i in range(n):
    ans *= a[i]
    if ans > 10**18:
        print(-1)
        exit()
print(ans)

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

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

int main() {
    int h, a, ans = 0;
    cin >> h >> a;
    while (h > 0) {
        ans++;
        h -= a;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long lli;
int main()
{
	string str; cin >> str;
	map<lli, lli> M;
	M[0] = 1;
	lli ans = 0, sum = 0, now = 1;
	for(int i=str.size() - 1; i >= 0; i--)
	{
		sum = (sum + (str[i] - '0') * now) % 2019;
		ans += M[sum];
		M[sum] ++;
		now = (now * 10) % 2019;
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 3752
#include <string>
#include <vector>
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<stack>
#include<queue>
#include<cmath>
#include<algorithm>
#include<functional>
#include<list>
#include<deque>
#include<bitset>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<cstring>
#include<sstream>
#include<complex>
#include<iomanip>
#include<numeric>
#include<cassert>
#define X first
#define Y second
#define pb push_back
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
#define repe(X,Y) for ((X) = 0;(X) < (Y);++(X))
#define peat(X,Y) for (;(X) < (Y);++(X))
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define eb emplace_back
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define Endl endl
#define NL <<"\n"

using namespace std;
using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
template<class T> using vv=vector<vector<T>>;
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}
//#undef NUIP
#ifdef NUIP
#include "benri.h"
#else
#define out(args...)
#endif
#ifdef __cpp_init_captures
template<typename T>vector<T> table(int n, T v){ return vector<T>(n, v);}
template <class... Args> auto table(int n, Args... args){auto val = table(args...); return vector<decltype(val)>(n, move(val));}
#endif
const ll MOD=1e9+7; //998244353

int solve(vector<int> a){
	int n=a.size();
	sort(all(a));
	ll s=accumulate(all(a),0ll);
	if(n%2) return s%2;
	if(s%2){
		return 1;
	}
	return a[0]%2;
}

int main(){
  ios_base::sync_with_stdio(false); cin.tie(0);
  cout<<fixed<<setprecision(0);
	int n;
	cin>>n;
	vector<int> a(n);
	rep(i,n) cin>>a[i];
	cout<<(solve(a)?"First":"Second") NL;
  return 0;
}



Measured memory_bytes: 4472
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
//for(int i = 0; i<n; i++)
 
 
int main()
{
    int a,b,c,d,e,f;cin>>a>>b>>c>>d;
    e = c - a; f = d - b;;
    cout << c - f << " " << d + e << " " << a - f << " " << b + e << endl; 
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int a[] = new int[N];
    int alice =0,bob=0;
    for (int i=0; i<N; i++) {
      a[i] = sc.nextInt();
    }
    Arrays.sort(a);
    for (int i=0; i<=(N-1)/2; i++) {
      int tmp = a[i];
      a[i] = a[N-1-i];
      a[N-1-i] = tmp;
    }
    for (int i=0; i<=N-1; i++) {
      if(i % 2 ==0) alice += a[i];
      if(i % 2 ==1) bob += a[i];
    }
    System.out.println(alice - bob);
  }
}

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

int main() {
  int N;
  cin >> N;
  vector<string> s(N);
  set<string> score;
  for (int i = 0; i < s.size(); ++i) {
    cin >> s.at(i);
    score.insert(s.at(i));
  }
  cout << score.size() << endl;
}

Measured memory_bytes: 25096
from collections import defaultdict
con = 10 ** 9 + 7; INF = float("inf")

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

#処理内容
def main():
	H, W, K = getlist()
	C = []
	for i in range(H):
		c = list(input())
		C.append(c)

	ans = 0
	for i in range(1 << H):
		for a in range(1 << W):
			bitlistH = []
			bitlistW = []
			for j in range(H):
				if ((i >> j) & 1) == 1:
					#or処理
					bitlistH.append(0)
				else:
					bitlistH.append(1)

			for b in range(W):
				if ((a >> b) & 1) == 1:
					#or処理
					bitlistW.append(0)
				else:
					bitlistW.append(1)

			cnt = 0
			for x in range(H):
				for y in range(W):
					if C[x][y] == "#" and bitlistH[x] == 0 and bitlistW[y] == 0:
						cnt += 1

			if cnt == K:
				ans += 1

	# print(bitlistH)
	# print(bitlistW)

	print(ans)





if __name__ == '__main__':
	main()

Measured memory_bytes: 69136
from sys import setrecursionlimit
setrecursionlimit(1000000)

def Euclid_algorithm(a:int, b:int)->int:
    if a < b:
        a, b = b, a
    else:
        pass
    if b == 0:
        return a
    else:
        return Euclid_algorithm(b, a % b)

k = int(input())
ans = 0
for h in range(1, k+1):
    for i in range(1, k+1):
        for j in range(1, k+1):
            ans += Euclid_algorithm(h, Euclid_algorithm(i, j))
print(ans)


Measured memory_bytes: 84864
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define vi vector<int>
#define pb push_back
#define INF 999999999
//#define INF (1LL<<59)


#define MAX_V 100000
vector<int> G[MAX_V];   //???
vector<int> rG[MAX_V];  //??????

void add_edge(int from, int to){
    G[from].push_back(to);
    rG[to].push_back(from);
}

void dfs(int v, bool used[MAX_V], vector<int> &vs){
    used[v] = true;
    rep(i,G[v].size()){
        if(!used[G[v][i]])dfs(G[v][i],used,vs);
    }
    vs.push_back(v);
}

void rdfs(int v,int k,vector<int> &sccs, vector<int> &cmp, bool used[MAX_V]){
    used[v] = true;
    sccs.push_back(v);
    cmp[v] = k;
    rep(i,rG[v].size()){
        if(!used[rG[v][i]])rdfs(rG[v][i],k,sccs,cmp,used);
    }
}

int scc(int V, vector< vector<int> > &each_scc, vector<int> &cmp){
    vector<int> vs;
    bool used[MAX_V];
    rep(i,MAX_V)used[i] = false;
    vs.clear();
    rep(v,V){
        if(!used[v]) dfs(v, used, vs);
    }
    
    rep(i,MAX_V) used[i] = false;
    int k=0;
    for(int i=vs.size()-1;i>=0;i--){
        vector<int> sccs;
        if(!used[vs[i]]){
            rdfs(vs[i], k++, sccs, cmp, used);
            each_scc.push_back(sccs);
        }
    }
    return k;
}
/*
 vector<vector<int>> each_scc;  //????????????????????£?????????????????????
 vector<int> cmp(MAX_V);        //???????????????????±??????????????????£??????????????????( ??????each_scc????????????????????? )
 int k = scc(v,each_scc,cmp);   //?????£??????????????°???
*/


int main(){
    int V,E;
    cin>>V>>E;
    rep(i,E){
        int s,t;
        cin>>s>>t;
        add_edge(s,t);
    }
    vector<vector<int>> each_scc;
    vector<int> cmp(MAX_V);
    int k = scc(V,each_scc,cmp);
    
    int q;
    cin>>q;
    rep(i,q){
        int u,v;
        cin>>u>>v;
        if(cmp[u]==cmp[v])cout<<1<<endl;
        else cout<<0<<endl;
    }
}

Measured memory_bytes: 9324
import Control.Monad
import Control.Applicative
import Data.Functor
import Data.List
import Data.List.Split
import Data.Char
import Data.Ord
import Data.Array.IO
import Data.IORef

readInt = read :: String -> Int
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
-- end of templete

wf arr range = do
    forM_ range $ \k -> do
        forM_ range $ \i -> do
            forM_ range $ \j -> do
                before <- readArray arr (i,j)
                after1 <- readArray arr (i,k)
                after2 <- readArray arr (k,j)
                writeArray arr (i,j) $ min before $ after1 + after2

cost arr (-1) = return 0
cost arr n = readArray arr (n,1)

main = do
    arr <- newArray ((0,0),(9,9)) 1234 :: IO (IOUArray (Int, Int) Int)
    [h, w] <- getInts
    forM_ [0..9] $ \i -> do
        cs <- getInts
        forM_ (zip cs [0..9]) $ \(c, j) -> writeArray arr (i,j) c
    wf arr [0..9]
    ref <- newIORef 0
    walls <- concat <$> replicateM h getInts
    forM_ walls $ \n -> do
        cost arr n >>= modifyIORef ref . (+)
    readIORef ref >>= print
    return ()



Measured memory_bytes: 7548
#include <iostream>
#include <utility>
#include <vector>
#include <cstring>
using namespace std;
const int MAX_N = 1000,MAX_M = 1000;
int n;
typedef pair<int,int> P;
P ilist[MAX_N];
P memo[MAX_N + 1][MAX_M + 1];

P comp(const P &a,const P &b){
	if(a.first < b.first) return b;
	return a;
}

P dp(int now,int lim){
	if(memo[now][lim].first > -1){
		return memo[now][lim];
	}
	P res;
	if(now == n) return make_pair(0,0);
	else if(lim < ilist[now].second){
		res = dp(now + 1,lim);
	}
	else{
		res = dp(now + 1,lim - ilist[now].second);
		res.second += ilist[now].second;
		res.first += ilist[now].first;
		res = comp(dp(now + 1,lim),res);
	}
	return memo[now][lim] = res;
}

int main(){
	int lim,cnt = 0,w,v;
	P item;
	char buf;
	while(cin >> lim,lim){
		for(int i = 0;i <= MAX_N;++i){
			for(int j = 0;j <= MAX_M;++j){
				memo[i][j] = make_pair(-1,-1);
			}
		}
		++cnt;
		cin >> n;
		for(int i = 0;i < n;++i){
			cin >> v >> buf >> w;
			ilist[i] = make_pair(v,w);
		}
		item = dp(0,lim);
		cout << "Case " << cnt << ":" << endl;
		cout << item.first << endl << item.second << endl;
	}
	return 0;
}

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

using namespace std;

int main() {

	int n;

	cin >> n;
	vector<long long> arr(n);
	while (n--) {
		cin >> arr[n];
	}

	sort(arr.rbegin(), arr.rend());

	deque<long long> queue;
	long long ans = 0;
	queue.push_back(arr[0]);
	for (int i = 1; i < arr.size(); i++) {
		long long biggest = queue.front(); queue.pop_front();
		ans += biggest;
		long long new_space = min(arr[i], biggest);
		queue.push_back(new_space);
		queue.push_back(new_space);
	}
	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 6420
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	int N;
	cin >> N;
	map<string, int> cnt;
	for (int i = 0; i < N; ++ i) {
		string s;
		cin >> s;
		++ cnt[s];
	}
	cout << "AC x " << cnt["AC"] << endl;
	cout << "WA x " << cnt["WA"] << endl;
	cout << "TLE x " << cnt["TLE"] << endl;
	cout << "RE x " << cnt["RE"] << endl;
}


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

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

using namespace std;

vector<int> divisor(int n)
{
    vector<int> res;
    for(int i=1;i*i<=n;i++){
        if(n%i==0){
            res.push_back(i);
            if(n/i!=i) res.push_back(n/i);
        }
    }
    return res;
}



int main()
{
    int N,A[200010],f[1000100];
    rep(i,1000010){
        f[i]=0;
    }

    cin>>N;
    rep(i,N){
        cin>>A[i];
        //f[A[i]]=1;
    }

    sort(A,A+N);

    int ans = 0;
    rep(i,N){
        int flag = 1;
        for(int j=1;j*j<=A[i];j++){
            if(A[i]%j==0){
                if(f[j]==1 || f[A[i]/j]==1){
                    flag = 0;
                    break;
                }
            }
        }
        if(flag){
            if(i<N-1 && A[i+1]!=A[i]){
                //cout << A[i] << endl;
                ans++;
            }
            if(i==N-1) ans++;
        }
        f[A[i]]=1;
    }

    cout << ans << endl;

    return 0;
}

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

#define int long long
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pld;

#define x first
#define y second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple

#define len(a) ((int) (a).size())
#define all(a) (a).begin(), (a).end()

ld getld() {
    string s;
    cin >> s;
    return stold(s);
}

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    ld a = getld();
    ld b = getld();
    cout << (ll)trunc(a * b);
    return 0;
}


Measured memory_bytes: 3716
#include<bits/stdc++.h>
using namespace std;
main(){
long long i,j,k,l,m,n,p;
while(cin>>p>>n>>m){
if(m-n<=0)cout<<"delicious"<<endl;
else if(m-n<=p)cout<<"safe"<<endl;
else cout<<"dangerous"<<endl;
} return 0;
}


Measured memory_bytes: 256
n=gets.to_i
a=gets.split.map(&:to_i)

a=a.map{|i|
  if i%2>0
    0
  elsif i%4>0
    1
  else
    2
  end
}

c=(0..2).map{|i|a.count(i)}

if c[0]<=c[2] || (c[0]+c[2]==n && c[0]-1==c[2])
  puts "Yes"
else
  puts "No"
end


Measured memory_bytes: 11268
import sys
input = sys.stdin.readline

N, M, C = map(int, input().split())
B = list(map(int, input().split()))
A = [None] * N
for i in range(N):
    A[i] = list(map(int, input().split()))

count = 0
for i in range(N):
    check = 0
    for j in range(M):
        check += A[i][j] * B[j]
    check += C
    if check > 0:
        count += 1
print(count)

Measured memory_bytes: 3064
import java.util.*;
public class Main {
	static char[] l = new char[] {'q','w','e','r','t','a','s','d','f','g','z','x','c','v','b'};
	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		while(true) {
			int n = stdIn.nextInt();
			int m = stdIn.nextInt();
			int p = stdIn.nextInt();
			if(n == 0 && m == 0 && p == 0) break;
			int[] a = new int[n];
			int b = 0;
			for(int i = 0; i < n; i++) {
				a[i] = stdIn.nextInt();
				b += a[i] * 100;
			}
			int c = (int)(b - b * p * 0.01);
			if(a[m-1] == 0) System.out.println("0");
			else {
				System.out.println(c / a[m-1]);
			}
			
		}
	}
}

Measured memory_bytes: 27768
#include <iostream>

using namespace std;
long long X, Y;

int main() {

    cin >> X >> Y;

    if (X % Y == 0) {
        cout << -1 << endl;
        return 0;
    }

    while (X < 1000000000000000000) {
        if (X % Y != 0) {
            cout << X << endl;
            return 0;
        }
        X += X;
    }
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int a,b,i;
  scanf("%d%d",&a,&b);
  char s[12];
  scanf("%*c%s",s);
  for(i=0;i<a+b+1;i++)
    if((s[i]!='-' && i==a) ||(s[i]=='-' && i!=a)){
      puts("No");
      return 0;
    }
  puts("Yes");
  return 0;
}


Measured memory_bytes: 128
N = int(input())
A = list(map(int, input().split()))
S = sum(A)/2
x1 = S - sum([a for a in A[1:N:2]])
ans = "%d"%(x1*2)
x = x1
for a in A[:-1]:
  x = a-x
  ans += " %d"%(x*2)
print(ans)


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

int main(){
    int a,b,c,five=0,seven=0;
    scanf("%d %d %d",&a,&b,&c);
    if(a==5) five++;
    else if(a==7) seven++;
    if(b==5) five++;
    else if(b==7) seven++;
    if(c==7) seven++;
    else if(c==5) five++;
    if(five==2 and seven==1) printf("YES\n");
    else printf("NO\n");
    return 0;
}


Measured memory_bytes: 256