akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

#define MG 210000000

 main(){
	
	int n,m;
	int i,j;
	int a[40],b[40],c[40],d[40];
	int e,f,g=MG,h,l;
	int k[21][21],flg[21],dk[21],dkn;
	int flg2[21],dk2[21];
	
	scanf("%d",&n);
	
	scanf("%d",&m);
	
	for(i=0;i<=n;i++){
		dk[i]=MG;
		flg[i]=0;
		dk2[i]=MG;
		flg2[i]=0;
		for(j=0;j<=n;j++){
			k[i][j]=MG;
		}
	}
	
	for(i=1;i<=m;i++){
		scanf("%d,%d,%d,%d",&a[i],&b[i],&c[i],&d[i]);
	}
	scanf("%d,%d,%d,%d",&e,&f,&dkn,&h);
	
	

	
	for(i=1;i<=m;i++){
		k[a[i]][b[i]]=c[i];
		k[b[i]][a[i]]=d[i];
	}
	

	dk[e]=0;
	
	for(i=0;i<=n;i++){
		g=MG;
		for(j=0;j<=n;j++){
			if(flg[j]==0 && dk[j]<g){
				g=dk[j];
				l=j;
			}
		}
		
		flg[l]=1;
		
		for(j=0;j<=n;j++){
			if(dk[l]+k[l][j]<dk[j]){
				dk[j]=dk[l]+k[l][j];
			}
		}
	}
	
	dk2[f]=0;
	
	for(i=0;i<=n;i++){
		g=MG;
		for(j=0;j<=n;j++){
			if(flg2[j]==0 && dk2[j]<g){
				g=dk2[j];
				l=j;
			}
		}
		
		flg2[l]=1;
		
		for(j=0;j<=n;j++){
			if(dk2[l]+k[l][j]<dk2[j]){
				dk2[j]=dk2[l]+k[l][j];
			}
		}
	}
	
	dkn=dkn-(h+dk[f]+dk2[e]);
	
	printf("%d\n",dkn);
	
	return 0;
	
}

Measured memory_bytes: 1032
#define rep(i, n) for(int i = 0; i < (int)(n); i++)

#include <iostream>
#include <string>
#include <algorithm>
#include<vector>
#include<unordered_set>
using namespace std;

int main(){
    long long int ii,n,m,x;
    long long int ans[100000]={0};
    long long int ansz;
    bool flag = true;
    unordered_set<long long int > s;
    cin >> n >> x >> m;
    ans[1]= x;
    for(long long int i = 2; i <=n; i++){
        x = ((x%m)*(x%m)%m);
        if(s.find(x)!=s.end()){
            for(int j =1;j < i ;j++){
                if(ans[j]-ans[j-1] == x){
                    ii = j;
                    break;
                }
            }
            ansz = ans[(n-ii)%(i-ii)+ii]+  (ans[i-1]- ans[ii-1]) * ((n-ii)/(i-ii)); //ここあとでかく
            //cout << ans[(n-ii)%(i-ii)+ii] << " " << (ans[i-1]- ans[ii-1]) << " "  << (n-ii)/(i-ii) << endl;
            flag = false;
            break;
        }else{
            ans[i]= x + ans[i-1];
            s.insert(x);
        }
    }
    if(flag){
        cout << ans[n] << endl;
    }else{
        cout << ansz << endl;
    }
}

Measured memory_bytes: 5588
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,k;
    cin>>n>>k;
    long long arr[n+1];
    arr[0]=0;
    for(long long i=1;i<=n;i++)
    cin>>arr[i];
    long long dp[n+1];
    dp[0]=0;
    dp[1]=0;
    for(long long i=2;i<=n;i++)
    {
        long long ans=100000000000;
            for(long long int j=max(1LL,i-k);j<i;j++)
            {
                ans=min(ans,dp[j]+abs(arr[j]-arr[i]));
            }
            dp[i]=ans;
    }
    cout<<dp[n];
}

Measured memory_bytes: 1792
V, E = map(int, input().split())

adjacents = []

for i in range(V):
  adjacents.append([])

for i in range(E):
  s, t = map(int, input().split())
  adjacents[t].append(s)

def topological_sort(num, adjacents):
  colors = ["white"] * num
  result = []

  def dfs(u):
    if colors[u] == "black":
      return

    colors[u] = "black"

    for a in adjacents[u]:
      if colors[a] != "black":
        dfs(a)

    result.append(u)

  for n in range(num):
    dfs(n)

  return result

for i in topological_sort(V, adjacents):
  print(i)


Measured memory_bytes: 8692
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for(int i=0; i<n; i++)
#define reps(i, s, e) for(int i=s; i<e; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define reprs(i, s, e) for(int i=e-1; i>=s; i--)

int main(){

    int h, w; cin >> h >> w;
    int c[10][10];
    rep(i, 10){
        rep(j, 10){
            cin >> c[i][j];
        }
    }

    map<int, int> mp;
    rep(i, h){
        rep(j, w){
            int a; cin >> a;
            if(a == -1) continue;

            mp[a]++;
        }
    }

    rep(k, 10){
        rep(i, 10){
            rep(j, 10){
                c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
            }
        }
    }

    // rep(i, 10){
    //     rep(j, 10){
    //         cout << c[i][j] << " ";
    //     }
    //     cout << endl;
    // }

    ll cnt = 0;
    for(auto x : mp){
        cnt += x.second * c[x.first][1];
    }

    cout << cnt;



    return 0;
}

Measured memory_bytes: 256
// #include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <climits>
#include <string>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <ctime>
#include <cassert>
#include <fstream>
#include <stack>
#include <random>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define all(a) a.begin(), a.end()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template<typename T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template<typename T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template<typename T>
void vdeb(std::vector<T> &da) {
    for (int i = 0;i < da.size();i++) {
        if (i == da.size() - 1) std::cout << da[i];
        else std::cout << da[i] << ' ';
    }
    std::cout << '\n';
}
template<typename T>
void vdeb(std::vector<std::vector<T>> &da) {
    for (int i = 0;i < da.size();i++) {
        std::cout << i << ' ';
        vdeb(da[i]);
    }
    std::cout << '\n';
}

