akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>

using namespace std;

int const size = 21;
int dp[1<<size];
int arr[30][30];
int mod = 1e9 + 7;

int countbits(int x){
	int count = 0 ;
	while(x){
		count++;
		x = x&x-1;
	}
	return count;
}

long long int solve(int x, int n){
	if(x == (1<<n) -1) return 1;
	if(x >= (1<<n)) return 0;
	if(dp[x] != -1) return dp[x];
	int ans = 0;
	int count = countbits(x);
	// cout<<x<<" "<<n<<"\n";

	for(int i=0;i<n;i++){
		if(!(x&(1<<i)) && arr[count][i] == 1) ans += solve(x | (1<<i), n)%mod;
		ans%=mod;
	}
	dp[x] = ans;
	return dp[x];
}

int main(){
	int n;
	scanf("%d",&n);
	for(int x=0;x<n;x++){
		for(int i=0;i<n;i++) scanf("%d",&arr[x][i]);
	}
	for(int x=0;x<(1<<n);x++) dp[x] = -1;

	cout<<solve(0,n);
	return 0;
}

Measured memory_bytes: 8448
class Convolution:

    ROOT = 3

    def __init__(self, mod):
        self.MOD = mod

    def __butterfly(self, arr):
        n = len(arr)
        h = (n - 1).bit_length()
        MOD = self.MOD
        sum_e = (911660635, 509520358, 369330050, 332049552, 983190778, 123842337, 238493703, 975955924, 603855026, 856644456, 131300601,
                 842657263, 730768835, 942482514, 806263778, 151565301, 510815449, 503497456, 743006876, 741047443, 56250497, 0, 0, 0, 0, 0, 0, 0, 0, 0)
        for ph in range(1, h + 1):
            w = 1 << (ph - 1)
            p = 1 << (h - ph)
            now = 1
            for s in range(w):
                offset = s << (h - ph + 1)
                for i in range(p):
                    l = arr[i + offset]
                    r = arr[i + offset + p] * now
                    arr[i + offset] = (l + r) % MOD
                    arr[i + offset + p] = (l - r) % MOD
                now *= sum_e[(~s & -~s).bit_length() - 1]
                now %= MOD

    def __butterfly_inv(self, arr):
        n = len(arr)
        h = (n - 1).bit_length()
        MOD = self.MOD
        sum_ie = (86583718, 372528824, 373294451, 645684063, 112220581, 692852209, 155456985, 797128860, 90816748, 860285882, 927414960, 354738543,
                  109331171, 293255632, 535113200, 308540755, 121186627, 608385704, 438932459, 359477183, 824071951, 0, 0, 0, 0, 0, 0, 0, 0, 0)
        for ph in range(1, h + 1)[::-1]:
            w = 1 << (ph - 1)
            p = 1 << (h - ph)
            inow = 1
            for s in range(w):
                offset = s << (h - ph + 1)
                for i in range(p):
                    l = arr[i + offset]
                    r = arr[i + offset + p]
                    arr[i + offset] = (l + r) % MOD
                    arr[i + offset + p] = (MOD + l - r) * inow % MOD
                inow *= sum_ie[(~s & -~s).bit_length() - 1]
                inow %= MOD

    def __call__(self, a, b):
        n = len(a)
        m = len(b)
        MOD = self.MOD
        if not n or not m:
            return []
        if min(n, m) <= 50:
            if n < m:
                n, m = m, n
                a, b = b, a
            res = [0] * (n + m - 1)
            for i in range(n):
                for j in range(m):
                    res[i + j] += a[i] * b[j]
                    res[i + j] %= MOD
            return res
        z = 1 << (n + m - 2).bit_length()
        a += [0] * (z - n)
        b += [0] * (z - m)
        self.__butterfly(a)
        self.__butterfly(b)
        for i in range(z):
            a[i] *= b[i]
            a[i] %= MOD
        self.__butterfly_inv(a)
        a = a[:n + m - 1]
        iz = pow(z, MOD - 2, MOD)
        for i in range(n + m - 1):
            a[i] *= iz
            a[i] %= MOD
        return a


def atcoder_practice2_f():
    import sys
    input = sys.stdin.buffer.readline

    N, M = map(int, input().split())
    A = [int(x) for x in input().split()]
    B = [int(x) for x in input().split()]

    convolution = Convolution(998244353)
    print(*convolution(A, B))


if __name__ == "__main__":
    atcoder_practice2_f()


Measured memory_bytes: 197160
#include <stdio.h>

int main()
{
	char ch;

for(;;)
{
    scanf("%c", &ch);
    
    
    if('a' <= ch && ch <= 'z')
	{
		printf("%c",ch-32);

	}
	
	if('A' <= ch && ch <= 'Z')
	{
		printf("%c",ch+32);
	}

	
	if ('A'>ch||ch>'z')		printf("%c",ch);
	
	

    if ( ch == '\n' )
	{
		break;
	} 
}
	

return 0;
}



Measured memory_bytes: 2116
//Andrew Yang
#include <iostream>
#include <stdio.h>
#include <sstream>
#include <fstream>
#include <string>
#include <string.h>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <utility>
#include <bitset>
#include <cmath>	
#include <cstdlib>
#include <ctime>
#include <cstdio>
#include <climits>
using namespace std;
#define FOR(index, start, end) for(int index = start; index < end; index++)
#define RFOR(index, start, end) for(int index = start; index > end; index--)
#define FOREACH(itr, b) for(auto itr = b.begin(); itr != b.end(); itr++)
#define RFOREACH(itr, b) for(auto itr = b.rbegin(); itr != b.rend(); itr++)
#define INF 1000000000
#define M 1000000007
typedef long long ll;
typedef pair<int, int> pii;

int main(void)
{
	char a, b;
	cin >> a >> b;
	bool x = a == 'H';
	bool y = b == 'H';
	if (!x)
	{
		y = !y;
	}
	if (y)
	{
		cout << "H" << endl;
	}
	else
	{
		cout << "D" << endl;
	}
}

Measured memory_bytes: 256
from operator import itemgetter
from itertools import chain


N = int(input())
L = []
R = []
for i in range(N):
    S = input()
    low = 0
    var = 0

    for s in S:
        if s == '(':
            var += 1
        else:
            var -= 1
        low = min(low, var)
    
    if var >= 0:
        L.append((low, var))
    else:
        R.append((low, var))

L.sort(key=itemgetter(0), reverse=True)
R.sort(key=lambda x: x[0] - x[1])
pos = 0
for i, (low, var) in enumerate(chain(L, R)):
    if pos + low < 0:
        ans = 'No'
        break
    pos += var
