akhauriyash/Code-Regression huggingface dataset:
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush
from math import *

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)
def ston(c, c0='a'):
    return ord(c)-ord(c0)
def ntos(x, c0='a'):
    return chr(x+ord(c0))
class counter(dict):
    def __init__(self, *args):
        super().__init__(args)
    def add(self,x):
        self.setdefault(x,0)
        self[x] += 1

L,R = mint()
if R-L>=2019:
    print(0)
    exit()
ans = INF
for i in range(L,R):
    for j in range(i+1,R+1):
        ans = min(ans,(i*j)%2019)
        if ans==0:
            print(0)
            exit()
print(ans)

Measured memory_bytes: 68124
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
int main(){
  int N;
  cin >> N;
  vector<pair<ll,ll>> ba;
  for(int i = 0;i < N;i++){
    ll A,B; cin >> A >> B;
    ba.push_back(make_pair(B,A));
  }

  sort(ba.begin(),ba.end());

  ll now_sum = 0;
  for(int i = 0;i < N;i++){
    now_sum += ba[i].second;
    if(now_sum > ba[i].first){
      cout << "No" << endl;
      return 0;
    }
  }

  cout << "Yes" << endl;
}


Measured memory_bytes: 6384
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(){
  int n;
  cin >> n;
  string s;
  int ans = 0;
  int a=0, b=0, ab = 0;
  for(int i=0;i<n;i++){
    cin >> s;
    for(int j=1;j<s.size();j++){
      if(s[j-1] == 'A' && s[j] == 'B') ans++;
    }
    if(s[0] == 'B' && s[s.size()-1] == 'A') ab++;
    else if(s[0] == 'B') b++;
    else if(s[s.size()-1] == 'A') a++;
  }
  if(ab >= 1){
      ans += ab - 1;
      if(ab != n){
        if(b!=0)a++;
        if(a-(b!=0?1:0)!=0)b++;
      }
  }
  ans += min(a,b);
  cout << ans << endl;
}

Measured memory_bytes: 256
#heapqすら使わなくても良い
x,y,a,b,c=map(int,input().split())

p=sorted(list(map(int,input().split())),reverse=True)[:x]
q=sorted(list(map(int,input().split())),reverse=True)[:y]
r=sorted(list(map(int,input().split())),reverse=True)

p.extend(q)
ans=sorted(p)

#ansは小さい順、rは大きい順
for i in range(x+y):
    if len(r)==i or r[i]<ans[i]:
        break
    else:
        ans[i]=r[i]
print(sum(ans))

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

const int64_t MOD = 998244353;
void add(int64_t& a, int64_t b){
    a = (a+b) % MOD;
}
void mul(int64_t& a, int64_t b){
    a = a*b % MOD;
}

int N, K;
vector<int> edges[100000];

int64_t dp[100000][301][2];
int64_t dp2[302][2];
int sz[100000];

void dfs(int i, int p){
    dp[i][1][1] = 1;
    dp[i][0][0] = 1;
    sz[i] = 1;
    for(int j : edges[i]) if(j != p){
        dfs(j, i);
        memset(dp2, 0, sizeof(dp2));
        for(int n1=0; n1<=min(K, sz[i]); n1++) for(int n2=0; n2<=min(K+1-n1, sz[j]); n2++){
            add(dp2[n1+n2][1], dp[i][n1][1] * dp[j][n2][0]);
            if(n1+n2) add(dp2[n1+n2-1][1], dp[i][n1][1] * dp[j][n2][1]);
            add(dp2[n1+n2][1], dp[i][n1][1] * dp[j][n2][1]);
            add(dp2[n1+n2][0], dp[i][n1][0] * dp[j][n2][1]);
            add(dp2[n1+n2][0], dp[i][n1][0] * dp[j][n2][0]);
        }
        sz[i] += sz[j];
        for(int n=0; n<=K; n++) for(int k=0; k<2; k++) dp[i][n][k] = dp2[n][k];
    }
}

int main(){
    cin >> N >> K;
    for(int i=0; i<N-1; i++){
        int a, b;
        cin >> a >> b;
        edges[a-1].push_back(b-1);
        edges[b-1].push_back(a-1);
    }

    dfs(0, -1);
    int64_t ans = 0;
    for(int k=0; k<2; k++) add(ans, dp[0][K][k]);
    cout << ans << endl;
    return 0;
}



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

int main()
{
string s ;
cin >> s ;
ll n=s.size();
if(s[0]=='0'||s[n-2]=='0'||s[n-1]=='1'){
cout << -1 << endl;
return 0;
}
ll pre=1;
vector<ll> ans;
rep(i,n-1){
  if(s[i]=='1'){
    if(s[n-i-2]=='1'){
      ans.push_back(i+2);
      ans.push_back(pre);
      pre=i+2;
    }
    else{cout << -1 << endl;return 0;}
  }
  else{
    if(s[n-i-2]=='0'){
      ans.push_back(i+2);
      ans.push_back(pre);
    }
    else{cout << -1 << endl;return 0;}
  }
}
rep(i,n-1){
  cout << ans[i*2]<< " "  << ans[i*2+1] << endl;
}

return 0;
}


Measured memory_bytes: 3312
n, k = list(map(int, input().split()))
r, s, p = list(map(int, input().split()))
t = list(input())

score = {"r": r, "s": s, "p": p}


def get_score(t):
    if t == "r":
        return score["p"]
    if t == "s":
        return score["r"]
    if t == "p":
        return score["s"]

l = [-1] * n

for i in range(n):
    if l[i] >= 0:
        continue

    if i > n - k - 1:
        l[i] = get_score(t[i])
        continue

    if t[i] == t[i + k]:
        l[i] = get_score(t[i])
        l[i + k] = 0
    else:
        l[i] = get_score(t[i])


print(sum(l))


Measured memory_bytes: 4796
n=int(input())
from collections import Counter
cc=Counter()
a=list(map(int,input().split()))
for i in a:
    cc[i]+=1
ans=0
for i in cc:
    if cc[i]<i:
        ans+=cc[i]
    elif cc[i]>i:
        ans+=cc[i]-i
print(ans)


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

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

  int ans = 0;

  if(D == 0) {
    int n = 1;
    for(int i=1;;i++) {
      if(i % 100 != 0) {
        if(n == N) {
          ans = i;
          break;
        }
        n++;
      }
    }
  } else if (D == 1) {
    int n = 1;
    for(int i=100;;i+=100) {
      if(i % 10000 != 0) {
        if(n == N) {
          ans = i;
          break;
        }
        n++;
      }
    }
  } else {
    int n=1;
    for(int i=10000;;i+=10000 ) {
      if(i % 1000000 != 0) {
        if(n == N) {
          ans = i;
          break;
        }
        n++;
      }
    }
  }

  cout << ans << endl;
}

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