using namespace std;

int main() {
    ll n; cin >> n;
    string ans = "";
    while(n) {
        int now = n%26;
        if(now == 0) now = 26;
        ans += 'a' + now -1;
        n = (n-now)/26;
    }
    reverse(all(ans));
    cout << ans << endl;
}

Measured memory_bytes: 3628
#include <math.h>
#include <ctype.h>
#include <limits.h>
#include <assert.h>

#include <vector>
#include <numeric>
#include <iostream>
#include <algorithm>
#include <functional>

#define nl                std::cout << "\n"
#define in(x)             std::cin  >> (x)
#define out(x)            std::cout << (x) << " "
#define err(x)            std::cerr << #x << "=" << (x) << " | "

#define inn(x)            int x; in(x)
#define rep(i, n)         for (int i =  0 ; i < (n); ++i)
#define per(i, n)         for (int i = (n) - 1; i > -1; --i)
#define repr(i, l, r)     for (int i = (l); i < (r); ++i)

#define no                puts("NO")
#define yes               puts("YES")

using ll  = long long int;
using vi  = std::vector<int>;
using ii  = std::pair<int, int>;
using iii = std::pair< ii, int>;
using vii = std::vector<ii>;

const int N = 1010101;
const int MD = 1e9 + 7;

void solve() {
    inn(n); inn(W);

    int w[n], v[n];
    rep(i, n) {
        in(w[i]);
        in(v[i]);
    }

    ll dp[W + 1];
    rep(i, W + 1) dp[i] = (i >= w[0]) ? v[0] : 0;

    repr(i, 1, n) {
        for (int j = W; j >= w[i]; --j) {
            dp[j] = std::max(dp[j], dp[j - w[i]] + v[i]);
        }
    }

    out(dp[W]);
}

int main() {
    std::ios_base::sync_with_stdio(0); std::cin.tie(0); std::cout.tie(0);

    //inn(t); repr(tc, 1, t + 1)
    solve();

    return 0;
}


Measured memory_bytes: 1024
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush
from bisect import bisect_left,bisect_right 
import sys,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()))

x,y,z,k = inpl()
a = inpl()
b = inpl()
c = inpl()
ab = []
for s in a:
    for t in b:
        ab.append(s+t)
ab.sort(reverse = True)
ab = ab[:3000]
abc = []
for s in ab:
    for j in c:
        abc.append(s+j)
abc.sort(reverse = True)
print(*abc[:k])


Measured memory_bytes: 221976
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define fast ios_base::sync_with_stdio(false),cin.tie(nullptr)
#define pi 3.14159265358979323846264338327950L
#define modd 1000000000
#define k 100000000

int main()
{
        fast;
        int t=1;
       // cin>>t;
        while(t--)
        {
             ll a,b,n,x;
             cin>>a>>b>>n;
             x=min(b-1,n);
             cout<<floor((a*x)/b)<<endl;
        }
}

Measured memory_bytes: 3696
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <algorithm>
#include <bitset>
#include <tuple>
#include <set>
#include <map>
#define range(i, r) for(int i=0;i<r;i++)
#define ranges(i, l, r) for(int i=l;i<r;i++)
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi std::vector<std::vector<int> >
#define vvl std::vector<std::vector<ll> >
#define MODs 1000000007;
typedef long long int ll;
using namespace std;

int main(int argc, char const *argv[]) {
  ll N, M, reg;
  std::cin >> N >> M;
  set<int> a;
  range(i, M) {
    std::cin >> reg;
    a.insert(reg);
  }
  std::vector<int> dp(N+1, 0);
  dp[0] = 1;
  auto itr = a.find(1);
  if(itr!=a.end()){
    dp[1] = 0;
  }else{
    dp[1] = 1;
  }
  for(int i=2; i<N+1;i++){
    auto itr2 = a.find(i);
    if(itr2!=a.end()) dp[i] = 0;
    else{
      dp[i] = (dp[i-1] + dp[i-2])%1000000007;
    }
  }
  std::cout << dp[N] << '\n';
  return 0;
}


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

using namespace std;
using std::vector;

#define ll long long
#define vi  vector<int>
#define vvi vector<vi>
#define pi  pair<int,int>
#define mp  make_pair
#define pb  push_back
#define MOD int(1e9) + 7
#define PAI  3.1415926535
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define chmax(x,y) x = max(x,y)
#define chmin(x,y) x = min(x,y)
#define pr(x) cout << x << endl
#define Endl endl
#define rep(i,n) for(int i = 0 ; i < n; i++)

const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
const int ddx[8] = {-1,0,1,-1,1,-1,0,1};
const int ddy[8] = {-1,-1,-1,0,0,1,1,1};
const int inf = 99999999;
const ll linf = 1LL << 62;

ll gcd(ll a,ll b){
  if(a < b)swap(a , b);
  if(a % b != 0) gcd(b, a%b);
  return b;
}

ll lcm(ll a,ll b){
  if(a < b)swap(a , b);
  return (a / gcd(a , b)) * b;
}

int main(){
 
  int n; cin >> n;
  vi v(n);
  rep(i,n) cin >> v[i];
  int ans = 0;
  int h = v[0];

  for(int i = 1; i < n;i++){
    if(h <= v[i]){
      ans++;
      h = v[i];
    }
  }
 
  pr(ans + 1);

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#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)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main(){

  int a,b,c;
  cin>>a>>b>>c;
  int x,y;
  x = max(c,max(a,b));
  y = min(c,min(a,b));
  cout<<x-y<<endl;


  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  int count=0;
  cin >>S;
  for(int i=0;i<S.size();i++){
    if(S.at(i)=='x'){count++;}
  }
  if(count>7){cout <<"NO"<<endl;}
  else{cout <<"YES"<<endl;}
      }

Measured memory_bytes: 256
#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;
const int INF=1145141919,MOD=1e9+7;
const long long LINF=8931145141919364364,LMOD=998244353;
// const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};