else:
    ans = 'Yes' if pos == 0 else 'No'
print(ans)


Measured memory_bytes: 212116
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<set>
#include<map>

using namespace std;
long long MOD = 1000000007LL;

int main() {
	int H, W, N;
	cin >> H >> W >> N;
	if(N % max(H, W) == 0)cout << N / max(H, W) << endl;
	else cout << N / max(H, W) + 1 << endl;
	return 0;
}



Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, char const *argv[]) {
  char a[1000000];
  char acp[1000000];
  long long int x=0;
  int ans1=0;
  int ans2=0;
  scanf("%s",a);
  for (int i = 0;x==0; i++) {
    acp[i]=a[i];
    if (a[i]!='0'&& a[i]!='1') {
      x=i;
      break;
    }
  }
  for (int i = 0; i < x-1; i++) {
    if (a[i]==a[i+1]) {
      if (a[i]=='0') {
        a[i+1]='1';
        ans1++;
      }else{
        a[i+1]='0';
        ans1++;
      }
    }
  }
  if (a[0]=='0') {
    a[0]=='1';
  }else{
    a[0]=='0';
  }
  for (int i = 0; i < x-1; i++) {
    if (acp[i]==acp[i+1]) {
      if (acp[i]=='0') {
        acp[i+1]='1';
        ans2++;
      }else{
        acp[i+1]='0';
        ans2++;
      }
    }
  }
  if (ans1>ans2) {
    printf("%d\n",ans2);
  }else{
    printf("%d\n",ans1);
  }
  return 0;
}

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

using namespace std;

using ll = long long;

const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

int main () {
  cin.tie(0);
  cout << fixed << setprecision(10);

  int n; cin >> n;
  vector<ll> a(n);
  bool posi = true, nega = true;
  ll mi = LINF, ma = 0;
  int mipos = 0, mapos = 0;
  for(int i=0;i<n;++i) {
    cin >> a[i];
    if(a[i] < 0) posi = false;
    else nega = false;
    if(mi > a[i]) {
      mipos = i;
      mi = a[i];
    }
    if(ma < a[i]) {
      mapos = i;
      ma = a[i];
    }
  }

  vector<pair<int, int>> ans;

  if(!posi && !nega) {
    if(abs(mi) < abs(ma)) {
      posi = true;
      for(int i=0;i<n;++i) {
        if(a[i] < 0) {
          ans.push_back(make_pair(mapos+1, i+1));
        }
      }
    } else {
      nega = true;
      for(int i=0;i<n;++i) {
        if(a[i] > 0) {
          ans.push_back(make_pair(mipos+1, i+1));
        }
      }
    }
  }

  if(posi) {
    for(int i=1;i<n;++i) {
      ans.push_back(make_pair(i, i+1));
    }
  } else {
    for(int i = n;i >= 2; --i) {
      ans.push_back(make_pair(i, i-1));
    }
  }

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

}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int n,m=1;cin >> n;
  int d[21]={};
  int a,v;
  while(n--){
    cin >> a >> v;d[a]=v;
    if(d[m]==d[a]&&a<m)m=a;
    if(d[m]<d[a])m=a;
  }
  cout << m << " " << d[m] << endl;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
	cout << fixed << setprecision(10);
	ll n;
	cin >> n;
	if(n==1) cout << 0 << endl;
	else cout << (n-1)*(1+n-1)/2 << endl;
	return 0;
}

Measured memory_bytes: 256
def solve():
  N, K = map(int, input().split())
  A = list(map(int, input().split()))
  mod = 10**9+7
  dp = [[0]*(K+2) for _ in range(N+1)]
  dp[0] = [0]+[1]*(K+1)
  for n in range(1,N+1):
    for k in range(1,K+2):
      dp[n][k] = (dp[n-1][k]-dp[n-1][max(0,k-A[n-1]-1)]+dp[n][k-1])%mod
  ans = (dp[-1][-1]-dp[-1][-2])%mod
  return ans
print(solve())

Measured memory_bytes: 147588
#include<cstdio>
char ch;
int f[26],ans;
int main()
{
	ch=getchar();
	f[ch-'A']++;
	ch=getchar();
	f[ch-'A']++;
	ch=getchar();
	f[ch-'A']++;
	ch=getchar();
	f[ch-'A']++;
	for(int i=0;i<26;i++)if(f[i])ans++;
	if(ans==2)puts("Yes");
	else puts("No");
	return 0;
}


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

#define fst(t) std::get<0>(t)
#define snd(t) std::get<1>(t)
#define thd(t) std::get<2>(t)
#define unless(p) if(!(p))
#define until(p) while(!(p))

using ll = std::int64_t;
using P = std::tuple<int,int>;

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

  int A, B;
  std::cin >> A >> B;

  int res = std::max(A - 2 * B, 0);
  std::cout << res << std::endl;
}


Measured memory_bytes: 256
[<AutoOpen>]
module Program

open System

let read f = stdin.ReadLine() |> f
let reada f = stdin.ReadLine().Split() |> Array.map f
let reads f = stdin.ReadLine().Split() |> Array.toList |> List.map f

[<EntryPoint>]
let main _ =
    let [n;w] = reads int
    let wvs = Array.init n (fun _ -> reads int)
    let vmax = pown 10 5
    let inf = pown 10 9 + 7

    let dp = Array2D.create (n + 1) (vmax + 1) inf
    dp.[0, 0] <- 0
    for i = 1 to n do
        let [iw;iv] = wvs.[i-1]
        for j = 0 to vmax do
            if j - iv < 0 then
                dp.[i, j] <- dp.[i-1, j]
            else
                dp.[i, j] <- min (dp.[i-1, j]) (dp.[i-1, j-iv] + iw)

    let mutable res = 0
    for i = 0 to vmax do
        if dp.[n, i] <= w then
            res <- max res i
    printfn "%i" res

    0

Measured memory_bytes: 53212
#include<bits/stdc++.h>
#define ll long long int
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
static const ll MAX = 1000000000000000;
static const int NIL = -1;
using namespace std;
const long double EPS = 0.0000000001;
const long double PI = (acos(-1));
const int MOD = 1000000007;

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")