int main(){
    string S;
    cin >> S;
    deque<char> que;
    for(char c : S) que.push_back(c);
    int rev = 0;
    int Q;
    cin >> Q;
    while(Q--){
        int t;
        cin >> t;
        if(t == 1){
            rev = 1-rev;
        }else{
            int f;
            char c;
            cin >> f >> c;
            f--;
            if(rev^f){
                que.push_back(c);
            }else{
                que.push_front(c);
            }
        }
    }
    if(rev) reverse(que.begin(), que.end());
    for(auto c : que) cout << c;
    cout << endl;
    return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <functional>
#include <utility>
#include <cctype>
#include <fstream>

using namespace std;

#define ll long long
#define INF 2000000000
#define LINF 9000000000000000000
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define du(x) cout<<#x<<'='<<x<<endl
#define du2(x,y) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<'\n'<<endl
#define du3(x,y,z) cout<<#x<<'='<<x<<' '<<#y<<'='<<y<<' '<<#z<<'='<<z<<'\n'<<endl
#define darr(arr,n) rep(i,(n-arr)){cout<<*(arr+i)<<' ';}cout<<endl
#define ddarr(arr,a,b) rep(i,a){rep(j,b){cout<<*(arr+i*b+j)<<' ';}cout<<endl;}
#define ddd ifstream in("Text.txt");cin.rdbuf(in.rdbuf());


int a[110];
ll cu[110];

int main() {
    int N;
    cin >> N;
    rep(i, N)cin >> a[i];

    int mi = INF;

    for (int T = -1; T <= N; T++) {
    int su1 = 0, su2 = 0;
        rep(i, N) {
            if (i <= T)su1 += a[i];
            else su2 += a[i];
        }
    mi = min(mi, abs(su1 - su2));
    }


    cout << mi << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#define int long long
#define mod 998244353
using namespace std;
inline int read(){
    int f=1,ans=0;char c=getchar();
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9'){ans=ans*10+c-'0';c=getchar();}
    return f*ans;
}
const int MAXN=301;
const int MAXNS=90001;
int n,a[MAXN],S,f[MAXN][MAXNS],g[MAXN][MAXNS];
int ksm(int a,int b){
    int ans=1;
    while(b){
        if(b&1) ans*=a,ans%=mod;
        a*=a,a%=mod;
        b>>=1;
    }return ans;
}
signed main(){
    n=read();
    for(int i=1;i<=n;i++) a[i]=read(),S+=a[i];
    f[0][0]=1,g[0][0]=2;
    for(int i=1;i<=n;i++){
        for(int j=0;j<=S;j++){
            f[i][j]=f[i-1][j]*2;f[i][j]%=mod;
            if(j>=a[i]) f[i][j]+=f[i-1][j-a[i]];f[i][j]%=mod;
            g[i][j]=g[i-1][j];g[i][j]%=mod;
            if(j>=a[i]) g[i][j]+=g[i-1][j-a[i]];g[i][j]%=mod;
        }
    }
    int res=0;
    for(int i=(S+1)>>1;i<S;i++) res+=f[n][i]-g[n][i];res*=3;res%=mod;
    int cnt=(((ksm(3,n)-3*ksm(2,n)+3)%mod)+mod)%mod;
    printf("%lld\n",(((cnt-res)%mod)+mod)%mod);
    return 0;
}

Measured memory_bytes: 422784
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

long long n, a[200009], dp[200009], s;

int main()
{
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	dp[0] = 1;
	s = a[0];
	int pre = 0;
	for (int i = 1; i < n; i++) {
		while ((a[i] ^ s) != a[i] + s) {
			s -= a[pre];
			pre++;
		}
		dp[i] = i - pre + 1;
		s += a[i];
	}
	long long ans = 0;
	for (int i = 0; i < n; i++) {
		ans += dp[i];
	}
	cout << ans << E;
	//system("pause");
	return 0;
}

Measured memory_bytes: 3328
#include<cstdio>
#include<algorithm>
char p[301000];
int D[256], w[301000], Aft[256][4], TD[256], Mod = 1000000007, OK[8], Next[8][4], C[8];
int n;
int main() {
	int i, j, k;
	for (i = 0; i < 8; i++)for (j = 0; j < 3; j++)if ((i >> j) & 1)C[i]++;
	scanf("%s", p);
	for (i = 0; p[i]; i++);
	n = i;
	if (n == 1) {
		int res = 0;
		if (p[0] != '0')res = 1;
		printf("%d\n", res);
		return 0;
	}
	for (i = 0; i < n; i++) {
		if (p[i] != '?')w[i] = p[i] - '0';
		else w[i] = 2;
	}
	for (i = 0; i < 8; i++) {
		for (j = 0; j < 4; j++) {
			int t = i + j * 8;
			for (k = 0; k <= 2; k++) {
				int s = (t >> (k + 3)) << (k + 1);
				s += (t&((1 << k) - 1));
				if (C[(t >> k) & 7] >= 2)s += (1 << k);
				Next[i][j] |= (1 << s);
			}
		}
	}
	for (i = 0; i < 256; i++)for (j = 0; j < 8; j++)for (k = 0; k < 4; k++) {
		if ((i >> j) & 1)Aft[i][k] |= Next[j][k];
	}
	for (i = 0; i < 8; i++) {
		for (j = 0; j < 3; j++) {
			if (w[j] == 2)continue;
			if (w[j] != ((i >> j) & 1))break;
		}
		if (j == 3)D[(1 << i)] = 1;
	}


	for (i = 3; i < n; i += 2) {
		if (w[i] != 1 && w[i + 1] != 1) {
			for (j = 0; j < 256; j++) {
				TD[Aft[j][0]] = (TD[Aft[j][0]] + D[j]) % Mod;
			}
		}
		if (w[i] != 0 && w[i + 1] != 1) {
			for (j = 0; j < 256; j++) {
				TD[Aft[j][1]] = (TD[Aft[j][1]] + D[j]) % Mod;
			}
		}
		if (w[i] != 1 && w[i + 1] != 0) {
			for (j = 0; j < 256; j++) {
				TD[Aft[j][2]] = (TD[Aft[j][2]] + D[j]) % Mod;
			}
		}
		if (w[i] != 0 && w[i + 1] != 0) {
			for (j = 0; j < 256; j++) {
				TD[Aft[j][3]] = (TD[Aft[j][3]] + D[j]) % Mod;
			}
		}
		for (j = 0; j < 256; j++) {
			D[j] = TD[j];
			TD[j] = 0;
		}
	}
	for (i = 0; i < 8; i++) {
		int c = 0;
		for (j = 0; j < 3; j++)if ((i >> j) & 1)c++;
		if (c >= 2)OK[i] = 1;
	}
	int res = 0, ss = 0;
	for (i = 0; i < 256; i++) {
		for (j = 0; j < 8; j++) {
			if (OK[j] && ((i >> j) & 1))break;
		}
		if (j != 8)res = (res + D[i]) % Mod;
	}
	printf("%d\n", res);
}

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

int main() {
  int n, k;
  k = 0;
  cin >> n;
  vector<int> vec(n);
  for(int i=0; i<n; i++){
    cin >> vec.at(i);
  }
  sort(vec.begin(),vec.end());
  for(int i = 0; i<n-1; i++){
    if(vec.at(i) < vec.at(i+1))
      k++;
  }
  cout << k+1;
}


Measured memory_bytes: 256
/*
Author: Racer5x
 ***************************************   UNAUTHORISED COPYING OF CODE PROHIBITED   **********************************
*/
 
// #pragma GCC optimize("O3")
// #pragma GCC optimize("Ofast")
// #pragma GCC optimize("unroll-loops")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#include<bits/stdc++.h>
#define int         long long
#define double      long double
#define pb          emplace_back
#define pf          emplace_front
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define x           first
#define y           second
#define endl        '\n'
#define hell        998244353 
#define PI          3.141592653589
#define tezz        ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define MAX         2000000000000000000
#define M           1000000007
using namespace std;

int dp[(1<<13)];
 
signed main()
{
    tezz

    int n, m;
    cin>>n>>m;
    for(int i=0;i<(1<<13);i++) dp[i] = MAX;

    // for(int i=0;i<(1<<12); i++) cout<<dp[i]<<" ";
    //     cout<<endl;

    dp[0] = 0;

    for(int i=0;i<m;i++){
        int a, b;
        cin>>a>>b;

        vi v(b);
        for(int &x:v) cin>>x;

        for(int mask = 0; mask<(1<<n); mask++){
            int curr = mask;
            for(int j=0;j<b;j++){
                int x = v[j]-1;

                curr = (curr | (1<<x));
            }
            // cout<<mask<<' '<<curr<<endl;
            dp[curr] = min(dp[curr], dp[mask] + a);
        }
    }
    // cout<<endl;

    if(dp[(1<<n) - 1] != MAX) cout<<dp[(1<<n) - 1];
    else cout<<-1;
} 

Measured memory_bytes: 384
def resolve():
    N = int(input())
    c = [[0] * 10 for _ in range(10)]
    for k in map(str, range(1, N+1)):
        i = int(k[0])
        j = int(k[-1])
        c[i][j] += 1
    n = 0
    for i in range(10):
        for j in range(10):
             n += c[i][j] * c[j][i]
    print(n)

resolve()

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
  
  int n;
  cin >> n;
  vector<int> cont(n);
  vector<pair<int,int>> cnt1(100009);
  vector<pair<int,int>> cnt2(100009);
  
  for(int i = 0 ; i < n ; i++){
    cin >> cont.at(i);
  }
  
  for(int i = 0 ; i < n ; i++){
    int a = cont.at(i);
    if(i%2 == 0){
      cnt1.at(a).first++;
      cnt1.at(a).second = a;
    }
    else{
      cnt2.at(a).first++;
      cnt2.at(a).second = a;
    }
  }
  
  sort(cnt1.begin() , cnt1.end());
  reverse(cnt1.begin() , cnt1.end());
  
  sort(cnt2.begin() , cnt2.end());
  reverse(cnt2.begin() , cnt2.end());
  
  int a1 = cnt1.at(0).first;
  int a2 = cnt1.at(1).first;
  int a1_num = cnt1.at(0).second;
  int a2_num = cnt1.at(1).second;
  
  int b1 = cnt2.at(0).first;
  int b2 = cnt2.at(1).first;
  int b1_num = cnt2.at(0).second;
  int b2_num = cnt2.at(1).second;
  
  int ans = n;
  if(b1_num != a1_num){
    ans -= a1+b1;
  }
  else{
    ans -= max(a1+b2 , a2+b1);
  }
  cout << ans << endl;
} 

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

int main() {
  int n; cin>>n;
  vector<int> a(n);
  for (int i=0; i<n; i++) cin>>a[i];

  int cnt=0;
  for (int i=0; i<n; i++) {
    cnt++;
    while ((a[i]==a[i+1])&&(i<n-1)) i++;
    if (i==n-1) break;
    if (a[i]>a[i+1]) {
      while ((a[i]>=a[i+1])&&(i<n-1)) i++;
    }
    else {
      while ((a[i]<=a[i+1])&&(i<n-1)) i++;
    }
  }
  cout<<cnt<<endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001
#define mod 1000000007
#define pi 3.141592653589793

/*ll gcd(ll a,ll b){
    if(b>a) swap(a,b);
    ll r=a%b;
    while(r!=0){
        a=b;
        b=r;
        r=a%b;
    }
    return b;
}*/
int main (){
    int n;
    int mx=0;
    int ans=0;
    cin >> n;
    vector<int>h(n);
    rep(i,n) {
        cin >> h[i];
        mx=max(mx,h[i]);
    }
    rep(i,mx){
        int j=0;
        while(j<n){
            if(h[j]==0) j++;
            else{
                ans++;
                while(j<n&&h[j]>0) j++;
            }
        }
        rep(j,n){
            if(h[j]>0) h[j]--;
        }
    }
    cout << ans << endl;
    return 0;
}



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

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}


int main() {
    int N;
    cin >> N;
    vector<int> v(N);
    REP(i,N) cin >>v[i];

    int cnt = 0;
    int mini = INF;
    REP(i,N) {
        if (mini >= v[i] || i == 0) cnt++;
        chmin(mini,v[i]);
    }

    cout << cnt << endl;

    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define debug(...)   printf( __VA_ARGS__ )
//#define debug(...)   /****nothing****/
#define pb push_back
#define mp make_pair
#define LL long long
#define resett(arr,val,N) for(int ii=0;ii<(N);ii++) arr[ii]=val;
const int MX=1e6;
LL n,a,b,c,d,x,y,ar[MX];

int main()
{
    //freopen("d://i.txt","r",stdin);
    //freopen("d://o.txt","w",stdout);
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0) ;
    while(cin>>a>>b>>c>>d>>n)
    {
        b=min(2*a,b);
        c=min(2*b,c);
        if(c*2<=d)
            cout<<1LL*n*c<<endl;
        else
            cout<<(1LL*(n/2)*d + 1LL*(n%2)*c)<<endl;

    }

    return 0;
}




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

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line = "";

        while ((line = br.readLine()) != null && !line.isEmpty()) {
            int n = Integer.parseInt(line);
            if (n == 0) {
                break;
            }
            int min = 1001, max = -1, sum = 0;
            for (int i = 0; i < n; i++) {
                int s = Integer.parseInt(br.readLine());
                sum += s;
                if (s < min) {
                    min = s;
                }
                if (s > max) {
                    max = s;
                }
            }
            System.out.println((sum - min - max) / (n - 2));
        }
    }
}