int main(){
    long long n,t,a; cin>>n>>t>>a;
    a*=1000,t*=1000;
    long long diff=LINF,ans=1;
    rep(i,n){
        long long h; cin>>h;
        long long ave=t-h*6;
        if(abs(a-ave)<diff){
            ans=i+1;
            diff=abs(a-ave);
        }
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;

const ll mod=1e9+7;

#define all(x) x.begin(),x.end()
#define allr(x) x.rbegin(),x.rend()
#define rc(x)  return cout<<x<<"\n",0
#define sz(s)  (int) s.size()

#define pb push_back
#define mp make_pair
#define fr first
#define sc second

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

ll pow(ll a, ll b)
{
	ll res=1;
	while(b)
	{
		if(b%2) res=(res*a)%mod;
		a=(a*a)%mod;
		b/=2;
	}
	return res;
}

int dp[3001][3001];
string x,y;

void afisare(int i,int j)
{
	if(dp[i][j])
	{
		if(x[i-1]==y[j-1]) afisare(i-1,j-1); else
		if(dp[i][j]==dp[i-1][j]) afisare(i-1,j); else 
		if(dp[i][j]==dp[i][j-1]) afisare(i,j-1);
		if(x[i-1]==y[j-1]) cout<<x[i-1];
	}
}

int ugabuga()
{

	cin>>x>>y;

	for(int i=1;i<=sz(x);i++)
	for(int j=1;j<=sz(y);j++)
	{
		if(x[i-1]==y[j-1]) dp[i][j]=dp[i-1][j-1]+1; else
		dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
	}
	afisare(sz(x),sz(y));

	return 0;
}


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

    int t=1;
    //cin>>t;
    while(t--)
    {
        ugabuga();
    }

}

Measured memory_bytes: 35840
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <list>
#include <ctime>
#include <complex>

#define ff first
#define ss second

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

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

    string s;
    cin>>s;
    if(s[0]=='S') cout<<"Cloudy";
    else if(s[0]=='C') cout<<"Rainy";
    else cout<<"Sunny";

    return 0;
}


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

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> l(N);
  for (int i = 0; i < N; ++i) cin >> l.at(i);
  
  sort(l.begin(), l.end());
  reverse(l.begin(), l.end());
  
  int total = 0;
  for (int i = 0; i < K; ++i) total += l.at(i);
  
  cout << total << endl;
}

Measured memory_bytes: 256
# 要は、M 階動的に最大値を半分にしていけばよい
import heapq
n, m = map(int, input().split())
a = list(map(int, input().split()))
a = [i*-1 for i in a]
heapq.heapify(a)