int main() {

    ll n,m,a,b; cin >> n >> m;
    ll ans = 0;

    map<ll,ll> mp;
    set<ll, greater<ll>> st;

    rep(i,n){
        cin >> a;
        if(mp.count(a) == 0) mp[a] = 1;
        else mp[a] ++;
        st.insert(a);
    }
    rep(i,m){
        cin >> a >> b;
        if(mp.count(b) == 0)mp[b] = a;
        else mp[b] += a;
        st.insert(b);
    }



    for(auto itr = st.begin(); itr != st.end(); ++itr) {
        if(n > mp[*itr]){
            ans += mp[*itr]*(*itr);
            n -= mp[*itr];
        }else{
            ans += n*(*itr);
            cout << ans;
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 25420
n,m=map(int,input().split())
h=list(map(int,input().split()))
l=[0]*n
for i in range(m):
  a,b=map(int,input().split())
  if h[a-1]<h[b-1] and l[a-1]==0:
    l[a-1]=-1
  elif h[a-1]>h[b-1] and l[b-1]==0:
    l[b-1]=-1
  elif h[a-1]==h[b-1]:
    l[a-1]=-1
    l[b-1]=-1
print(l.count(0))

Measured memory_bytes: 19880
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
int main() {
  string n;
  int ans=0;
  cin>>n;
  if(n[0]=='A' && 'a'<=n[1] && n[1]<='z' && 'a'<=n[n.size()-1] && n[n.size()-1]<='z'){
    for(int i=2;i<n.size()-1;i++){
      if(n[i]=='C' && ans==0){
        ans++;
      }else if('a'<=n[i] && n[i]<='z'){
      }else if(ans==1 && n[i]=='C'){
        cout<<"WA"<<endl;
        return 0;
      }else{
        cout<<"WA"<<endl;
        return 0;
      }
    }
  }else{
    cout<<"WA"<<endl;
    return 0;
  }
  if(ans==1){
    cout<<"AC"<<endl;
  }else{
    cout<<"WA"<<endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1e9+7,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<ll,ll> P;

void Main() {
  int n;
  R n;
  int a[n];
  rep(i,n) R a[i];
  set<int> s;
  rep(i,n) s.in(a[i]);
  if(s.size()==n) pr("YES");
  else pr("NO");
}

int main(){ios::sync_with_stdio(0);cin.tie(0);Main();return 0;}


Measured memory_bytes: 10368
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
template <class T>
using V = vector<T>;

int main() {
  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  V<ll> p(a), q(b), r(c);
  rep(i, a) cin >> p[i];
  rep(i, b) cin >> q[i];
  rep(i, c) cin >> r[i];

  sort(p.rbegin(), p.rend());
  sort(q.rbegin(), q.rend());
  priority_queue<ll, V<ll>, greater<ll>> que;
  rep(i, x) que.push(p[i]);
  rep(i, y) que.push(q[i]);

  sort(r.rbegin(), r.rend());
  int l = min(c, x + y);
  rep(i, l) {
    if (r[i] <= que.top()) break;
    que.pop();
    que.push(r[i]);
  }
  ll ans = 0;
  while (!que.empty()) {
    ans += que.top();
    que.pop();
  }
  cout << ans << endl;
}


Measured memory_bytes: 7732
#include<bits/stdc++.h>
using namespace std;
const int N=300010;
struct node
{
	int sum,lc,rc;
}t[N<<5];
int n,m,cnt,tot;
struct sec
{
	int l,r;
	bool operator < (const sec a)const
	{
		return r<a.r;
	}
}a[N];
int rt[N<<2],id[N];
void ins(int l,int r,int x,int &k,int pre)
{
	k=++cnt;
	t[k]=t[pre];
	t[k].sum++;
	if(l==r)return;
	int mid=l+r>>1;
	if(x<=mid)
		ins(l,mid,x,t[k].lc,t[pre].lc);
	else
		ins(mid+1,r,x,t[k].rc,t[pre].rc);
}
int query(int L,int R,int l,int r,int k,int pre)
{
	if(l<=L && R<=r)return t[k].sum-t[pre].sum;
	int mid=L+R>>1;
	int res=0;
	if(l<=mid)
		res=query(L,mid,l,r,t[k].lc,t[pre].lc);
	if(r>mid)
		res+=query(mid+1,R,l,r,t[k].rc,t[pre].rc);
	return res;
}
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++)
		scanf("%d%d",&a[i].l,&a[i].r);
	sort(a+1,a+n+1);
	int now=1;
	for(int i=1;i<=m;i++)
	{
		while(a[now].r==i && now<=n)
		{
			tot++;
			ins(1,m,a[now].l,rt[tot],rt[tot-1]);
			now++;
		}
		id[i]=tot;
	}
	for(int i=1;i<=m;i++)
	{
		int ans=0;
		for(int j=i;j<=m;j+=i)
			ans+=query(1,m,j-i+1,j,rt[tot],rt[id[j-1]]);
		printf("%d\n",ans);
	}
	return 0;
}


Measured memory_bytes: 71808
#include<iostream>
#include<string>
#include<map>
#include<algorithm>
using namespace std;
map<string,int> mp;
string ans[200001];
int now;
string s[200001];
int main()
{
	int n,maxn=0;
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>s[i];
	}
	sort(s,s+n);
	for(int i=0;i<n;i++)
	{
		mp[s[i]]++;
		if(mp[s[i]]>maxn)
		{
			now=0;
			ans[++now]=s[i];
			maxn=mp[s[i]];
		}
		else if(mp[s[i]]==maxn)
		{
			ans[++now]=s[i];
		}
	}
	for(int i=1;i<=now;i++)
	{
		cout<<ans[i]<<endl;
	}
	return 0;
}


Measured memory_bytes: 28288
#include <iostream>
#include <vector>
#include <algorithm>
#include <random>
#include <string>
#include <cmath>
#include <sstream>
#include <istream>
#include <iomanip>
#include <typeinfo>
#include <stack>

using namespace std;
typedef long long ll;
ll N;

int main(){
    //ll P , Q , R;
    //cin >> P >> Q  >> R;
    ll N, D;
    cin >> N >> D;
    vector<vector<ll >> vec(N, vector<ll >(D, 0));
    //vector<ll > vec(N, )
    for(ll i = 0; i < N; i++){
        for(ll j = 0; j < D; j++){
            cin >> vec[i][j];
        }
    } 

    ll cnt = 0;
    for(ll i = 0; i < N - 1; i++){
        for(ll k = i + 1; k < N; k++){
            double ans = 0;
            for(ll j = 0; j < D; j++){
                ans += pow(vec[i][j] - vec[k][j], 2);
            }
            ans = sqrt(ans);
            if(ceil(ans) != floor(ans)){

            }else{
                cnt++;
            }
            //cout << ans << endl;
        }
    }

    cout << cnt << endl;




} 

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for(ll i = 0; i < n; i++)
const ll INF = 1LL << 60;

int main(){
    int sum = 0;
    vector<int> a(9);
    rep(i, 9){
        cin >> a[i];
        sum += a[i];
    }
    if(sum == 3 *(a[0] + a[4] + a[8])) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3616
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>

using namespace std;
#define INF (1<<29)
int n,m,s,g1,g2;
int G[102][102];
int main(){
  while(1){
    scanf("%d %d %d %d %d",&n,&m,&s,&g1,&g2);
    if(!n && !m && !s && !g1 && !g2) break;
    for(int i=1;i<=n;i++){
      for(int j=1;j<=n;j++){
	if(i==j) G[i][j]=0;
	else G[i][j]=INF;
      }
    }
    for(int i=0;i<m;i++){
      int b1,b2,c;
      scanf("%d %d %d",&b1,&b2,&c);
      G[b1][b2]=c;
      //      G[b2][b1]=c;
    }

    for(int i=1;i<=n;i++)
      for(int j=1;j<=n;j++)
	for(int k=1;k<=n;k++)
	  G[j][k] = min(G[j][k],G[j][i]+G[i][k]);

    int res = INF;
    for(int i=1;i<=n;i++){
      res = min(res,G[s][i]+G[i][g1]+G[i][g2]);
      /*      printf("%d -> %d = %d\n",s,i,G[s][i]);
      printf("%d -> %d = %d\n",i,g1,G[i][g1]);
      printf("%d -> %d = %d\n",i,g2,G[i][g2]);
      puts("");*/
    }
    
    printf("%d\n",res);
  }
}

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

int main(){
  int A,B,K,sum=0,ans;
  cin>> A >> B >> K;
  for(int i=min(A,B);i>0;i--){
    if(A%i==0 && B%i==0){
      sum++;
    if(sum==K)ans=i;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import sys
import math
n=int(input())
a=list(map(int,input().split()))
arr=[0]*(10**5+1)
s=sum(a)
for i in range(n):
    arr[a[i]]+=1
q=int(input())
for i in range(q):
    b,c=map(int,input().split())
    s-=b*arr[b]
    arr[c]+=arr[b]
    s+=c*arr[b]
    arr[b]=0
    print(s)
    

Measured memory_bytes: 84116
#include <iostream>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <stack>
#include <queue>
#include <bitset>
#include <numeric>
#include <cassert>
#include <random>
#ifdef DEBUG
#include "./Lib/debug.hpp"
#include "./Lib/Timer.hpp"
#include "./Lib/sample.hpp"
#else
#define dump(...)
template<class T>inline auto d_val(T a, T b) { return a; }
#endif

/* (=＾o＾=) */
#define int ll

/* macro */
#define FOR(i, b, e) for(ll i = (ll)(b); i < (ll)(e); ++i)
#define RFOR(i, b, e) for(ll i = (ll)(e-1); i >= (ll)(b); --i)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, 0, n)
#define REPC(x,c) for(const auto& x:(c))
#define REPI2(it,b,e) for(auto it = (b); it != (e); ++it)
#define REPI(it,c) REPI2(it, (c).begin(), (c).end())
#define RREPI(it,c) REPI2(it, (c).rbegin(), (c).rend())
#define REPI_ERACE2(it, b, e) for(auto it = (b); it != (e);)
#define REPI_ERACE(it, c) REPI_ERACE2(it, (c).begin(), (c).end())
#define ALL(x) (x).begin(),(x).end()
#define cauto const auto&
/* macro func */
#define SORT(x) do{sort(ALL(x));}while(false)
#define RSORT(x) do{sort((x).rbegin(),(x).rend());}while(false)
#define UNIQUE(v) do{v.erase( unique(v.begin(), v.end()), v.end() );}while(false)
#define MAX(x,y) do{x = std::max(x,y);}while(false)
#define MIN(x,y) do{x = std::min(x,y);}while(false)
#define BR do{cout<<"\n";}while(false)

/* type define */
using ll = long long;
using PAIR = std::pair<ll, ll>;
using VS = std::vector<std::string>;
using VL = std::vector<long long>;
using VVL = std::vector<VL>;
using VVVL = std::vector<VVL>;
using VD = std::vector<double>;
template<class T>
using V = std::vector<T>;

/* using std */
using std::cout;
constexpr char endl = '\n';
using std::cin;
using std::sort;
using std::pair;
using std::string;
using std::stack;
using std::queue;
using std::vector;
using std::list;
using std::map;
using std::unordered_map;
using std::multimap;
using std::unordered_multimap;
using std::set;
using std::unordered_set;
using std::unordered_multiset;
using std::multiset;
using std::bitset;
using std::priority_queue;

/* constant value */
constexpr ll MOD = 1000000007;
//constexpr ll MOD = 998244353;

/* Initial processing  */
struct Preprocessing { Preprocessing() { std::cin.tie(0); std::ios::sync_with_stdio(0); }; }_Preprocessing;

/* Remove the source of the bug */
signed pow(signed, signed) { assert(false); return -1; }

/* define hash */
namespace std { template <>	class hash<std::pair<ll, ll>> { public:	size_t operator()(const std::pair<ll, ll>& x) const { return hash<ll>()(1000000000 * x.first + x.second); } }; }

/* input */
template<class T> std::istream& operator >> (std::istream& is, vector<T>& vec) { for (T& x : vec) is >> x; return is; }

//=============================================================================================

signed main() {

	VS vs = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
	string s;
	cin >> s;

	REP(i, 7) {
		if (s == vs[i]) {
			cout << 7 - i << endl;
			return 0;
		}
	}

}


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

int main() {
  string S; cin >> S;
  reverse(S.begin(), S.end());
  S += '0';
  int L = S.size();
  const int INF = 1000000007;
  vector<vector<int>> dp(L+1, vector<int>(2, INF));
  dp.at(0).at(0) = 0;
  for (int i = 0; i < L; i++) {
    int D = S.at(i) - '0';
    // 繰り下げが起きていないとき (dp[i][0] からの遷移)
    dp.at(i+1).at(0) = min(dp.at(i+1).at(0), dp.at(i).at(0) + D);
    dp.at(i+1).at(1) = min(dp.at(i+1).at(1), dp.at(i).at(0) + 10 - D);
    // 繰り下げが起きているとき (dp[i][1] からの遷移)
    dp.at(i+1).at(0) = min(dp.at(i+1).at(0), dp.at(i).at(1) + D + 1);
    dp.at(i+1).at(1) = min(dp.at(i+1).at(1), dp.at(i).at(1) + 9 - D);
  }
  int ans = dp.at(L).at(0);
  cout << ans << endl;
}

Measured memory_bytes: 55940
/*
* Created by: WeirdBugsButOkay
*/

#include <bits/stdc++.h>

#define ll long long
#define ld long double
#define ff first
#define ss second

using namespace std;

void solve()
{
    string s, t;
    cin >> s >> t;
    int ans = 0;
    for(int i = 0; i < (int)s.size(); i++)
        if(s[i] != t[i])
            ans++;
    cout << ans << endl;
}

int main()
{
    int q = 1;
    //scanf("%d", &q);
    for(int i = 1; i <= q; i++)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3916
#include <bits/stdc++.h>
#define LL long long
#define PB push_back
using namespace std;
const LL mod = 1000 * 1000 * 1000 + 7;
const LL ob = (mod + 1) >> 1;
LL ans = mod * mod;
LL n;
LL a[2005];
LL b[2005];
LL x;
int main()
{
	ios_base::sync_with_stdio(0);
	cin >> n >> x;
	for(int i = 0; i < n; i++)
	{
		cin >> a[i];
		b[i] = a[i];
	}
	for(int times = 0; times < n; times++)
	{
		LL cost = times * x;
		for(int i = 0; i < n; i++)
			cost += b[i];
		ans = min(ans , cost);
		for(int i = 0; i < n; i++)
		{
			b[i] = min(b[i] , a[(i - (times + 1) + n) % n]);
		}
	}


	cout << ans;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define mod (int)(1e9+7)
#define inf (int)(3e18)
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define P std::pair<int,int>
#define PiP std::pair<int,std::pair<int,int>>
#define all(v) v.begin(),v.end()
#define mkp std::make_pair
#define prique(T) std::priority_queue<T,vector<T>,greater<T>>
using namespace std;
template<class T> inline void chmax(T& a, T b) { a = std::max(a, b); }
template<class T> inline void chmin(T& a, T b) { a = std::min(a, b); }

bool prime(int x) {
	for (int i = 2; i * i <= x; i++) {
		if (x % i == 0)return false;
	}
	return x != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}
int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}
int get_rand(int MIN, int MAX) {
	std::random_device rnd;
	std::mt19937 mt32(rnd());
	std::uniform_int_distribution<int>engine(MIN, MAX);
	return engine(mt32);
}
/*--------Library Zone!--------*/

int n, q;
string s;
int summ[1000005];
signed main() {
	cin >> n >> s >> q;
	rep(i, n) {
		if (s[i] == 'M')summ[i]++;
		summ[i + 1] = summ[i];
	}
	while (q--) {
		int k; cin >> k;
		int ans = 0;
		int d = 0, dm = 0;
		rep(i, n) {
			if (s[i] == 'D')d++;
			else if (s[i] == 'M')dm += d;
			else if (s[i] == 'C')ans += dm;
			if (i >= k - 1 && s[i - k + 1] == 'D') {
				d--;
				dm -= summ[i] - (i >= k ? summ[i - k] : 0);
			}
		}
		cout << ans << endl;
	}
}


Measured memory_bytes: 9220
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
using namespace std;

#define rep(i, s) for (int i = 0; i < s; ++i)
#define all(v) (v.begin(), v.end())
#define COUT(x) cout << #x << ” = ” << (x) << ” (L” << __LINE__ << “)” << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)
#define VEC(a, n) vector<int>a(n)
#define PQ(a) priority_queue<int>a
#define PQmin(a) priority_queue< int, :vector<int>, greater<int> >a
#define PAIR pair<int, int>
/*
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
       return l.first<r.first || (l.first==r.first && l.second > r.second);
       });
*/

typedef long long  ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
   int n;
   cin>>n;
   vector<int>d(n);
   for(int i=0;i<n;i++){
      cin>>d.at(i);
   }
   ll ans=0;
   for(int i=0;i<n;i++){
      for(int j=i+1;j<n;j++){
         ans+=d.at(i)*d.at(j);
      }
   }
   cout<<ans<<endl;



   return 0;
}

Measured memory_bytes: 256
// +build ignore
package main

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

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

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

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

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

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

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

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

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

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

func run(input io.Reader, output io.Writer) int {
	sc := NewScanner()
	A := sc.nextInt()
	B := sc.nextInt()

	if A == 1 {
		A = 14
	}

	if B == 1 {
		B = 14
	}

	switch {
	case A > B:
		fmt.Println("Alice")
	case A < B:
		fmt.Println("Bob")
	default:
		fmt.Println("Draw")
	}

	return 0
}

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


Measured memory_bytes: 640
#include <stdio.h>

int main()
{
  int xx, aa, bb, soo = 0, ss = 0;
  scanf("%d", &xx);
  soo = xx / 500;
  soo *= 1000;
  xx %= 500;
  ss = xx / 5;
  ss *= 5;
  xx = soo + ss;
  printf("%d\n", xx);
  return 0;
}

Measured memory_bytes: 128
import math
import sys
import itertools
from math import gcd
from math import sqrt
from sys import stdin
def input() : return stdin.readline().rstrip()
def mips():
    return map(int,input().split())
def ii():
    return int(input())
sys.setrecursionlimit(10**9)

N,K = mips()
ans = 0
P = [p for p in mips()]
P.sort()
for i in range(K):
    ans += P[i]
print(ans)
    


Measured memory_bytes: 9188
#include<iostream>
#include<map>
#include<vector>
#include<cmath>
#include<string>
#include<cstring>
#include<algorithm> 
#include<climits>
#include<stack>
#include<queue>
#include<set>
#include<cctype>
using namespace std;

struct UnionFind {
    vector<int> par;
    vector<int> sz;
    map<int, int> szmp; // map<size, cnt>
 
    // n : 要素数
    UnionFind(int n = 0){
        if(n > 0) initialize(n);
    }
 
    void initialize(int n){
        par.resize(n);
        sz.resize(n);
        for(int i = 0; i < n; i++){
            par[i] = i;
            sz[i] = 1;
        }
        szmp[1] = n;
    }
 
    // 0-index
    int find(int x){
        if(par[x] == x){
            return x;
        } else {
            return par[x] = find(par[x]);
        }
    }

    // 0-index
    void unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y) return;
        if(sz[x] > sz[y]) swap(x, y);
 
        for(int s : {sz[x], sz[y]}){
            szmp[s]--;
            if(szmp[s] == 0) szmp.erase(s);
        }
        par[x] = y;
        sz[y] += sz[x];
        szmp[sz[y]]++;
    }
 
    // 0-index
    bool same(int x, int y){
        return find(x) == find(y);
    }

    // 0-index
    int size(int x){
        return sz[find(x)];
    }
 
    // 最小要素サイズ
    int minsz(){
        return szmp.begin() -> first;
    }

    // 連結成分個数
    int unitenum(){
        int ret = 0;
        for(auto u : szmp){
            ret += u.second;
        }
        return ret;
    }
};

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

    UnionFind uf(n);

    while(m--){
        int a, b;
        cin >> a >> b;
        uf.unite(a-1, b-1);
    }
    cout << uf.unitenum() - 1 << endl;
    return 0;
}


Measured memory_bytes: 4052
#payment=桁DPの復習方法
n=input()
#0の方がちょうど、1の方が余裕持って払う
dp0=[0 for i in range(1000002)]
dp1=[0 for i in range(1000002)]
nums=int(n[-1])

dp0[1]=nums
dp1[1]=11-nums
#dp0、dp1でそれぞれぴったり払う時と余裕を持たせて払うときのiけためまでを一つの数としてみたときの最小の値を表すものとする
for i in range(1,len(n)):
    s=int(n[-(i+1)])
    dp0[i+1]=s+min(dp0[i],dp1[i])
    dp1[i+1]=min(9-s+dp1[i],11-s+dp0[i])
print(min(dp0[len(n)],dp1[len(n)]))


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

#define LL long long
const int mod = 1e9 + 7;

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    
    LL n, m, x, a=0, b=0;
    cin >> n >> m;

    for(LL i = 1; i <= n; i++) cin >> x, (a += ((i-1) * x) % mod) %= mod, (a += mod - ((n-i) * x) % mod) %= mod;

    for(LL i = 1; i <= m; i++) cin >> x, (b += ((i-1) * x) % mod) %= mod, (b += mod - ((m-i) * x) % mod) %= mod;

    cout << (a * b) % mod;    
}

Measured memory_bytes: 3656
#include<bits/stdc++.h>
#define ll long long
#define F first
#define S second
#define Tsetso ios_base::sync_with_stdio(0) ; cin.tie(0) ;
using namespace std;
const ll N = 1e5+50, inf = 1e3+5, mod = 1e9+7, NN = 1e5+10;
int vis[N][3] ;
vector < int > graph[N] ;
int n, m, t,s, u, v ;
int main()
{
    Tsetso
    cin >> n >> m ;
    for ( int i = 0 ; i < m ; i++)
    {
        cin >> u >> v ;
        graph[u].push_back(v);
    }
    cin >> s >> t ;
    queue < int > q ;
    q.push(s);
    vis[s][0] = 1 ;
    int cnt = 1 ;
    while ( q.size())
    {
        int y = q.size() ;
        for ( int i = 0 ; i < y ; i++)
        {
            for ( auto j : graph[q.front()])
            {
                if ( !vis[j][cnt%3])
                {
                    if ( cnt%3 == 0 && j == t )
                        return cout << cnt/3, 0 ;
                    q.push(j);
                    vis[j][cnt%3] = 1 ;
                }
            }
            q.pop();
        }
        cnt++ ;
    }
    cout << -1 ;
}


Measured memory_bytes: 10244
#include<cstdio>
#include<algorithm>
using ll = long long;
struct edge{int u, v, cost;};
const static int MAX_N = 100000;
int par[MAX_N];
int rank[MAX_N];

void init_union_find(int n){
	for (int i = 0; i < n; ++i){
		par[i] = i;
		rank[i] = 0;
	}
}

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

void unite(int x, int y){
	x = find(x);
	y = find(y);
	if(x == y) return;
	if(rank[x] < rank[y]){
		par[x] = y;
	}else{
		par[y] = x;
		if(rank[x] == rank[y]) rank[x]++;
	}
}

bool same(int x, int y){
	return find(x) == find(y);
}

bool comp(const edge& e1, const edge& e2){
	return e1.cost < e2.cost;
}

int main(){
	int N;
	scanf("%d", &N);
	std::pair<int, int> x[N], y[N];
	for (int i = 0; i < N; ++i){
		x[i].second = y[i].second = i;
		scanf("%d %d", &x[i].first, &y[i].first);
	}
	std::sort(x, x + N), std::sort(y, y + N);
	edge es[2*(N - 1)];
	for (int i = 0; i < N - 1; ++i){
		es[i].u = x[i].second;
		es[i].v = x[i + 1].second;
		es[i].cost = x[i + 1].first - x[i].first;
	}
	for (int i = N - 1; i < 2*(N - 1); ++i){
		es[i].u = y[i + 1 - N].second;
		es[i].v = y[i + 2 - N].second;
		es[i].cost = y[i + 2 - N].first - y[i + 1 - N].first;
	}
	std::sort(es, es + 2*(N - 1), comp);
	init_union_find(N);
	int total = 0;
	for (int i = 0; i < 2*(N - 1); ++i){
		edge e = es[i];
		if(!same(e.u, e.v)){
			unite(e.u, e.v);
			total += e.cost;
		}
	}
	printf("%d\n", total);
	return 0;
}

Measured memory_bytes: 4864
import java.util.*;
public class Main {
    public static void main(String [] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        long cnt = 0;
        for(int i=1;i<=N;i++) {
            int a = (N-1)/i;
            cnt+=a;
        }
        System.out.println(cnt);
    }
}

Measured memory_bytes: 35720
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int,int> P;

vector<int> depth;
vector<int> subtree_size;
void dfs(const Graph &G, int v, int p, int d) {
    depth[v] = d;
    for (auto nv : G[v]) {
        if (nv == p) continue; // nv が親 p だったらダメ
        dfs(G, nv, v, d+1);
    }

    // 帰りがけ時に、部分木サイズを求める
    subtree_size[v] = 1; // 自分自身
    for (auto c : G[v]) {
        if (c == p) continue;
        subtree_size[v] += subtree_size[c]; // 子のサイズを加える
    }
}

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

    // グラフ入力受取
    Graph G(N);
    for (int i = 0; i < N-1; ++i) {
        int a, b;
        cin >> a >> b;
        G[a - 1].push_back(b - 1);
        G[b - 1].push_back(a - 1);
    }

    ll f[N], s[N];

    // 探索
    int root = 0; // 仮に頂点 0 を根とする
    depth.assign(N, 0);
    subtree_size.assign(N, 0);
    dfs(G, root, -1, 0);
    // 結果
    for (int v = 0; v < N; ++v) {
        // cout << v << ": depth = " << depth[v] << ", subtree_size = " << subtree_size[v] << endl;
        f[v] = depth[v];
    }

    // 探索
    root = N - 1; // 仮に頂点 0 を根とする
    depth.assign(N, 0);
    subtree_size.assign(N, 0);
    dfs(G, root, -1, 0);
    // 結果
    for (int v = 0; v < N; ++v) {
        // cout << v << ": depth = " << depth[v] << ", subtree_size = " << subtree_size[v] << endl;
        s[v] = depth[v];
    }

    ll F = 0, S = 0;
    rep(i, N){
        if (f[i] <= s[i]) F++;
        else S++;
    }

    if (F > S) cout << "Fennec" << endl;
    else cout << "Snuke" << endl;
}

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

int main() {
    int l, n; scanf("%d%d", &l, &n);
    vector<int> x(n);
    for (int i = 0; i < n; ++i) scanf("%d", &x[i]);

    vector<int> right(x.rbegin(), x.rend());
    vector<int> left;
    long long ans = max(x[n - 1], l - x[0]);
    vector<long long> lsum(1, 0);
    vector<long long> rsum(n + 1, 0);
    for (int i = 0; i < right.size(); ++i) rsum[i + 1] = rsum[i] + l - right[i];
    for (int i = 0; i < n - 1; ++i) {
        left.push_back(right.back());
        lsum.push_back(lsum.back() + left[i]);
        right.pop_back();
        int ldiff = max((int)left.size() - (int)right.size(), 0);
        int rdiff = max((int)right.size() - (int)left.size(), 0);
        long long res = 2 * (lsum[left.size()] - lsum[ldiff] + rsum[right.size()] - rsum[rdiff]);
        {
            long long tres = res;
            if (rdiff - 1 >= 0) tres += 2 * (l - right[rdiff - 1]);
            ans = max(ans, tres - (l - right.back()));
        }
        {
            long long tres = res;
            if (ldiff - 1 >= 0) tres += 2 * left[ldiff - 1];
            ans = max(ans, tres - left.back());
        }
    }
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 6768
N,M,X = map(int,input().split())

C = [0]*N
A = [0]*N
for i in range(N):
    I = list(map(int,input().split()))
    C[i] = I[0]
    A[i] = I[1:]

m = sum(C)+1
for i in range(2**N):
    U = [0]*M
    book = [0]*N
    for j in range(N):
        if i&(2**j) == 2**j:
            book[j] = 1
            for k in range(M):
                U[k] += A[j][k]
    det = 0
    for k in range(M):
        if U[k] < X:
            det = -1
            break

    if det == 0:
        price = 0
        for j in range(N):
            price += C[j]*book[j]
        m = min(m,price)

if m == sum(C)+1:
    print(-1)
else:
    print(m)

Measured memory_bytes: 68748
#include<cstdio>
#include<algorithm>
#include<map>
using namespace std;
#define N 1000002
int n,a,b,c,d;
char s[N];
int ss[N],t;
int main()
{
	//freopen("general.in","r",stdin);
    //freopen("general.out","w",stdout);
    scanf("%d%d%d%d%d",&n,&a,&b,&c,&d);
    scanf("%s",s+1);
    if(c<b)
    {
    	for(int i=a;i<c;i++)
    		if(s[i]=='#'&&s[i+1]=='#')
	    	{
	    		printf("No\n");
	    		return 0;
			}
		for(int i=b;i<d;i++)
    		if(s[i]=='#'&&s[i+1]=='#')
	    	{
	    		printf("No\n");
	    		return 0;
			}
		printf("Yes\n");
		return 0;
	}
	int e=max(c,d);
	for(int i=min(a,b);i<e;i++)
		if(s[i]=='#'&&s[i+1]=='#')
		{
	    	printf("No\n");
	    	return 0;
		}
    if(c>d)
    {
    	int k=0;
    	for(int i=b;i<=d;i++)
    		if(s[i]=='.'&&(s[i-1]!='#'&&s[i+1]!='#'))
    		{
				k++;
				break;
    		}
    	if(k)printf("Yes\n");
    	else printf("No\n");
		return 0;
	}
	printf("Yes\n");
}

Measured memory_bytes: 2176
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <numeric>
#include <cstdint>
#include <iomanip>
using ll = long long;

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

    std::vector<ll> v(s.size()+1, 0);
    for(int i=0; i<v.size(); ++i){
        if(s[i]=='<') v[i+1] = v[i]+1;
    }
    for(int i=v.size()-1; i>-1; --i){
        if(s[i]=='>') v[i] = std::max(v[i+1]+1, v[i]);
    }
    std::cout << std::accumulate(v.begin(), v.end(), 0LL);
    return 0;
}


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

int main(){
  vector<int> num(4);
  for(int &x:num){
    cin>>x;
  }
  sort(num.begin(),num.end());
  vector<int> base={1,4,7,9};
  for(int i=0;i<4;i++){
    if(num[i]!=base[i]){
      cout<<"NO"<<endl;
      return 0;
    }
  }
  cout<<"YES"<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = Integer.parseInt(scanner.nextLine());
        int k = Integer.parseInt(scanner.nextLine());
        int x = Integer.parseInt(scanner.nextLine());
        int y = Integer.parseInt(scanner.nextLine());

        int sum = 0;
        for (int i = 1; i <= n; i++) {
            if (i >= k + 1) {
                sum += y;
            } else {
                sum += x;
            }
        }
        System.out.println(sum);
    }
}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