Measured memory_bytes: 16908
#include "bits/stdc++.h"
using namespace std;

int main() {
  int N;
  cin >> N;
  long long a[N];
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  
  long long x = a[0];
  long long y = 0;
  for(int i = 1; i < N; i++) {
    y += a[i];
  }
  
  long long min = abs(x-y);
  for (int i = 1; i < N-1; i++) {
    x += a[i];
    y -= a[i];
    long long dif = abs(x-y);
    if(dif < min) min = dif;
  }
  cout << min << endl;
  return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<functional>
#include<queue>
#include <iomanip>
#include<map>
#include<limits>
#include<cmath>
#include<algorithm>
#include<bitset>
#include<utility>
#include<complex>
#include<cstdlib>
#include<set>
#include<cctype>

#define DBG cerr << '!' << endl;
#define REP(i,n) for(int (i) = (0);(i) < (n);++i)
#define rep(i,s,g) for(int (i) = (s);(i) < (g);++i)
#define rrep(i,s,g) for(int (i) = (s);i >= (g);--(i))
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int i = 0;i < (n);i++)cerr << v[i] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()

using namespace std;

typedef long long ll;
typedef vector<int> iv;
typedef vector<iv> iiv;
typedef vector<string> sv;

#define INF 1000000007;

bool lock[100010];
ll dp[100010];
ll a[100010],b[100010];