for _ in range(m):
    pop = heapq.heappop(a)
    p = -(pop*-1//2)
    # 負数の切り捨て（割り切れないとき）は絶対値が1上がるので注意
    heapq.heappush( a, p)
print(sum(list(a))*-1)

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

int main() {
	int n, j, key;
	cin >> n;
	int *a = new int[n];
	for(int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n; i++) {
		key = a[i];
		j = i - 1;
		while(( j >= 0) && (a[j] > key)) {
			a[j+1] = a[j];
			a[j--] = key;
		}
		for (int j = 0; j < n-1; j++)
			cout << a[j] << ' ';
		cout << a[n-1] << endl; 
	}
	return 0;
}

Measured memory_bytes: 3068
#include <iostream>
#include<string>
#include<cstring>
#include <cstdio>
#include<utility>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<bitset>
#include<queue>
#include<stack>
#include<set>
#include <limits>
#include <climits>
#include <numeric>
#include<cassert>
#include<cctype>
#include<iterator>
using namespace std;
typedef long long ll;
typedef vector<ll>VI;
typedef vector<bool>VB;
typedef pair<ll,ll>P;
typedef pair<double,double>P_D;
#define VV(T) vector<vector<T>>
#define PI 3.1415926535897932384626433832795
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define reprev(i, n) for (ll i = (ll)n - 1; i >= 0; i--)
#define bitrep(bit,A) for(int bit=A; ;bit=(bit-1)&A)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) (ll)((a).size())
#define c_max(a, b) (((ll)a)>((ll)b)?(a):(b))
#define c_min(a,b) (((ll)a)<((ll)b)?(a):(b))
#define chmax(x,a) x=c_max(x,a)
#define chmin(x,a) x=c_min(x,a)
#define vmax(v) *max_element(ALL(v))
#define vmin(v) *min_element(ALL(v))
#define SORT(c) stable_sort(ALL(c))
#define $(x) {cout<<#x<<" = " <<(x)<<endl;}
#define fi first
#define se second
#define MAX 100100//5
#define MAX2 200100
#define MAX_6 1001001//6
#define MAX_7 10010010//7
#define SENTINEL 2000000000//9
#define NIL -1
#define MOD 1000000007
#define INF 1<<30
#define INFTY 1000000000000000001LL
#define MAX_INT INT_MAX
#define Endl '\n'
#define greater greater<int>()
VI findAll(string S,string pattern){VI P;ll pos=(ll)S.find(pattern);
while(pos!=string::npos){P.push_back(pos);pos=(ll)S.find(pattern,pos+1);}return P;}
inline ll GCD(ll a,ll b){return b?GCD(b,a%b):a;}
inline ll lcm(ll a,ll b){return a*b/GCD(a,b);}
bool is_prime(ll n){if(n<2)return 0;for(int i=2;i*i<n;i++)if(n%i==0)return 0;return 1;}
inline void eratosthenes(VB& p){rep(i,SZ(p))p[i]=1;p[0]=p[1]=0;
rep(i,SZ(p)/2+1){if(p[i])for(ll j=i+i;j<SZ(p);j+=i)p[j]=0;}}
inline ll mod_add(ll a,ll b){return (a+b)%MOD;}
inline ll mod_sub(ll a,ll b){return (a+MOD-b)%MOD;}
inline ll mod_mul(ll a,ll b){return ((a%MOD)*(b%MOD))%MOD;}
inline ll mod_pow(ll x,ll n,ll mod=(ll)MOD){ll res=1;while(n>0){
if(n&1)res=res*x%mod;x=x*x%mod;n>>=1;}return res;}
inline ll mod_inv(ll x){return mod_pow(x,MOD-2);}
inline ll mod_div(ll a, ll b){return mod_mul(a,mod_inv(b));}
using Graph=vector<vector<int> >;//int と P
int main(){
    ll n;cin>>n;
    ll T[1010],A[1010];rep(i,n)cin>>T[i]>>A[i];
    ll t=T[0],a=A[0];
    for(int i=1;i<n;i++){
        ll rate=max((t+T[i]-1)/T[i],(a+A[i]-1)/A[i]);
        t=rate*T[i];a=rate*A[i];
    }
    cout<<t+a<<endl;
}

Measured memory_bytes: 256
# Author: cr4zjh0bp
# Created: Thu Mar 12 19:40:42 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
nf = lambda: float(ns())
nfn = lambda y: [nf() for _ in range(y)]
nfa = lambda: list(map(float, stdin.readline().split()))
nfan = lambda y: [nfa() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()

N = ni()
S = nas()
c = dict()
for i in range(N):
    c[S[i]] = 1

print("Three" if len(c.items()) == 3 else "Four")

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <assert.h>

using namespace std;

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

int main()
{
  int N, R;
  cin >> N >> R;
  int ans;
  if (N >= 10)
  {
    ans = R;
  }
  else
  {
    ans = R + 100 * (10 - N);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
#define LL long long
const LL LINF = 1e18;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<int,int>
#define I vector<int>
#define S set<int>
#define pb(v) push_back(v)
#define V vector
#define rt return

int main(){
   CIN(N);CIN(M);
   LL ans = 1;
   if(abs(N-M)<=1){
       FOR(a,1,N+1){
           ans*=a;
           ans%=MOD;
       }
       FOR(a,1,M+1){
           ans*=a;
           ans%=MOD;
       }
       if(N==M){
           ans*=2;
           ans%=MOD;
       }
       COUT(ans);
   }else{
       COUT(0);
   }
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
 public static int md(int as,int bs,int ap,int bp){
	 return Math.abs(as-ap)+Math.abs(bs-bp); 
 }
 public static void main(String[] args){
	Scanner sc=new Scanner(System.in);
	int N =Integer.parseInt(sc.next());
	int M =Integer.parseInt(sc.next());
	int[] as = new int[N];
	int[] bs = new int[N];
	for(int i=0;i<N;i++){
		as[i]=Integer.parseInt(sc.next());
		bs[i]=Integer.parseInt(sc.next());
	}
	int[] ap = new int[M];
	int[] bp = new int[M];
	for(int i=0;i<M;i++){
		ap[i]=Integer.parseInt(sc.next());
		bp[i]=Integer.parseInt(sc.next());
	}
	for(int i=0;i<N;i++){
		int minj=0;
		int mind=md(as[i],bs[i],ap[0],bp[0]);
		for(int j=1;j<M;j++){
			int d=md(as[i],bs[i],ap[j],bp[j]);
			if(d<mind){
				minj=j;mind=d;
			}
		}
		System.out.println(minj+1);
	}

 }
}


Measured memory_bytes: 23508
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
const int inf = 1e9 + 7;
const ll INF = 1e18;
// int mod = 998244353;
int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { a += b; if (a >= mod) a -= mod; }


void solve();

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

  int T;
  // cin >> T;
  T = 1;

  while (T--) {
    solve();
  }
}

void solve() {
  int n;
  cin >> n;
  vector<int> a(n + 1);
  rep3(i, 1, n + 1) cin >> a[i];

  vector<int> b(n + 1);
  for (int i = n; i >= 1; --i) {
    int sum = 0;
    for (int j = i; j <= n; j += i) {
      (sum += b[j]) %= 2;
    }
    if (sum != a[i]) b[i] = 1;
  }
  vector<int> ans;
  rep3(i, 1, n + 1) if (b[i]) ans.eb(i);
  cout << sz(ans) << endl << ans << endl;
}


Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define pf push_front
#define pii pair <int, int>
#define all(vv) (vv).begin(), (vv).end()
#define time cerr << '\n' << (double)clock()/CLOCKS_PER_SEC << '\n'; return 0

int n, m;
map <int, int> G;

int32_t main() {
	cin >> n >> m;
	for(int i = 0; i < m; ++i) {
		int a, b; cin >> a >> b;
		G[a - 1]++;
		G[b - 1]++;
	}
	for(int i = 0; i < n; ++i) {
		cout << G[i] << '\n';
	}
	time;
}

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

int main(){
    int a,b; cin >> a >> b;
    int ans = -1;
    int p = b*10;
    while(p*0.04<=a){
        if(floor(p*0.08)==a &&floor(p*0.1)==b){
            ans = p;
            break;
        }
        p++;
    }
  cout << ans << endl;
}

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

int main(int argc, char* argv[]){
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N; cin >> N;
	if(N <= 999)
		printf("ABC\n");
	else
		printf("ABD\n");
	return 0;
}

Measured memory_bytes: 3628
# https://atcoder.jp/contests/abc079/tasks/abc079_d
# ワーシャルフロイド

h, w = map(int, input().split())
edge = [[] for _ in range(10)]
for i in range(10):
    edge[i] = list(map(int, input().split()))

num = [list(map(int, input().split())) for _ in range(h)]

for k in range(10):
    for i in range(10):
        for j in range(10):
            # iからjへの最短距離
            # 負の辺がある場合　つっこむとかなり遅くなる
            # if edge[i][k] != float('inf') and edge[k][j] != float('inf'):
            edge[i][j] = min(edge[i][j], edge[i][k] + edge[k][j])

ans = 0
for i in num:
    for j in i:
        if j == 1 or j == -1:
            continue
        else:
            ans += edge[j][1]

print(ans)


Measured memory_bytes: 40540
#include <iostream>
#include <algorithm>

using namespace std;

int main() {
    long n, sum=0;
    cin >> n;
    for (long m=1; m<=n; m++) {
        if (n / m < m + 2) break;
        if (n%m != 0) continue;
        sum += n/m - 1;
    }
    cout << sum << '\n';
    return 0;
}


Measured memory_bytes: 256
# ABC061C - Big Array
import sys
input = sys.stdin.readline

def main():
    n, k = map(int, input().split())
    memo = [0] * (10 ** 5 + 1)
    for _ in range(n):
        i, j = map(int, input().split())
        memo[i] += j
    for i, j in enumerate(memo):
        k -= j
        if k <= 0:
            print(i)
            break


if __name__ == "__main__":
    main()


Measured memory_bytes: 5748
/* ex4-4
   Yuta Takayanagi  */

#include<stdio.h>
int main(void){
    int number, bit1, bit2, i;

    scanf( "%d" , &number);

    bit1 = number % 10;
    number = (number - bit1) / 10;

    for(i=0; i < 3; i++){

        bit2 = number % 10;
        number = (number - bit2) / 10;

        if(bit1==bit2){

            printf( "Bad\n" );

            return 0;

        }

        bit1 = bit2;

    }

    printf( "Good\n" );

    return 0;

}

Measured memory_bytes: 128
from collections import defaultdict
n, x, y= list(map(int, input().split()))
k = [0]*n
for i in range(1,n):
  for j in range(i+1,n+1):
    c = min(j-i, abs(x-i)+abs(y-j)+1, abs(x-j)+abs(y-i)+1)
    k[c] = k[c] + 1
for i in k[1:]:
  print(i)



Measured memory_bytes: 47708
import java.io.*;
import java.util.*;
 
public class Main {
	static final Reader in = new Reader();
	static final PrintWriter out = new PrintWriter(System.out);
	static final long A=2147483647;
	
	public static void main(String[] args) {
		int n=in.nextInt();
		long[] x = new long[n], y = new long[n];
		for(int i=0; i<n; ++i) {
			x[i]=in.nextInt()+A;
			y[i]=in.nextInt()+A;
			if(i>0&&(x[i]+y[i])%2!=(x[i-1]+y[i-1])%2) {
				System.out.println(-1);
				return;
			}
		}
		boolean al=false;
		if((x[0]+y[0])%2==0) {
			al=true;
			for(int i=0; i<n; ++i)
				++x[i];
		}
		out.println((31+(al?1:0)));
		for(int i=0; i<31; ++i)
			out.print((1L<<i)+" ");
		if(al)
			out.print(1);
		out.println();
		for(int i=0; i<n; ++i) {
			for(int j=0; j<31; ++j) {
				if(x[i]%(1L<<(j+1))==0) {
					y[i]-=1L<<j;
					if(j>29!=(x[i]%(1L<<(j+2))==y[i]%(1L<<(j+2)))) {
						out.print('R');
						x[i]-=1L<<(j+1);
					} else
						out.print('L');
				} else {
					x[i]-=1L<<j;
					if(j>29!=(y[i]%(1L<<(j+2))==x[i]%(1L<<(j+2)))) {
						out.print('U');
						y[i]-=1L<<(j+1);
					} else
						out.print('D');
				}
			}
			if(al)
				out.print('L');
			out.println();
		}
		out.close();
	}
	
	static class Reader {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st;
		String next() {
			while(st==null||!st.hasMoreTokens()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch(Exception e) {}
			}
			return st.nextToken();
		}
		int nextInt() {
			return Integer.parseInt(next());
		}
	}
}

Measured memory_bytes: 22996
#include "bits/stdc++.h"
using namespace std;
// #define endl '\n'
// #define double long double
// #define int long long
// int MOD = 1000 * 1000 * 1000 + 7;
// int MOD = 998244353;

signed main() {
	
	int a, b, c;
	cin >> a >> b >> c;
	swap(a, b);
	swap(a, c);
	cout << a << ' ' << b << ' ' << c;
	
}


Measured memory_bytes: 256
lines = []
while line = gets
    lines << line.chomp.split(' ').map(&:to_i)
end

N = lines[0][0]
$x = []
$y = []
for i in 1..N do
  $x.push(lines[i][0])
  $y.push(lines[i][1])
end

def length(i,j)
  return (($x[i-1] - $x[j-1]) ** 2 + ($y[i-1] - $y[j-1]) ** 2) ** 0.5
end

sum_length = 0
for i in 1..N-1 do
  for j in i+1..N do
    sum_length += length(i,j)
  end
end

print 2 * sum_length / N

Measured memory_bytes: 1788
#include <bits/stdc++.h>
#include <iostream>
#include<math.h>
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main()
{
    double percent = 0.0;
    double N, K;
    cin >> N >> K;
    for (int64_t i=1; i<=N; i++) {
        int64_t count = 0;
        int64_t n = i;
        while (n < K) {
            n = n * 2;
            count += 1;
        }

        if (count == 0) {
            percent += 1 / N;
        } else {
            percent += ((1 / N) * pow(0.5, count));
        }
    }

    cout << setprecision(13) << percent << endl;
    return 0;
}

Measured memory_bytes: 4008
#include <cstdio>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <cmath>

using namespace std;

int main() {
  long a[3], k;
  cin>>a[0]>>a[1]>>a[2]>>k;
  sort(a,a+3);
  a[2] <<= k;
  cout<<(a[0]+a[1]+a[2])<<endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long int lint;
typedef pair<lint, lint> plint;
typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
template<class T>bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T & a, const T & b) { if (b < a) { a = b; return 1; } return 0; }
template<typename T1, typename T2> pair<T1, T2> operator+(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first + r.first, l.second + r.second); }
template<typename T1, typename T2> pair<T1, T2> operator-(const pair<T1, T2>& l, const pair<T1, T2>& r) { return make_pair(l.first - r.first, l.second - r.second); }
const lint MOD = 1e9 + 7, MAX = 1e18;
typedef long double ld;

lint N, arr[100001], sum[100002];
int main() {
	cin.tie(0); ios_base::sync_with_stdio(false);
	cin >> N;
	REP(i, N + 1) {
		cin >> arr[i];
	}
	sum[N + 1] = 0;
	IREP(i, N + 1) {
		sum[i] = sum[i + 1] + arr[i];
	}
	lint cnt = 1, vertex_cnt = 1 - arr[0];
	if (vertex_cnt < 0) {
		cout << -1 << endl;
		return 0;
	}
	REP(i, N) {
		vertex_cnt = min(vertex_cnt * 2 - arr[i+1], sum[i + 2]);
		if (vertex_cnt < 0) {
			cout << -1 << endl;
			return 0;
		}
		cnt += (vertex_cnt + arr[i+1]);
	}
	cout << cnt << endl;
}


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

ll l, r, c;
int main () {
	cin >> l >> r;
	if (l <= 0 && r >= 0) return puts("Zero"), 0;
	c = l < 0 ? -l : 0;
	c -= r < 0 ? -r + 1 : 0;
	puts(c & 1 ? "Negative" : "Positive");
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.next();
        int N = S.length();
        char[] c = S.toCharArray();
        int ans = 0;
        for (int i=0;i<N/2;i++) {
            if (c[i]!=c[N-1-i]) ans++;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 23892
a,b,c,d=map(int, input().split())

if c%b==0:
    taka=c//b
else:
    taka=c//b+1
    
if a%d==0:
    ao=a//d
else:
    ao=a//d+1
    

if taka<=ao:
    print("Yes")
else:
    print("No")
    

Measured memory_bytes: 9160
def is_kaibun(str):
    for i in range(len(str) // 2):
        if str[i] != str[~i]:
            return False
    return True


s = input()
n = len(s)
if (is_kaibun(s) and is_kaibun(s[:n // 2])
        and is_kaibun(s[n // 2 + 1 if n % 2 else n // 2:])):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3060
#include <iostream>
#include <climits>
using namespace std;
int N;
int L;
int apple[200];

int abs(int i)
{
	if(i >= 0)return i;
	else return -1 * i;
}
int main(){
	cin >> N >> L;
	
	int min_value = INT_MAX;
	int min_index = INT_MAX;
	int sum = 0;
	for(int i = 1; i < N+1; i++){
		int azi = L + i - 1;
		sum += azi;
		if( abs( azi ) < min_value ) {
			min_value = abs(azi);
			min_index = i;
		}
	}
	cout << sum - (L + min_index -1 ) << endl;
	
}

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd, log
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

def main():
	N = INT()
	A = [LIST() for _ in range(N)]

	match = defaultdict(int)
	cnt = 0
	for i, j in combinations(range(N), 2):
		match[(i, j)] = cnt
		match[(j, i)] = cnt
		cnt += 1

	V = N*(N-1)//2
	graph = [[] for _ in range(V)]
	dag = [0]*V

	for i in range(N):
		for j in range(N-2):
			graph[match[(i, A[i][j]-1)]].append(match[(i, A[i][j+1]-1)])
			dag[match[(i, A[i][j+1]-1)]] += 1

	q = deque([i for i in range(V) if dag[i] == 0])
	day = [1]*V
	while q:
		p = q.popleft()
		for v in graph[p]:
			dag[v] -= 1
			if dag[v] == 0:
				day[v] = day[p]+1
				q.append(v)
				ans = day[v]

	if any(dag):
		print(-1)
	else:
		print(ans)

if __name__ == '__main__':
	main()




Measured memory_bytes: 271716
a,b,n = map(int,input().split())
def floor(x):
    return (a*x)//b - a*(x//b)
ans = 0
if b <= n: 
    '''
    for i in range(b-1,n+1):
        ans = max(ans,floor(i))
        #print(floor(i))
    print(ans)
    '''
    print(floor(b-1))
else:
    print(floor(n))

Measured memory_bytes: 61836
object Main {
  def main(args: Array[String]): Unit = {
    solve
  }

  def solve(): Unit = {
    val sc = new java.util.Scanner(System.in)
    val n = sc.nextInt
    val v = new Array[Int](n)
    for (i <- 0 until n) {
      v(i) = sc.nextInt
    }
    val sortedV = v.sorted
    var tmp = sortedV(0).toDouble
    for (i <- 1 until n) {
      tmp = (tmp + sortedV(i)) / 2
    }

    println(tmp)
  }
}


Measured memory_bytes: 25416
n = int(input())
s = input()
mod = 10**9+7
data = {}
for i in s:
    if i in data:
        data[i] += 1
    else:
        data[i] = 1
ans = 1
for i in data.values():
    ans *= i+1
    ans %= mod
print(ans-1)

Measured memory_bytes: 3188
/*
 * written by Yaqi Zhang
 * University of Wisconsin-Madison
 * 2020
 */

#include<algorithm>
#include<cstring>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stdio.h>
#include<vector>

#define INF 0x3f3f3f3f

using namespace std;

const int MOD = 1e9 + 7;

int modpow(int x, int y, int mod) {
    if (y == 0) return 1;
    int half = modpow(x, y / 2, mod);
    if(y & 1) return 1LL * half * half % mod * x % mod;
    else return 1LL * half * half % mod;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> dp(k + 1, -1);
    for(int x = k; x > 0; --x) {
        int cnt = k / x;
        dp[x] = modpow(cnt, n, MOD);
        for(int i = 2; i <= cnt; ++i) {
            dp[x] = (dp[x] - dp[x * i] + MOD) % MOD;
        }
    }
    int ans = 0;
    for(int i = 1; i <= k; ++i) {
        ans = (ans + 1LL * i * dp[i] % MOD) %MOD;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 3696
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
 
using namespace std;
 
#define rep(i,n) for(int i=0; i<(n); i++)
#define repc(i,s,e) for(int i=(s); i<(e); i++)
#define pb(n) push_back((n))
#define mp(n,m) make_pair((n),(m))
#define all(r) r.begin(),r.end()
#define fi first
#define se second
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
 
const int INF = 10000000;
const int mod = 1e9 + 7;
const double EPS = 1e-9;
 
const int MAX_N = (int)(1e6) +10;

vi isPrime(MAX_N, 1);
vi primes;

void setPrime(){
	isPrime[0] = isPrime[1] = 0;
	for(int i = 2; i < MAX_N; i++){
		if(isPrime[i]==1){
			primes.pb(i);
			for(int j = i + i; j < MAX_N; j += i){
				isPrime[i] = 0;
			}
		}
	}
}

vi func(int n){
	vi ret;
	for(int i = 0; i < primes.size() && primes[i] <= n; i++){
		while(n %primes[i] == 0){
			n /= primes[i];
			if(ret.size() == 0 || *ret.rbegin() != primes[i]){
				ret.pb(primes[i]);
			} 
		}
	}
	return ret;
}

int calc(vi v){
	int ret = 0;
	for(vi::iterator it = v.begin(); it != v.end(); it++){
		ret -= *it;
	}
	ret += *v.rbegin()*2;
	return ret;
}

int main(){
	setPrime();
	int a, b;
	while(cin>>a>>b){
		if(a == 0 && b == 0) break;
		// for(int i = 0; i < func(a).size(); i++){
		// 	cout<<" "<<func(a).at(i);
		// }
		// cout<<endl;
		// cout<<calc(func(a))<<" "<<calc(func(b))<<endl;
		if(calc(func(a)) > calc(func(b))) cout<<"a"<<endl;
		else cout<<"b"<<endl;
	}
}

Measured memory_bytes: 9760
N, K, L = [int(_) for _ in input().split()]


class UFT():
    def __init__(self):
        self.par = {}
        self.rank = {}
        for i in range(1, N + 1):
            self.par[i] = i
            self.rank[i] = 0

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            self.par[x] = self.find(self.par[x])
            return self.par[x]

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return

        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def same(self, x, y):
        return self.find(x) == self.find(y)


Road = UFT()
for _ in range(K):
    p, q = [int(_) for _ in input().split()]
    Road.unite(p, q)
Railway = UFT()
for _ in range(L):
    r, s = [int(_) for _ in input().split()]
    Railway.unite(r, s)
memo = {}
for i in range(1, N + 1):
    memo[Road.find(i), Railway.find(i)] = memo.get(
        (Road.find(i), Railway.find(i)), 0) + 1
print(' '.join(str(memo[Road.find(i), Railway.find(i)])
               for i in range(1, N + 1)))


Measured memory_bytes: 106648
S = input()

N = len(S)
halfN = int((N-1)/2)

Ans = 'Yes'

for indx in range(halfN):
    if S[indx] != S[(N-1)-indx]:
        Ans = 'No'

if Ans == 'No':
    print(Ans)
else:
    for halfIndx in range(int(halfN/2)):
        if S[halfIndx] != S[(halfN-1) - halfIndx]:
            Ans = 'No'
    print(Ans)


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

using namespace std;

int main(){
  int n; cin>>n;
  int mn=n+1;
  int ans=0;
  for(int i=0;i<n;i++){
    int x;cin>>x;
    if(x<mn){
     ans++;
     mn=x;

    }

  }  cout<<ans;

    return 0;
}


Measured memory_bytes: 3592
import java.io.*;
import java.math.BigInteger;
import java.util.*;


public class Main implements Runnable {

    private void solve() throws IOException {

        int N = nextInt();
        int L = nextInt();
        String[] s = new String[N];
        for(int i = 0; i < N; ++i) {
            s[i] = reader.readLine();
        }
        Arrays.sort(s);
        String ret= "";
        for(int i = 0; i < s.length; ++i) ret += s[i];
        writer.println(ret);
    }

    public static void main(String[] args) {

        new Main().run();
    }

    BufferedReader reader;
    StringTokenizer tokenizer;
    PrintWriter writer;

    public void run() {
        try {
            reader = new BufferedReader(new InputStreamReader(System.in));
//             reader = new BufferedReader(new FileReader("input.txt"));
            tokenizer = null;
            writer = new PrintWriter(System.out);
            solve();
            reader.close();
            writer.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

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

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

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

    String nextToken() throws IOException {
        while(tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }

        return tokenizer.nextToken();
    }
}


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

string n;
int cnt;

int main()
{
    cin >> n;
    if(n.size() == 1){
        cout << n << endl;
        return 0;
    }
    for(int i = 1; i < n.size(); i++){
        if(n[i] == '9'){
            cnt++;
        }
    }
    if(cnt == n.size() - 1){
        cout << 9 * (n.size() - 1) + (n[0] - '0') << endl;
        return 0;
    }
    cout << (n[0] - '0') - 1 + 9 * (n.size() - 1) << endl;



    return 0;
}


Measured memory_bytes: 256
a = []
for i in range(3):
    a.append(list(map(int, input().split())))

n = int(input())
b = []
for i in range(n):
    b.append(int(input()))

a2 = []#たて
a3 = []#ななめ

for i in range(3):
    a2.append([a[0][i], a[1][i], a[2][i]])

a3.append([a[0][0], a[1][1], a[2][2]])
a3.append([a[0][2], a[1][1], a[2][0]])

for i in range(3):
    for _b in b:
        if _b in a[i]:
            a[i].remove(_b)

for i in range(3):
    if len(a[i]) == 0:
        print("Yes")
        exit()

for i in range(3):
    for _b in b:
        if _b in a2[i]:
            a2[i].remove(_b)

for i in range(3):
    if len(a2[i]) == 0:
        print("Yes")
        exit()

for i in range(2):
    for _b in b:
        if _b in a3[i]:
            a3[i].remove(_b)

for i in range(2):
    if len(a3[i]) == 0:
        print("Yes")
        exit()

print("No")

Measured memory_bytes: 3064
import           Control.Monad

main :: IO ()
main = do
    [n, _, c] <- fmap (map read . words) getLine :: IO [Int]
    bs        <- fmap (map read . words) getLine :: IO [Int]
    ass       <- replicateM n $ fmap (map read . words) getLine :: IO [[Int]]
    print $ length $ filter (judge c bs) ass

judge :: Int -> [Int] -> [Int] -> Bool
judge c bs as = sum (zipWith (*) bs as) + c > 0


Measured memory_bytes: 1020
import math
import fractions
import copy
import numpy as np
def j(q):
    if q==1: print("Yes")
    elif q == 0:print("No")
    exit(0)
rem = pow(10,9)+7
"""
def ct(x,y):
    if (x>y):print("+")
    elif (x<y): print("-")
    else: print("?")
"""

def ip():
    return int(input())
def iprow():
    return [int(i) for i in input().split()]
def ips():
    return (int(i) for i in input().split())
def printrow(a):
    for i in a:
        print(i)
"""
#decomment when needed
def combinations(n,r):
    if n<r:return 0
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
def permutations(n,r):
    if n<r:return 0
    return math.factorial(n) // math.factorial(n - r)
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
"""
n = ip()
a = iprow()
cm = a[0]
for i in range(n):
    if a[i] > cm:
        cm = a[i]
    elif  a[i] < cm-1: j(0)
j(1)

Measured memory_bytes: 24384
import datetime
while True:
    y1, m1, d1, y2, m2, d2 = [int(x) for x in input().split()]
    if y1 < 0:
        break
    dt1 = datetime.date(y1,m1,d1)
    dt2 = datetime.date(y2,m2,d2)
    print((dt2-dt1).days)



Measured memory_bytes: 6036
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int N;
string S[16];
vector<string>C;
int T[16][16],dp[1<<15][16];

void mini(int *a,int b)
{
	if(*a==-1)*a=b;
	else *a=min(*a,b);
}

int solve()
{
	bool flg[16];
	memset(flg,1,sizeof(flg));
	for(int i=0;i<N;i++)
		for(int j=0;j<N;j++)
			if(i!=j&&flg[j]&&S[j].find(S[i])!=string::npos)
				flg[i]=0;
	C.clear();
	for(int i=0;i<N;i++)
		if(flg[i])
			C.push_back(S[i]);
	N=C.size();
	for(int i=0;i<N;i++)
		for(int j=0;j<N;j++)
			if(i!=j)
			{
				int n=C[i].size(),m=C[j].size();
				for(int k=min(n,m);k>=0;k--)
					if(C[i].substr(n-k,k)==C[j].substr(0,k))
					{
						T[i][j]=m-k;
						break;
					}
			}
	memset(dp,-1,sizeof(dp));
	for(int i=0;i<N;i++)
		dp[1<<i][i]=C[i].size();
	for(int S=0;S<1<<N;S++)
		for(int u=0;u<N;u++)
			if(S&(1<<u))
				for(int v=0;v<N;v++)
					if(!(S&(1<<v)))
						mini(&dp[S|(1<<v)][v],dp[S][u]+T[u][v]);
	int res=1e10;
	for(int i=0;i<N;i++)
		mini(&res,dp[(1<<N)-1][i]);
	return res;
}

int main()
{
	for(;scanf("%d",&N),N;)
	{
		for(int i=0;i<N;i++)
			cin>>S[i];
		printf("%d\n",solve());
	}
}

Measured memory_bytes: 3312
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <cassert>
#include <string.h>
#include <iomanip>

using namespace std;

int main()
{
	int K, X;
	cin >> K >> X;
	
	if (K*500>=X) cout <<"Yes"<<endl;
	else cout << "No" <<endl;
	
	
	
	
	
	
	
	return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <map>  
#include <algorithm>


int main()
{
	long long X, Y;
	std::cin >> X;
	std::cin >> Y;
	int count = 0;
	long long data = X;
	while (1) {
		if (data > Y) break;
		data *= 2;
		count++;
	}

	std::cout << count << std::endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<math.h>
#define kaku M_PI*1.0/3.0

typedef struct xy{
  double x,y;
}xy;

void koch(int i,xy s,xy e){
  if(i==0)return;
  xy a={(e.x+2*s.x)/3,(e.y+2*s.y)/3},b={(e.x*2+s.x)/3,(e.y*2+s.y)/3},c;
  c.x=(b.x-a.x)*cos(kaku)-(b.y-a.y)*sin(kaku)+a.x;
  c.y=(b.x-a.x)*sin(kaku)+(b.y-a.y)*cos(kaku)+a.y;
  koch(i-1,s,a);
  printf("%.8f %.8f\n",a.x,a.y);
  koch(i-1,a,c);
  printf("%.8f %.8f\n",c.x,c.y);
  koch(i-1,c,b);
  printf("%.8f %.8f\n",b.x,b.y);
  koch(i-1,b,e);
}

int main(){
  xy s={0,0},e={100,0};
  int n;
  scanf("%d",&n);
  printf("%.8f %.8f\n",s.x,s.y);
  koch(n,s,e);
  printf("%.8f %.8f\n",e.x,e.y);
  return 0;
}





Measured memory_bytes: 2692
#include<bits/stdc++.h>
using namespace std;
int a[200100];
int n;
bool check(int mid){
	if(a[n+1]<=mid&&a[n]<=mid||a[n]<=mid&&a[n-1]<=mid)
		return 1;
	if(a[n+1]> mid&&a[n]> mid||a[n]> mid&&a[n-1]> mid)
		return 0;
	for(int i=1;i<n-1;i++){
		if(a[n+i+1]<=mid&&a[n+i]<=mid||a[n-i]<=mid&&a[n-i-1]<=mid)
			return 1;
		if(a[n+i+1]> mid&&a[n+i]> mid||a[n-i]> mid&&a[n-i-1]> mid)
			return 0;
	}
	return a[1]<=mid;
}
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	for(int i=1;i<=2*n-1;i++)
		cin>>a[i];
	int l=0;
	int r=2*n-1;
	while(l!=r){
		int mi=(l+r)/2;
		if(check(mi))
			r=mi;
		else
			l=mi+1;
	}
	cout<<l<<endl;
	return 0;
}


Measured memory_bytes: 1024
length = int(input())
a, b, c = [input() for i in range(3)]
ans = 0
for i in range(length):
  if a[i]==b[i]==c[i]: ans += 0
  elif a[i]==b[i] or b[i]==c[i] or c[i]==a[i]: ans += 1
  else: ans += 2
print(ans)

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

using namespace std;
int main()
{
	uint64_t A, B;
	cin >> A >> B;
	uint64_t i = 1;
	while (1) {
		
		if (i * 8 / 100 == A && i * 10 / 100 ==B) {
			cout << i;
			return 0;
		}
		else if(i * 8 / 100 > A && i * 10 / 100 > B){
			cout << -1;
			return 0;
		}

		i++;
	}




}



Measured memory_bytes: 256