int a[1000001];
vector<int> v;
int cnt;
void insertsort(int n,int g){
    FOR(i,g,n){
        int ai=a[i];
        int j=i-g;
        while(j>=0&&a[j]>ai){
            a[j+g]=a[j];
            j=j-g;
            ++cnt;
        }
        a[j+g]=ai;
    }
}
int main(){
    int n;
    cin>>n;
    rep(i,n) cin>>a[i];
    int p=1;
    while(p<=n){
        v.pb(p);
        p*=2;
    }
    cnt=0;
    reverse(v.begin(),v.end());
    for(auto it:v) insertsort(n,it);
    cout<<v.size()<<endl;
    rep(i,v.size()) cout<<v[i]<<(i==v.size()?"":" ");
    cout<<endl;
    cout<<cnt<<endl;
    rep(i,n) cout<<a[i]<<endl;
    return 0;
}


Measured memory_bytes: 7080
import java.util.Scanner;

fun main(args: Array<String>) {
	val scanner = Scanner(System.`in`)
	val n = scanner.nextInt()
	val s = scanner.next()
	val map = mutableMapOf<Char, Int>()

	var cnt = 0
	var maxCnt = 0
	s.toCharArray().forEachIndexed{ i, c ->
		if (map.containsKey(c)){
			if (map.containsValue(i)) cnt--
		}else {
			val l = s.lastIndexOf(c)
			if (i!=l) {
				map[c] = l
				cnt++
				maxCnt = Math.max(maxCnt, cnt)
			}
		}
	}
	println(maxCnt)
}