int main()
{
	int n;cin >> n;
	
	REP(i,n)dp[i] = INF;
	REP(i,n)cin >> a[i];
	REP(i,n)cin >> b[i];
	
	ll now = 0;
	REP(i,n)
	{
		if(a[i] > now)
		{
			lock[i] = true;
			now = a[i];
		}
		dp[i] = min(dp[i],now);
	}
	
	now = 0;
	REP(i,n)
	{
		if(lock[n-i-1] && b[n-i-1] < dp[n-i-1])
		{
			cout << 0 << endl;
			return 0;
		}
		
		if(b[n-i-1] > now)
		{
			if(lock[n-i-1] && b[n-i-1] != dp[n-i-1])
			{
				cout << 0 << endl;
				return 0;
				
			}
			lock[n-i-1] = true;
		}
		now = b[n-i-1];
			
		dp[n-i-1] = min(dp[n-i-1],now);
	}
	
	ll ans = 1;
	
	REP(i,n)
	{
		if(!lock[i])
		{
			ans = (ans*dp[i]) % INF;
		}
	}
	
	//SHOW1d(dp,n);
	//SHOW1d(lock,n);
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 2688
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class t>
using table = vector<vector<t>>;
const ld eps=1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.answer"

bool isso(long long int a) {
	if (a == 1 || a == 0)return false;
	for (long long int i = 2; i*i <= a; ++i) {
		if ((a%i)) {
		}
		else {
			return false;
		}
	}
	return true;
}
int main() {
	
	int N;
	while (cin>>N) {
		for (int i = N - 1;; --i) {
			if (isso(i)) {
				cout << i << " ";
				break;
			}
		}
		for (int i = N + 1;; ++i) {
			if (isso(i)) {
				cout << i << endl;
				break;
			}
		}
	}
	return 0;
}

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

int main(void)
{
    int N,flag,cnt = 0,dist = 0;
    cin >> N;
    vector<int> A(N);

    rep(i, N){
        cin >> A[i];
    }

    rep(i,N-1){
        if(dist == 0){
            if(A[i] < A[i+1]){
                dist = 1;
            }
            if(A[i] > A[i+1]){
                dist = -1;
            }
        }

        else if(dist == 1 && A[i] > A[i+1]){
            dist = 0;
            cnt++;
        }

        else if(dist == -1 && A[i] < A[i+1]){
            dist = 0;
            cnt++;
        }
    }

    cout << cnt+1 << endl;

    return 0;
}

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

using namespace std;

void solve() {
  int N;
  string S, T;
  cin >> N >> S >> T;
  ostringstream ss;
  for (int i = 0; i < N; ++i) {
    ss << S[i] << T[i];
  }
  cout << ss.str() << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  solve();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)

using namespace std;

int32_t main(){IOS;
	
	int arr[5] ; 
	int base = 10;
	for(int i=0;i<5;i++){
		cin >> arr[i];
		if(arr[i]%10){
			base = min(base,arr[i]%10);
			arr[i] /= 10;
			arr[i]++;
			arr[i] *= 10;
		}
	}
	cout << accumulate(arr,arr+5,0ll)+base-10ll<<endl;
	return 0;
}


Measured memory_bytes: 256
N,u,v=map(int,input().split())
edge={i:[] for i in range(1,N+1)}
for i in range(N-1):
    a,b=map(int,input().split())
    edge[a].append(b)
    edge[b].append(a)

parent={i:-1 for i in range(1,N+1)}
depth={i:-1 for i in range(1,N+1)}
parent[v]=0
depth[v]=0
q=set([v])
sub=set([])
while q:
    while q:
        x=q.pop()
        for i in edge[x]:
            if parent[i]==-1:
                parent[i]=x
                depth[i]=depth[x]+1
                sub.add(i)

        if not q:
            q=sub
            sub=set([])
            break

if depth[u]%2==1:
    i=depth[u]//2
    stand=u
    while i>0:
        stand=parent[stand]
        i-=1
    test=depth[stand]
    q=set([stand])
    sub=set([])
    while q:
        while q:
            x=q.pop()
            for i in edge[x]:
                if i!=parent[x]:
                    test=max(test,depth[i])
                    sub.add(i)

            if not q:
                q=sub
                sub=set([])
                break

    print(test-1)
else:
    i=depth[u]//2-1
    stand=u
    while i>0:
        stand=parent[stand]
        i-=1
    test=depth[stand]
    q=set([stand])
    sub=set([])
    while q:
        while q:
            x=q.pop()
            for i in edge[x]:
                if i!=parent[x]:
                    test=max(test,depth[i])
                    sub.add(i)

            if not q:
                q=sub
                sub=set([])
                break

    print(test-1)


Measured memory_bytes: 84452
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int array[]=new int[150];
		int count=0,a,b;
		while(true){
			for(int i=0;i<150;i++){
				array[i]=0;
			}
			while(true){
				a=scan.nextInt();
				b=scan.nextInt();	
				array[a]++;
				array[b]++;
				if(a==0){
					if(b==0){
						break;
					}
				}
			}
			for(int i=0;i<150;i++){
				if(array[1]%2==1&&array[2]%2==1){
					if(i!=1&&i!=2){	
//						System.out.println(i+":番目,"+array[i]);
						if(array[i]%2==0){	
							if(i==149){
								System.out.println("OK");
							}
						}
						else{
							System.out.println("NG");
							break;
						}
					}
				}
				else{
					System.out.println("NG");
					break;
				}
			}
			if(!scan.hasNext()){
				break;
			}
		}
	}
}