Measured memory_bytes: 31396
#include <iostream>
using namespace std;
 
 
int main() {
  int N, M;
  cin >> N;
  
  int d1,d2,d3;
  d1 = N / 100;
  d2 = (N % 100) /10;
  d3 = (N % 10);
  
  if ( d1 == 1 )      { d1 = 9; }
  else if ( d1 == 9 ) { d1 = 1; }
 
  if ( d2 == 1 )      { d2 = 9; }
  else if ( d2 == 9 ) { d2 = 1; }
 
  if ( d3 == 1 )      { d3 = 9; }
  else if ( d3 == 9 ) { d3 = 1; }
 
  M = 100 * d1 + 10 * d2 + d3;
  
  cout << M << endl;
}

Measured memory_bytes: 256
n, d = map(int, input().split())
xy = [list(map(int, input().split())) for _ in range(n)]
ans = 0
for i in range(n):
    count = (xy[i][0]**2+xy[i][1]**2)**0.5
    if count <= d:
        ans += 1

print(ans)


Measured memory_bytes: 103140
#include <iostream>
#include <climits>
#include <cmath>
#include <iomanip>


using namespace std;

int dp[50001]; // j?????????????°?????????°?????????

int main() {
	int n,m;

	cin >> n >> m;


	int d[m];

	for (int i = 0; i < m; i++) {
		cin >> d[i];
	}
	for(int i = 0; i <= n; i++) {
		dp[i] = INT_MAX;
	}

	for (int i = 0; i < m; i++) {
		int curD = d[i];
		dp[curD] = 1;
		for (int j = curD + 1; j <= n; j++) {
			if (dp[j - curD] != INT_MAX) {
				dp[j] = min(dp[j] , dp[j - curD] + 1);
			}
		}
	}

	cout << dp[n] << endl;

/*
	for (int i = 0; i <= n ;i++) {
		if (dp[i] == INT_MAX) {
			cout << ".";
		} else {
			cout << dp[i];
		}
		cout << endl;
	}
 */
	return 0;
}

Measured memory_bytes: 1356
H, W = gets.split.map(&:to_i)
board = H.times.map { gets.chomp.chars }
w_count = board.map do |row|
  row.count('.')
end.reduce(&:+)

INF = 1 << 30
def bfs(board)
  cost = Array.new(H) do
    Array.new(W, INF)
  end
  cost[0][0] = 1
  ys = [-1, 0, 1]
  xs = [-1, 0, 1]
  queue = [[0, 0, 1]]
  while !queue.empty?
    i, j, c = queue.shift
    ys.each do |y|
      ii = i + y
      next if ii < 0 || ii >= H
      xs.each do |x|
        next if y != 0 && x != 0
        jj = j + x
        next if jj < 0 || jj >= W
        next if board[ii][jj] == '#'
        if c + 1 < cost[ii][jj]
          cost[ii][jj] = c + 1
          queue.push([ii, jj, c + 1])
        end
      end
    end
  end
  cost[H - 1][W - 1]
end

cost = bfs(board)
if cost == INF
  puts -1
  exit 0
end
ans = w_count - cost
puts ans


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

#define rep(i, n) for(int i=0; i < n; i++)
#define reps(i, n) for(int i=1; i <= n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

using namespace std;
using ll=long long;

int main() {
  ll N;
  cin >> N;

  ll ans=0;

  //bfs <digit,number,357exists>
  queue<pair<ll,int>> que;

  //initialize que with 3,5,7
  que.push(make_pair(3,0b001));
  que.push(make_pair(5,0b010));
  que.push(make_pair(7,0b100));

  while(!que.empty()){
    pair<ll,int> p= que.front();
    que.pop();
    for(int i=3;i<=7;i+=2){
      ll x= p.first*10+i;
      // bigger than N to get out
      if(x>N)continue;
      //copy 357existance status
      int flg = 0b111;
      //analyze only if  any of 357 is missing
      if(p.second != 0b111){
        if(i==3) flg=p.second |0b001;
        if(i==5) flg=p.second |0b010;
        if(i==7) flg=p.second |0b100;
      }
      if(flg==0b111) ans++;
      que.push(make_pair(x,flg));
    }
  }
  cout << ans;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A, B, C, D, L, R;
  cin >> A >> B >> C >> D;
  L = A + B; R = C + D;
  if(L > R){
  	cout << "Left" << endl;
  }
  else if(L == R){
  	cout << "Balanced" << endl;
  }
  else{
  	cout << "Right" << endl;
  }
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <unordered_map> 
#include <unordered_set>
#include <functional>

using namespace std;

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

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

int main(){
	int N;
	cin >> N;
	vector<P> v;
	for(int i = 0; i < N; i++){
		P p;
		cin >> p.first >> p.second;
		p.first -= p.second;
		v.push_back(p);
	}
	sort(v.begin(), v.end());
	long long int S = 0;
	priority_queue<P, vector<P>, greater<P> > que;
	for(P p : v){
		while(!que.empty() && que.top().first <= p.first){
			S = max(S, que.top().second);
			que.pop();
		}
		que.push(P(p.first + p.second * 2, S + 1));
	}
	while(!que.empty()){
		S = max(S, que.top().second);
		que.pop();
	}
	cout << S << endl;
	return 0;
}

Measured memory_bytes: 4976
N,Q = map(int,input().split())
AB = [tuple(map(int,input().split())) for i in range(N-1)]
PX = [tuple(map(int,input().split())) for i in range(Q)]

es = [[] for i in range(N)]
for a,b in AB:
    a,b = a-1,b-1
    es[a].append(b)
    es[b].append(a)

xs = [0] * N
for p,x in PX:
    xs[p-1] += x

ans = [0] * N
ans[0] = xs[0]
visited = [0] * N
stack = [0]
while stack:
    v = stack.pop()
    visited[v] = 1
    for to in es[v]:
        if visited[to]: continue
        stack.append(to)
        ans[to] = ans[v] + xs[to]

print(*ans)

Measured memory_bytes: 124548