Measured memory_bytes: 24216
#include <iostream>
#include <vector>
#include <cstdlib>
#include <algorithm>

using namespace std;
template<class T> inline bool chmax(T& a,T b){if (a < b) {a = b;return 1;}return 0;}
template<class T> inline bool chmin(T& a,T b){if (a > b) {a = b;return 1;}return 0;}

const long long INF = 1LL << 60;

int N;
long long h[100060];
long long dp[100060];

int main () {
    int N,K; cin >> N >> K;
    int price[N];
    for (int i = 0; i < N; i++)
    {
        cin >> price[i];
        /* code */
    }
    sort(price,price+N);
    int sum=0;
    for (int i = 0; i < K; i++)
    {
        sum+=price[i];
    }
    cout << sum << endl;

    return 0;

}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rp(i,n) for(int i=1;i<=(int)n;i++)
int main(){
int a,b,c;cin>>a>>b>>c;
cout<<c<<" "<<a<<" "<<b<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m,i,j,f=0;
    cin>>n>>m;
    char a[n][m];
    for(i=0;i<n;i++){
        for(j=0;j<m;j++){
            cin>>a[i][j];
        }
    }
    vector<int>r,c;
    for(i=0;i<n;i++){
        if(a[i][0] != '.')continue;
        int x=1;
        for(j=1;j<m;j++){
            if(a[i][j] == '.' && a[i][j-1] == '.'){
                x++;
            }
            else{
                break;
            }
        }
        if(x==m){
            r.push_back(i);
        }
    }
    for(i=0;i<m;i++){
        if(a[0][i] != '.')continue;
        int x=1;
        for(j=1;j<n;j++){
            if(a[j][i] == '.' && a[j-1][i] == '.'){
                x++;
            }
            else{
                break;
            }
        }
        if(x==n){
            c.push_back(i);
        }
    }
    for(i=0;i<n;i++){
        if(binary_search(r.begin(),r.end(),i)){
            continue;
        }
        for(j=0;j<m;j++){
            if(binary_search(c.begin(),c.end(),j)){
                continue;
            }
            cout<<a[i][j];
            f=1;
        }
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
import std.algorithm;
import std.bigint;
import std.concurrency;
import std.container;
import std.conv;
import std.functional;
import std.format;
import std.math;
import std.meta;
import std.numeric;
import std.random;
import std.range;
import std.stdio;
import std.string;
import std.traits;
import std.typecons;


auto solve(long N, double[] x, string[] u) {
    auto rate = u.map!(s => s == "JPY" ? 1.0 : 380000.0);
    auto ans = zip(x, rate).map!"a[0] * a[1]".sum;
    return format("%.5f", ans);
}


void main() {
    auto input = stdin.byLine.map!split.joiner;

    long N;
    N = input.front.to!long;
    input.popFront;

    double[] x = new double[](cast(size_t) (N));
    string[] u = new string[](cast(size_t) (N));
    foreach (i; 0 .. cast(size_t) (N)) {
        x[i] = input.front.to!double;
        input.popFront;
        u[i] = input.front.to!string;
        input.popFront;
    }

    static if (is(ReturnType!solve == void))
        solve(N, x, u);
    else
        solve(N, x, u).writeln;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
using ll = long long;
 
int n, x;
 
int main() {
	cin.sync_with_stdio(0); cin.tie(0);
	cin >> n >> x;
	if (x == 2 * n - 1 || x == 1) {
		cout << "No";
		return 0;
	} else {
		cout << "Yes\n";
		if (n % 2 && x == n) {
			for (int i = 1; i < 2 * n; ++i) cout << i << '\n';
			return 0;
		}
		vector<int> l, r;
		l.push_back(x - 1); r.push_back(x + 1);
		
		int a[] = {0, 1};
		for (int i = (x + 2) % (2 * n); i != x - 1; i++, i %= (2 * n)) {
			if (!i) {
				++i;
				if (i == x - 1) break;
			}
			if (a[0] != a[1]) {
				if (a[1]) r.push_back(i);
				else l.push_back(i);
				a[0] = a[1];
			} else {
				if (a[1]) l.push_back(i);
				else r.push_back(i);
				a[1] = !a[1];
			}
		}
		
		
		reverse(all(l));
		for (auto i : l) cout << i << '\n';
		cout << x << '\n';
		for (auto i : r) cout << i << '\n';
	}
}


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

int main(){
int a=0,b=0;
for(int c=0;c<4;c++){
	int d;
	scanf("%d",&d);
	a+=d;
}
for(int c=0;c<4;c++){
	int d;
	scanf("%d",&d);
	b+=d;
}
printf("%d\n",max(a,b));
}

Measured memory_bytes: 3172
#include <stdio.h>
#include <vector>
#include <algorithm>

using namespace std;

struct combination {
    int mass;
    int sugar;
    double density;
};

bool operator<(const combination& left, const combination& right)
{
  return left.density < right.density;
}

int main() {

    int A, B, C, D, E, F;
    scanf("%d %d %d %d %d %d", &A, &B, &C, &D, &E, &F);

    vector<int> water;
    for (int i = 0; i <= 30; ++i) {
        for (int j = 0; j <= 30; ++j) {
            int temp = 100 * A * i + 100 * B * j;
            if (temp <= F && temp != 0) water.push_back(temp);
            else break;
        }
    }

    vector<int> sugar;
    for (int i = 0; i <= 3000; ++i) {
        for (int j = 0; j <= 3000; ++j) {
            int temp = C * i + D * j;
            if (temp <= F) sugar.push_back(temp);
            else break;
        }
    }

    double solubility = 100.0 * E / (100 + E);
    // printf("%f\n", solubility);

    vector<combination> combinations;
    vector<int>::iterator iter_w;
    vector<int>::iterator iter_s;
    for (iter_w = water.begin(); iter_w != water.end(); ++iter_w) {
        for (iter_s = sugar.begin(); iter_s != sugar.end(); ++iter_s) {
            int s = *iter_s;
            int mass = s + *iter_w;
            double d = 100.0 * s / mass;
            combination c = {mass, s, d};
            // printf("%f\n", d);
            if (d <= solubility && mass <= F) combinations.push_back(c);
            else continue;
        }
    }

    combination max = *max_element(combinations.begin(), combinations.end());
    printf("%d %d\n", max.mass, max.sugar);

    return 0;
}


Measured memory_bytes: 18792
import math
K = int(input())

sum = 0
gcd_a_b = 0
for a in range(1,K+1):
  for b in range(1,K+1):
    gcd_a_b = math.gcd(a,b)
    for c in range(1,K+1):
      sum += math.gcd(gcd_a_b,c)
      
print(sum)

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

using namespace std;

int main() {
    int H, W;
    cin >> H >> W;

    vector< vector<string> > map(H, vector<string>(W));

    for (int h = 0; h < H; ++h) {
        string S;
        cin >> S;
        for (int w = 0; w < W; ++w) {
            map[h][w] = S[w];
        }
    }

    // 上下右左に「＃」マスがあればおk
    bool flg = true;
    for (int h = 0; h < H; ++h) {
        for (int w = 0; w < W; ++w) {

            if (map[h][w] == ".") {
                continue;
            }

            int count = 0;


            // 上
            // map[h-1][w] == "#"
            if (h > 0 && map[h-1][w] == "#") {
                ++count;
            }

            // 左
            // map[h][w-1] == "#"
            if (w > 0 && map[h][w-1] == "#") {
                ++count;
            }

            // 右
            // map[h][w+1] == "#"
            if (w < W - 1 && map[h][w+1] == "#") {
                ++count;
            }

            // 下
            // map[i+1][j] == "#"
            if (h < H - 1 && map[h+1][w] == "#") {
                ++count;
            }

            if (count == 0) {
                flg = false;
                break;
            }

        }
    }

    if (flg) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}



Measured memory_bytes: 384
sx,sy,tx,ty=map(int,input().split())

x=tx-sx
y=ty-sy
ans=[]
for i in range(y):
    ans.append("U")
for i in range(x):
    ans.append("R")
for i in range(y):
    ans.append("D")
for i in range(x+1):
    ans.append("L")
for i in range(y+1):
    ans.append("U")
for i in range(x+1):
    ans.append("R")
ans.append("D")
ans.append("R")
for i in range(y+1):
    ans.append("D")
for i in range(x+1):
    ans.append("L")
ans.append("U")
print("".join(ans))


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

const int N = 1 * 100 * 1000 + 1;
long long n, m, dp[N], h[N];
bool vis[N];
vector <int> adj[N], ans[N];

void dfs(int u) {
	vis[u] = true;
	for (int v: adj[u]) {
		int cnt = 0;
		if (vis[v] == false) {
			cnt++;
			h[v] = h[u] + 1;
			dfs(v);
			dp[v] % 2 == 1? ans[v].push_back(u): ans[u].push_back(v);
			dp[u] += dp[v];
		}
		else if (h[v] > h[u]) {
			cnt++;
			ans[u].push_back(v);
		}
		dp[u] += cnt;
	}
}

int main() {
	
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	
	cin >> n >> m;
	for (int i = 0, u, v; i < m; i++) {
		cin >> u >> v;
		adj[u].push_back(v);
		adj[v].push_back(u);
	}
	if (m % 2 == 1)
		return cout << "-1\n", 0;
	dfs(1);
	for (int i = 1; i <= n; i++)
		for (int v: ans[i])
			cout << i << ' ' << v << endl;
	
	return 0;
}

Measured memory_bytes: 18688
#include<bits/stdc++.h>
#define N 300000
typedef long long LL;
using namespace std;
int n;
LL sum, a[N];

LL calc(LL B, LL C, LL D, LL E) {
    return max(max(B, C), max(D, E)) - min(min(B, C), min(D, E));
}

int main() {
    cin >> n;
    for(int i = 1; i <= n; i++) cin >> a[i], sum += a[i];
    LL B = a[1], C = a[2], D = a[3], E = sum - a[1] - a[2] - a[3];
    int p1 = 2, p2 = 4;
    for(int i = p2; i < n; i++) {
        LL tmpD = D + a[i], tmpE = E - a[i];
        if (abs(D - E) > abs(tmpD - tmpE)) D = tmpD, E = tmpE, p2 = i + 1;
        else break;
    }
    LL ans = calc(B, C, D, E);
    for(int i = 3; i <= n - 2; i++) {
        C += a[i], D -= a[i];
        for(int j = p1; j < i; j++) {
            LL tmpB = B + a[j], tmpC = C -  a[j];
            if (abs(B - C) > abs(tmpB - tmpC)) B = tmpB, C = tmpC, p1 = j + 1;
            else break;
        }
        for(int j = p2; j < n; j++) {
            LL tmpD = D + a[j], tmpE = E - a[j];
            if (abs(D - E) > abs(tmpD - tmpE)) D = tmpD, E = tmpE, p2 = j + 1;
            else break;
        }
        ans = min(ans, calc(B, C, D, E));
    }
    cout << ans << endl;
}


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

using lli = long long int;

template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}

template <class T>ostream &operator<<(ostream &o,const pair<T, T>&p)
{o<<"("<<p.first<<", "<<p.second<<")";return o;}

int main(void){
    char b;
    cin >> b;
    if(b == 'A') cout << 'T' << endl;
    else if(b == 'T') cout << 'A' << endl;
    else if(b == 'C') cout << 'G' << endl;
    else if(b == 'G') cout << 'C' << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
using namespace std;

int main() {
    int N;

    cin >> N;

    cout << (N/500)*1000 + ((N%500)/5)*5 << endl;

    return 0;
}

Measured memory_bytes: 256
mod = 998244353
n = int(input())
l = list(map(int, input().split()))
m = [0]*(max(l)+1)

for x in l:
    m[x] += 1
if l[0] != 0 or not all(l[1:]) :
    print(0)
    exit()
t = 1
r = 1
for x in m:
    t = t * pow(r,x,mod) % mod
    r = x

print(t)


Measured memory_bytes: 14020
#include <bits/stdc++.h>
using namespace std;
long long N;
long long total;
vector<int> prime;
int main(){
	cin>>N;
	total=0;
	for(int i=2; i<=200; i++){
		int j=2;
		bool p=true;
		while(j*j<=i){
			if(i%j==0){
				p=false;
				break;
			}
			j++;
		}
		if(p){
			prime.push_back(i);
		}
	}
	long long kali[N+1];
	for(long long i=1; i<=N; i++){
		if(i>1){
			long long idx=N/i;
			kali[i]=i;
			long long j=1;
			while(j<i){
				if(i%j==0){
					kali[i]-=kali[j];
				}
				j++;
			}
			total+=idx*idx*idx*kali[i];
		}else{
			kali[1]=1;
			total+=N*N*N;
		}
	}
	cout<<total<<'\n';
}

Measured memory_bytes: 3644
import java.util.*;
 

public class Main {
    public static void main(String[] args) {   
        Scanner sc = new Scanner(System.in);
        String A = sc.next();
        String S = sc.next();
        String C = sc.next();

            System.out.println("A"+S.charAt(0)+"C");        
        
    }
    
}    





Measured memory_bytes: 21844
n=gets.chomp.to_i
p=gets.chomp.split(" ").map{|s| s.to_i}
c=0
for i in 1..n-2
  if [p[i-1],p[i],p[i+1]].min!=p[i] && [p[i-1],p[i],p[i+1]].max!=p[i]
    c+=1
  end
end
p c

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

/* -128 ~ 127 */
using i8  = int8_t;
/* 0 ~ 255 */
using u8  = uint8_t;
/* -32,768 ~ 32,767 */
using i16 = int16_t;
/* 0 ~ 65,535 */
using u16 = uint16_t;
/* -2,147,483,648 ~ 2,147,483,647 */
using i32 = int32_t;
/* 0 ~ 4,294,967,295 */
using u32 = uint32_t;
/* -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 */
using i64 = int64_t;
/* 0 ~ 18,446,744,073,709,551,615 */
using u64 = uint64_t;
/* (-3.4 * 10^38) ~ (3.4 * 10^38) */
using f32 = float;
/* (-1.7 * 10^308) ~ (1.7 * 10^308) */
using f64 = double;
using f80 = __float80;

template <class T>
using Vec = vector<T>;

template <typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template <typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }

/* 定数 */
constexpr i64 INF = 1'010'000'000'000'000'017LL;
constexpr i64 MOD = 1'000'000'007LL;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;

#define fn auto
#define ALL(v) v.begin(), v.end()

#define GCD(a, b) __gcd(a, b) // 最大公約数
#define LCM(a, b) a / __gcd(a, b) * b // 最小公倍数

fn Main() {
    u32 N;
    cin >> N;
    bool ans = false;
    while (N != 0) {
        if (N % 10 == 7)
            ans = true;
        N /= 10;
    }
    string result = ans ? "Yes" : "No";
    cout << result << endl;
}

fn main() -> int {
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}




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

#define ll long long
#define vecll vector<long long>
#define vec2ll vector<vector<long long>>
#define vecpairll vector<pair<long long,long long>>
#define forll(s,a,b) for(long long s = a;s < b;s++)
#define forllde(s,a) for(long long s = a;s > 0;s--)


int main()
{
  ll n, m, k, ans=0, c;
  cin >> n >> m;
  vec2ll v(m);
  vecll p(m);
  bool ok;
  forll(i, 0, m){
	cin >> k;
	v[i].resize(k);
	forll(j, 0, k){
	  cin >> v[i][j];
	  v[i][j]--;
	}
  }
  forll(i, 0, m) cin >> p[i];
  for (ll i = 0; i < (1 << n); ++i) {
	ok = true;
	forll (j, 0, m) {
	  c = 0;
	  for (ll id : v[j]) {
		if ((i >> id) & 1)
		  ++c;
	  }
	  c %= 2;
	  if (c != p[j])
		ok = false;
	}
	if (ok) {
	  ++ans;
	}
  }
  cout << ans << endl;
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int[] a = new int[N];
		for (int i = 0; i < N; i++) {
			a[i] = scan.nextInt();
		}

		int count = 0;
		for (int i = 0; i < N-2; i++) {
			if (a[i] == a[i+1]) {
				a[i+1] = a[i+2] + 1;
				count++;
			}
		}
		if (a[N-2] == a[N-1]) {
			count++;
		}
		System.out.println(count);
	}

}

Measured memory_bytes: 25684
h, w = map(int, input().split(" "))

if h == 1 or w == 1:
    print(1)
else:
    if w%2 == 0:
        print(w//2*h)
    else:
        sta = (w+1)//2
        if h%2 == 0:
            print((2*sta - 1) * h//2)
        else:
            print((2*sta - 1) * (h//2) + sta)

Measured memory_bytes: 38256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
using namespace std;

using P = std::pair<int, int>;


vector<vector<int>> bfs(vector<string> const& v, int y, int x) {
    vector<vector<int>> d(v.size(), vector<int>(v[0].size(), 1e9));
    d[y][x] = 0;
    queue<P> que;
    que.push(P{y, x});
    while(!que.empty()) {
        P p = que.front(); que.pop();
        int dx[4] = {0, 1, 0, -1},
            dy[4] = {1, 0, -1, 0};
        for(int i=0; i<4; ++i) {
            int ny = p.first + dy[i], nx = p.second + dx[i];
            if(0 <= ny && ny < v.size() && 0 <= nx && nx < v[0].size() && v[ny][nx] != '#' && d[ny][nx] == 1e9) {
                que.push(P{ny, nx});
                d[ny][nx] = d[p.first][p.second] + 1;
            }
        }
    }
    return d;
}

int main() {
    int H, W;
    cin >> H >> W;
    vector<string> v(H);
    for(int i=0; i<H; ++i) {
        cin >> v[i];
    }
    vector<vector<int>> d;
    for(int i=0; i<H; ++i) {
        for(int j=0; j<W; ++j) {
            if(v[i][j] == '%') {
                d = bfs(v, i, j);
            }
        }
    }
    int p=0, s=1e9;
    for(int i=0; i<H; ++i) {
        for(int j=0; j<W; ++j) {
            if(v[i][j] == '@') {
                p = d[i][j];
            }
            if(v[i][j] == '$') {
                s = min(s, d[i][j]);
            }
        }
    }
    if(s <= p) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FORD(i, a, b) for(int i = (a); i >= (b); --i)
#define VAR(v, i) __typeof(i) v=(i)
#define FORE(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define all(v) (v).begin(),(v).end()

#define PII pair<int,int>
#define mp make_pair
#define st first
#define nd second
#define pb push_back
#define lint long long int
#define VI vector<int>

#define debug(x) {cerr <<#x <<" = " <<x <<endl; }
#define debug2(x,y) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y <<endl; } 
#define debug3(x,y,z) {cerr <<#x <<" = " <<x << ", "<<#y<<" = "<< y << ", " << #z << " = " << z <<endl; } 
#define debugv(x) {{cerr <<#x <<" = "; FORE(itt, (x)) cerr <<*itt <<", "; cerr <<endl; }}
#define debugt(t,n) {{cerr <<#t <<" = "; FOR(it,0,(n)) cerr <<t[it] <<", "; cerr <<endl; }}

#define make( x) int (x); scanf("%d",&(x));
#define make2( x, y) int (x), (y); scanf("%d%d",&(x),&(y));
#define make3(x, y, z) int (x), (y), (z); scanf("%d%d%d",&(x),&(y),&(z));
#define make4(x, y, z, t) int (x), (y), (z), (t); scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
#define makev(v,n) VI (v); FOR(i,0,(n)) { make(a); (v).pb(a);} 
#define IOS ios_base::sync_with_stdio(0)
#define HEAP priority_queue

#define read( x) scanf("%d",&(x));
#define read2( x, y) scanf("%d%d",&(x),&(y));
#define read3(x, y, z) scanf("%d%d%d",&(x),&(y),&(z));
#define read4(x, y, z, t) scanf("%d%d%d%d",&(x),&(y),&(z),&(t));
#define readv(v,n) FOR(i,0,(n)) { make(a); (v).pb(a);}


using namespace std;

const int max_n = 1e6 + 5;


int mod = 1e9 + 7;

int powmod(int a, int b) {
	 if (b == 0) return 1;
	 int sq = powmod(a, b/2);
	 sq = (sq * 1LL * sq) % mod;
	 if (b%2 == 0) return sq;
	 return (sq * 1LL * a) % mod;
}

int fac[max_n];
int ifac[max_n];

int newton(int n, int k) {
	if (k < 0 || n < 0) return 0;
	if (k > n) return 0;
	int ans = (fac[n] * 1LL * ifac[k])%mod;
	return (ans * 1LL * ifac[n-k])%mod;
}

int main() {
	make(n);
	fac[0] = 1;
	ifac[0] = 1;
	n--;
	FOR(i,1,n+1) fac[i] = (i * 1LL * fac[i-1]) % mod;
	FOR(i,1,n+1) ifac[i] = powmod(fac[i], mod - 2);
	int ans = fac[n];
	FOR(k,1,n) {
		int mnoz = (fac[n-k]*1LL*fac[k])%mod;
		int ile = (newton(n, k) - newton(k-1, n-k)+mod)%mod;
		ans = (ans + mnoz * 1LL * ile) % mod;
	}
	printf("%d\n", ans);
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const long long INF=INT_MAX/4;
const long long MOD=998244353;
const double EPS=1e-14;
const bool DEBUG=false;

const string YES = "YES";
const string NO = "NO";
const string Yes = "Yes";
const string No = "No";

template<class T>
void debug(T head){
    if(DEBUG){
        cout<<head<<endl;
    }
}

template <class Head, class... Body>
void debug(Head head, Body... body){
    if(DEBUG){
        cout<<head<<" ";
        debug(body...);
    }
}

/////
void answer(ll N, vector<string> &s){
    ll answer = 0;
    ll x = 0, y = 0, z = 0;
    for(auto ss : s){
        int len = ss.length();
        for(int i=0; i<len - 1; ++i){
            if(ss.substr(i, 2) == "AB"){
                answer++;
            }
        }
        if(ss[0] == 'B' && ss[len - 1] == 'A'){
            z++;
        }else if(ss[0] == 'B'){
            x++;
        }else if(ss[len - 1] == 'A'){
            y++;
        }
    }
    debug(answer);
    debug(x, y, z);
    if(z>0){
        answer += z-1;
        // if(x != y){
        if(x + y > 0){
            answer++;
        }
    }
    answer += min(x, y);
    cout<<answer<<endl;
    return;
}

/////

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

    ll N;
    cin>>N;
    vector<string> s(N);
    for(auto &ss : s){
        cin>>ss;
    }
    answer(N, s);

    return 0;
}


Measured memory_bytes: 3716
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vi vector<int>
#define vl vector<ll>
#define vpii vector<pii>
#define vpll vector<pll>
using namespace std;
unordered_map<ll,ll> cnt;
ll BC(int n, int k)  
{  
    ll res = 1;   
    if ( k > n - k )  
        k = n - k;  
    for (int i = 0; i < k; ++i)  
    {  
        res *= (n - i);  
        res /= (i + 1);  
    }  
    return res;  
} 
ll solve(){
	ll ans = 0;
	for(auto it : cnt){
		if(it.second < 2)
			continue;
		else{
			ans += BC(it.second, 2);
		}
	}
	return ans;
}
int main()
{
	int n;
	cin>>n;
	vector<int> arr;
	for(int i = 0; i < n; i++){
		int a;
		cin>>a;
		arr.push_back(a);
		cnt[a]++;
	}
	ll ans = solve();
	for(int i = 0; i < n; i++){
		ans -= cnt[arr[i]] - 1;
		cout<<ans<<endl;
		ans += cnt[arr[i]] - 1;
	}
	return 0;
	return 0;
}


Measured memory_bytes: 8380
t = int(input())
import heapq
def tr(pnt,m):
  try:
    if use[m] > pnt:
      heapq.heappush(now,[pnt,m])
      use[m] = pnt
  except:
    heapq.heappush(now,[pnt,m])
    use[m] = pnt
for _ in range(t):
  n,a,b,c,d = map(int,input().split())
  now = [[0,n]]
  use = {}
  ans = n*d
  while True:
    sc,num = heapq.heappop(now)
    ans = min(ans,sc+num*d)
    if num == 1:
      print(ans)
      break

    if num % 2 == 0:
      tr(sc+a,num//2)
    else:
      tr(sc+a+d,(num-1)//2)
      tr(sc+a+d,(num+1)//2)
    
    if num % 3 == 0:
      tr(sc+b,num//3)
    elif num % 3 == 1:
      tr(sc+b+d,(num-1)//3)
    else:
      tr(sc+b+d,(num+1)//3)
    
    if num % 5 == 0:
      tr(sc+c,num//5)
    elif num % 5 == 1:
      tr(sc+c+d,(num-1)//5)
    elif num % 5 == 2:
      tr(sc+c+2*d,(num-2)//5)
    elif num % 5 == 3:
      tr(sc+c+2*d,(num+2)//5)
    else:
      tr(sc+c+d,(num+1)//5)

Measured memory_bytes: 87880
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int N,oc=0;
    cin>>N;
    for(int i=0;i<N;++i){
        if((i+1)%2==1)++oc;
    }
    cout<<1.0*oc/N<<endl;
}


Measured memory_bytes: 256