akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"fmt"
	"strings"
)

var stones []string

func judge(closePIndex int, closeGIndex int, distantPIndex int, distantGIndex int) {
	// check a person who has a more distant goal first
	for {
		// check if the person can arrive the goal
		if distantPIndex == distantGIndex {
			break
		} else if distantPIndex+1 == distantGIndex {
			distantPIndex++
			break
		} else if distantPIndex+2 == distantGIndex {
			distantPIndex += 2
			break
		}

		// check if the person can move forward
		if stones[distantPIndex+2] != "#" {
			distantPIndex += 2
			continue
		} else if stones[distantPIndex+1] != "#" {
			distantPIndex++
			continue
		}

		// no way to reach the goal or go forward
		fmt.Println("No")
		return
	}

	// Check the other person next
	for {
		// check if the person can arrive the goal
		if closePIndex == closeGIndex || closePIndex+1 == closeGIndex || closePIndex+2 == closeGIndex {
			fmt.Println("Yes")
			return
		}

		// check if the person can move forward
		if stones[closePIndex+2] != "#" && closePIndex+2 != distantPIndex {
			closePIndex += 2
			continue
		} else if stones[closePIndex+1] != "#" && closePIndex+1 != distantPIndex {
			closePIndex++
			continue
		}

		// no way to reach the goal or go forward
		fmt.Println("No")
		return
	}
}

func main() {
	var n, a, b, c, d int
	fmt.Scan(&n, &a, &b, &c, &d)

	var s string
	fmt.Scan(&s)
	stones = strings.Split(s, "")

	if c < d {
		judge(a-1, c-1, b-1, d-1)
	} else {
		// Check if A can overtake B
		// Need to be "AB." at some point

		// 1. find a place where ".B."
		bIndex := b - 1
		for {
			// Reached the end of the path
			if bIndex+1 == n {
				fmt.Println("No")
				return
			}

			// Find a nice place <3
			if stones[bIndex-1] == "." && stones[bIndex+1] == "." {
				break
			}

			// Can't move anymore (reached B's goal)
			if bIndex == d-1 {
				fmt.Println("No")
				return
			}

			// Try one step
			if stones[bIndex+1] == "." {
				bIndex++
				continue
			}

			// Try two steps
			if bIndex+2 < n && stones[bIndex+2] == "." {
				bIndex += 2
				continue
			}

			// No way to move
			fmt.Println("No")
			return
		}

		// 2. move A to just before B --> "AB."
		aIndex := a - 1
		for {
			// already "AB."
			if aIndex == bIndex-1 {
				break
			}
			// one step to "AB."
			if aIndex+1 == bIndex-1 {
				aIndex++
				break
			}
			// two steps to "AB."
			if aIndex+2 == bIndex-1 {
				aIndex += 2
				break
			}

			// try two steps forward
			if stones[aIndex+2] == "." {
				aIndex += 2
				continue
			}
			// try one step forward
			if stones[aIndex+1] == "." {
				aIndex++
				continue
			}

			// No way to move
			fmt.Println("No")
			return
		}

		// 3. overtake B --> ".BA"
		aIndex += 2

		// 4. do judge for the rest of the path
		judge(bIndex, d-1, aIndex, c-1)
	}
}


Measured memory_bytes: 4864
#include <bits/stdc++.h>
#define ll              long long int
#define int             int64_t
#define ff              first
#define ss              second
#define pb              push_back
#define mpair           make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define sbits(x)      __builtin_popcountll(x)
#define zbits(x)      __builtin_popcountlliltin_ctzll(x)
#define w(t)            int t;cin>>t;while(t--)
#define uset            unordered_set
#define en              cout<<endl
using namespace std;
void fast(){ios_base::sync_with_stdio(false);cin.tie(NULL);cout<<fixed<<setprecision(10);}
int max2(int a,int b){ if(a>b) return a;return b;}
int min2(int a,int b){ if(a<b)return a;return b;}
int max3(int a,int b,int c){ return max2(a,max2(b,c));}
int min3(int a,int b,int c){ return min2(a,min2(b,c));}
void system_output(){
  #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
   #endif
}
void solve(){
     string s;
     cin>>s;
     if(s[1]=='R')
      cout<<"ABC"<<endl;
      else
      cout<<"ARC"<<endl;  
}
signed main(void)
{
      fast();
      //w(t)
      solve();

}


Measured memory_bytes: 3672
"""memo
    numpyでやるときは配列を一気に更新するが(numpy使いたくないのでやらない)，
    このやり方は後ろの方から更新することで後の更新に影響を与えない(考え方すごい)．
    (参考#9889377)
"""

import sys
input = sys.stdin.readline

def main():
    #1:初期化
    N,W = map(int,input().split())
    dp = [0]*(W+1)

    #2:初期値(元からゼロなので記述無し)

    #3:dp実行部(貰うDP)
    for i in range(N):
        w, v = map(int,input().split())
        for i in range(W, w-1, -1):
            tmp = dp[i-w] + v
            if dp[i] < tmp:
                dp[i] = tmp
        #print(dp,sep="\n")

    #4:出力
    print(max(dp))

if __name__ == '__main__':
    main()

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

using namespace std;

int main(){
  int N,W;
  cin >> N >> W;
  vector< pair<int,int> > vec(N);
  for(int i = 0; i < N; i++) cin >> vec[i].first >> vec[i].second;
  vector<int> dp(W+1, 0);
  for(int i = 0; i < N; i++)
    for(int j = W; j >= 0; j--)
      if(j+vec[i].second <= W)
        dp[j+vec[i].second] = max(dp[j+vec[i].second], dp[j]+vec[i].first);
  int ans = 0;
  for(int i = 0; i <= W; i++) ans = max(ans, dp[i]);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1236
#include<cstdio>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/hash_policy.hpp>
#define neko 100010
#define orz return printf("-1\n"),0
#define f(i,a,b) for(register int i=(a);i<=(b);i=-(~i))
int n,a[neko],b[neko],c[neko],d[neko],fa[neko],x,ans,cnt;
__gnu_pbds::gp_hash_table<int,int>ht;
using namespace std;
int find(int x){return fa[x]^x?fa[x]=find(fa[x]):x;}
int main()
{
	scanf("%d",&n);
	f(i,1,n)scanf("%d",&a[i]),c[i]=a[i],x^=a[i];c[n+1]=a[n+1]=x,x=0;
	f(i,1,n)scanf("%d",&b[i]),d[i]=b[i],x^=b[i];d[++n]=b[n]=x;
	sort(c+1,c+n+1);
	sort(d+1,d+n+1);
	f(i,1,n-1)if(c[i]^d[i])orz;
	f(i,1,n)
	{
		if(a[i]^b[i]||i==n)
		{
			if(i<n)++ans;
			if(!ht[a[i]])ht[a[i]]=++cnt;
			if(!ht[b[i]])ht[b[i]]=++cnt;
		}
	}if(!cnt)return printf("0\n"),0;
	f(i,1,cnt)fa[i]=i;
	f(i,1,n)a[i]=ht[a[i]],b[i]=ht[b[i]];
	f(i,1,n)if(a[i]^b[i])fa[find(b[i])]=find(a[i]);
	f(i,1,cnt)if(fa[i]==i)++ans;
	return printf("%d\n",ans-1),0;
}

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

#define int long long

int gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

signed main()
{
    int i=0, j=0, k=0, ans=0;
    int N,M,A[10000];
    cin>>N>>M;
    for(i=0;i<M;i++){
        cin>>j;
        k+=j;
    }

    if(N<k)
        cout<<-1<<endl;
    else
        cout<<N-k<<endl;

    return 0;
}

Measured memory_bytes: 3632
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>
#include <complex>
#include <cstdint>
#include <tuple>
#include <regex>
#include <numeric>

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define MOD 1000000007

int s(LL x) {
	int ret = 0;
	while (x) {
		ret += x % 10;
		x /= 10;
	}
	return ret;
}


int main() {
	LL d = 1;
	int k;
	LL n = 1;
	scanf("%d", &k);
	while (k) {
		cout << n << endl;
		if (n+d > s(n+d)*d) {
			d *= 10;
		}
		n += d;
		k--;
	}
	return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/abc133/tasks/abc133_a

#include <iostream>
using namespace std;
using ll = long long;

struct C {
    ll N_{};
    ll A_{};
    ll B_{};
    C(ll N, ll A, ll B) : N_(N), A_(A), B_(B){}
    ll f() {
        return B_ < N_*A_ ? B_ : N_*A_;
    }

};
int main() {
    ll N, A, B;
    cin >> N >> A >> B;
    C c{N, A, B};
    cout << c.f() << endl;
    return 0;
}


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

int main() {
	string a,b;
	int i, l;
	
	cin >>a;
	l=a.size();
	b="";
	for (i=0;i<l;i++){
		b=a.substr(i,1)+b;
	}
	cout << b<<endl;
	return 0;
}

Measured memory_bytes: 1184
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;


int main(){
  int N;
  cin >> N;
  vector<int> v;
  rep(i,N){
    int a;
    cin >> a;
    v.push_back(a);
  }
  sort(ALLOF(v));

  ll ret = 0;
  rep(i,N){
    REP(j,i+1,N){
      int b = v[i];
      int a = v[j];

      // a-b < c < a+b
      // => a-b < a < c < a+b
      auto high = lower_bound(ALLOF(v), a+b);
      int dist = high - v.begin();
      //cout << b << " " << a << " " << dist << " " << dist-1-j << endl;
      ret += dist-1 - j;
    }
  }

  cout << ret << endl;
  
  return 0;
}



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

int solve() {
	int n;
	cin >> n;
	int k;
	cin >> k;
	int a[n];
	int i;
	for (i = 0; i < n; i++)cin >> a[i];
	if (n == 0)return 0;
	if (n == 1)return 0;
	int dp[n];
	dp[0] = 0;
	dp[1] = abs(a[1] - a[0]);
	int j;
	for (i = 2; i < n; i++) {
		int mn = inf;
		for (j = 1; j <= k && i - j >= 0; j++) {
			mn = min(dp[i - j] + abs(a[i] - a[i - j]) ,  mn);
		}
		dp[i] = mn;
	}

	return dp[n - 1];
}




int32_t main() {
	std::ios::sync_with_stdio(false);
	cout.tie(0);
	cin.tie(0);
	cout << solve();
	return 0;
}

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

struct data{
    int a,b,c;
    bool operator < (data obj) const{
        return ((this->a)-(this->b)) > obj.a-obj.b;
    }
};

signed main(){
    int x,y,z;
    cin>>x>>y>>z;
    int n = x+y+z;
    vector<data> v(n);
    rep(i,n){
        int a,b,c;
        cin>>a>>b>>c;
        v[i] = data{a,b,c};
    }
    
    sort(all(v));
    
    
    rep(i,n){
        v[i].a -= v[i].c;
        v[i].b -= v[i].c;
    }
    
    auto f = [&](vector<int> &dax, vector<int> &daz){
        priority_queue<pii,vector<pii>,greater<pii>> pq;
        rep(i,n){
            if(i<x){
                pq.push(pii(v[i].a,v[i].c));
                dax[i+1] = dax[i] + v[i].a+v[i].c;
            }else{
                pq.push(pii(v[i].a,v[i].c));
                dax[i+1] = dax[i] + (v[i].a+v[i].c);
                
                dax[i+1] -= pq.top().first+pq.top().second;
                daz[i+1] = daz[i] + pq.top().second;
                pq.pop();
            }
        }
    };
    
    vector<int> dax(n+1,0), daz(n+1,0), dby(n+1,0), dbz(n+1,0);

    f(dax, daz);

    reverse(all(v));
    rep(i,n)swap(v[i].a,v[i].b);
    
    swap(x,y);
    f(dby, dbz);
    swap(x,y);
    
    int ans = 0;
    for(int i=x;i<=n-y;i++){
        //        cout<<i<<" : "<<dax[i]<<" "<<daz[i]<<" "<<dby[n-i]<<" "<<dbz[n-i]<<endl;
        ans = max(ans,dax[i]+daz[i]+dby[n-i]+dbz[n-i]);
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 7924
#include <bits/stdc++.h>
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; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }


int main() {
    int N; cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; ++i) cin >> A[i];
    sort(A.begin(), A.end()); // ソート
    
    bool ok = true;
    for (int i = 0; i + 1 < N; ++i) {
        if (A[i] == A[i+1]) ok = false;
    }
    if (ok) cout << "YES" << endl;
    else cout << "NO" << endl;
}


Measured memory_bytes: 1024
#include<stdio.h>
#include<string.h>
int main(void){
    char S[7];
    char str3[2],str4[2],str5[2],str6[2];
    scanf("%s",S);
    strncpy(str3,S+2,1);
    str3[1]='\0';
    strncpy(str4,S+3,1);
    str4[1]='\0';
    strncpy(str5,S+4,1);
    str5[1]='\0';
    strncpy(str6,S+5,1);
    str6[1]='\0';
    if(strcmp(str3,str4)==0 && strcmp(str5,str6)==0){
        printf("Yes");
    }else{
        printf("No");
    }
    return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdint>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <valarray>
#include <vector>

#if __has_include(<string_view>)
#include <string_view>
#endif
#if __has_include(<optional>)
#include <optional>

template <class T>
constexpr const T& max(const T& a, const std::optional<T>& b)
{
    return b ? max(a, *b) : a;
}

template <class T>
constexpr const T& max(const std::optional<T>& a, const T& b)
{
    return a ? max(*a, b) : b;
}

template <class T>
constexpr const std::optional<T>& max(const std::optional<T>& a, const std::optional<T>& b)
{
    if (a && b)
        return *a > *b ? a : b;
    else if (a)
        return a;
    else
        return b;
}

template <class T>
constexpr const T& min(const T& a, const std::optional<T>& b)
{
    return b ? min(a, *b) : a;
}

template <class T>
constexpr const T& min(const std::optional<T>& a, const T& b)
{
    return a ? min(*a, b) : b;
}

template <class T>
constexpr const std::optional<T>& min(const std::optional<T>& a, const std::optional<T>& b)
{
    if (a && b)
        return *a < *b ? a : b;
    else if (a)
        return a;
    else
        return b;
}

#endif
#if __has_include(<any>)
#include <any>
#endif

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

using namespace std;

template <class T, class U>
istream& operator>>(istream& is, pair<T, U>& pair)
{
    is >> pair.first >> pair.second;
    return is;
}

template <class T>
istream& operator>>(istream& is, vector<T>& collection)
{
    for (auto& item : collection)
        is >> item;
    return is;
}

template <class T>
istream& operator>>(istream& is, valarray<T>& collection)
{
    for (auto& item : collection)
        is >> item;
    return is;
}

template <class T>
T peak_and_pop(std::queue<T>& q)
{
    assert(!q.empty());
    T t = move(q.front());
    q.pop();
    return t;
}

template <class T>
T peak_and_pop(std::priority_queue<T>& q)
{
    assert(!q.empty());
    T t = move(q.top());
    q.pop();
    return t;
}

template <class T>
T peak_and_pop(std::stack<T>& q)
{
    assert(!q.empty());
    T t = move(q.top());
    q.pop();
    return t;
}

void solution()
{
    int a,b;
    cin >> a >> b;
    for(int i : {1,2,3}){
        if(i != a && i != b){
            cout << i << '\n';
        }
    }
}

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


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void) {
	int n;

	cin >> n;

	int debt = 100000;
	for (int i = 1; i <= n; i++) {
		debt = (debt * 1.05);
		if (debt % 1000) {
			debt /= 1000;
			debt *= 1000;
			debt += 1000;
		}
	}

	cout << debt << endl;

	return 0;
}

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

int dp[50];

int fib(int n){
	if( n==0||n==1){
		return dp[n];
	}
	if(dp[n]==-1){
		dp[n]=fib(n-1)+fib(n-2);
	}
	return dp[n];
}

int main() {
	int n;
	cin>>n;
	for(int i=0;i<50;i++){
		dp[i]=-1;
	}
	dp[0]=dp[1]=1;
	printf("%d\n",fib(n));
}


Measured memory_bytes: 3228
#include<stdio.h>

int main()
{
  short x,y;
  int s,i,a,b,max;
  int n,m,p,q,r;

  while(1){
    max = 0;
    scanf("%hd %hd %d",&x,&y,&s);

    if(x == 0 && y == 0 && s == 0){
      break;
    }

    for(i = 1;i <= s/2;i++){
      n = i * (100+x) / 100;
      m = s - n;
      p = m * 100 / (100+x);

      while(1){
        p++;
        q = p * (100+x) / 100;

        if(n + q != s){
          p--;
          break;
        }
      }

      r = p * (100+x) / 100;

      if(n + r == s){
        a = i * (100+y) / 100;
        b = p * (100+y) / 100;
        if(a+b > max){
          max = a + b;
        }
      }
    }

    printf("%d\n",max);
  }

  return 0;
}

Measured memory_bytes: 600
import sys
cnt = 0

def merge_sort(a, left, right):
	if left + 1 < right:
		mid = int(left + (right - left) / 2)
		merge_sort(a, left, mid)
		merge_sort(a, mid, right)
		merge(a, left, mid, right)

def merge(a, left, mid, right):
	n1 = mid - left
	n2 = right - mid
	L = a[left:left+n1]
	R = a[mid:mid+n2]
	L.append(sys.maxsize)
	R.append(sys.maxsize)
	i = j = 0
	tmp = n1
	for k in range(left, right):
		if L[i] <= R[j]:
			if R[j] != sys.maxsize:
				tmp -= 1
			a[k] = L[i]
			i += 1
		else:
			if L[i] != sys.maxsize:
				global cnt
				cnt += tmp
			a[k] = R[j]
			j += 1		
	
n = int(input())
a = list(map(int, input().split()))
merge_sort(a, 0, len(a))
print(cnt)



Measured memory_bytes: 27484
package main

import "fmt"

func main(){
	var a,b,c,d int
	fmt.Scan(&a,&b,&c,&d)
	for ;; {
		c -= b
		if c <= 0 {
			fmt.Println("Yes")
			break
		}
		a -= d
		if a <= 0 {
			fmt.Println("No")
			break
		}
	}
}


Measured memory_bytes: 1752
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head

const int N=201000;

int tot,l[N],r[N],cnt[N],d[N],w[N],n,pt[N],u,v;
VI e[N];

void dfs(int u,int f) {
	l[u]=++tot;
	for (auto v:e[u]) if (v!=f) {
		dfs(v,u);
	}
	r[u]=tot;
}

int nd[4*N];
void upd(int p) {
	nd[p]=min(nd[p+p],nd[p+p+1]);
}
void build(int p,int l,int r) {
	nd[p]=1<<30;
	if (l==r) {
	} else {
		int md=(l+r)>>1;
		build(p+p,l,md);
		build(p+p+1,md+1,r);
		upd(p);
	}
}
int query(int p,int l,int r,int tl,int tr) {
	if (tl==l&&tr==r) return nd[p];
	else {
		int md=(l+r)>>1;
		if (tr<=md) return query(p+p,l,md,tl,tr);
		else if (tl>md) return query(p+p+1,md+1,r,tl,tr);
		else return min(query(p+p,l,md,tl,md),query(p+p+1,md+1,r,md+1,tr));
	}
}
void modify(int p,int l,int r,int x,int v) {
	if (l==r) nd[p]=v;
	else {
		int md=(l+r)>>1;
		if (x<=md) modify(p+p,l,md,x,v);
		else modify(p+p+1,md+1,r,x,v);
		upd(p);
	}
}

void dfs2(int u,int f,int dep) {
	d[u]=dep;
	pt[dep]=u;
	modify(1,1,n,u,dep);
	w[u]=pt[min(query(1,1,n,u,n)+1,dep)];
	if (f!=0&&d[w[u]]<d[w[f]]) {
		w[u]=w[f];
	}
	cnt[l[w[u]]]++;
	cnt[r[w[u]]+1]--;
	for (auto v:e[u]) if (v!=f) {
		dfs2(v,u,dep+1);
	}
	modify(1,1,n,u,1<<30);
}

int main() {
	scanf("%d",&n);
	rep(i,1,n) {
		scanf("%d%d",&u,&v);
		e[u].pb(v);
		e[v].pb(u);
	}
	build(1,1,n);
	dfs(1,0);
	dfs2(1,0,1);
	rep(i,1,n+1) cnt[i]+=cnt[i-1];
	rep(i,2,n+1) printf("%d ",cnt[l[i]]-1);
	puts("");
}

Measured memory_bytes: 29824
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
typedef long long lint;
typedef pair<int, int> p;

int main()
{
    int a, b;
    cin >> a >> b;
    int cnt = 0;
    for (int n = a; n <= b; n++) {
        // cout << n % 10 << endl;
        // cout << (n % 100) / 10 << endl;
        // cout << (n / 1000) % 10 << endl;
        // cout << n / 10000 << endl;
        if ((n % 10 == n / 10000) && (((n % 100) / 10) == (n / 1000) % 10))
            cnt++;
    }
    cout << cnt << endl;
    return 0;
}

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


#define Node(a,b,c,d) make_pair(a,make_pair(b,make_pair(c,d)))
#define T pair<int,pair<int,pair<int,int> > >

typedef long long LL;
map<T,LL> cnt;
const int maxn = 500;

int A[maxn][4];
int n;

T stand(T t)
{
    int num[4];
    num[0] = t.first;
    num[1] = t.second.first;
    num[2] = t.second.second.first;
    num[3] = t.second.second.second;

    T tmp[4];


    for(int s = 0;s < 4;++s)
    {
        tmp[s] = Node(num[(s+0)%4],num[(s+1)%4],num[(s+2)%4],num[(s+3)%4]);
    }
    sort(tmp,tmp+4);
    return tmp[0];

}

void update(int id,int val)
{
    T now = stand(Node(A[id][0],A[id][1],A[id][2],A[id][3]));
    cnt[now] += val;
}


LL calsame(T t)
{
    int num[4];
    num[0] = t.first;
    num[1] = t.second.first;
    num[2] = t.second.second.first;
    num[3] = t.second.second.second;


    T tmp[4];
    for(int s = 0;s < 4;++s)
    {
        tmp[s] = Node(num[(s+0)%4],num[(s+1)%4],num[(s+2)%4],num[(s+3)%4]);
    }
    LL c = 0;
    for(int s = 0;s < 4;++s)
        if(tmp[s] == tmp[0])
            c++;
    return c;

}

int main()
{
   // freopen("./test.txt","r",stdin);
    scanf("%d",&n);
    cnt.clear();
    for(int i = 1;i <= n;++i)
    {
        for(int j = 0;j < 4;++j)
            scanf("%d",&A[i][j]);
        update(i,1);
    }

    LL res = 0;
    for(int i = 1;i <= n;++i)
    {
        update(i,-1);

        for(int j = i+1;j <= n;++j)
          //  if(i != j)
            {
                update(j,-1);


                int Down[4];
                for(int ds = 0;ds < 1;++ds)
                {
                    for(int x = 0;x < 4;++x)
                        Down[x] = A[i][(ds+x)%4];

                    int Up[4];
                    for(int us = 0;us < 4;++us)
                    {
                        for(int y = 0;y < 4;++y)
                            Up[y] = A[j][(us-y+4)%4];

                        LL now = 1;

                        T X[4];

                        for(int k = 0;k < 4;++k)
                        {
                            X[k] = stand(Node(Down[k],Up[k],Up[(k+1)%4],Down[(k+1)%4]));

                            LL csame = calsame(X[k]);

                            now *= csame*cnt[X[k]];

                            cnt[X[k]] -= 1;

                        }

                        res += now;

                        for(int k = 0;k < 4;++k)
                            cnt[X[k]] += 1;

                       // printf("**** %d  %d\n",i,j);
//                        for(int k = 0;k < 4;++k)
//                            printf("%d%c",Down[k]," \n"[k == 3]);
//
//                        for(int k = 0;k < 4;++k)
//                            printf("%d%c",Up[k]," \n"[k == 3]);
//
//                        puts("");
                    }

                }



                update(j,1);
            }

        update(i,1);
    }

    printf("%lld\n",res/3);

    return 0;

}


Measured memory_bytes: 80128
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>
using namespace std;
int main(){
  vector<double> high;
  double d;
  while(cin >>d) high.push_back(d);
  sort(high.begin(),high.end());
  printf("%.1lf\n",high[high.size()-1]-high[0]);
  return 0;
}

Measured memory_bytes: 1260
// https://beta.atcoder.jp/contests/abc067

#include <bits/stdc++.h>
using namespace std;

void print_yes_no(bool cond, string yes = "Possible", string no = "Impossible") { cout << (cond ? yes : no) << endl; }

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

    sort(len.begin(), len.end(), greater<>());
    auto ans = accumulate(len.begin(), len.begin() + k, 0);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func checkAllEven(nums []int) bool {
	for i := range nums {
		if nums[i]%2 != 0 {
			return false
		}
	}

	return true
}

func main() {
	var (
		n     int
		count int
	)
	fmt.Scan(&n)
	nums := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&nums[i])
	}

	for checkAllEven(nums) {
		count++
		for i := 0; i < len(nums); i++ {
			nums[i] = nums[i] / 2
		}
	}
	fmt.Println(count)
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
using P = pair<int,int>;

int main(){
  int h, w;
  cin >> h >> w;
  vector<string> m(h);
  for(int i=0; i<h; ++i) cin >> m[i];
  queue<P> que;
  que.push(make_pair(0,0));
  vector<vector<int>> dis(h,vector<int>(w,-1));
  dis[0][0] = 1;
  while(!que.empty()){
    int x, y;
    tie(x,y) = que.front();
    que.pop();
    if(x>0 && dis[x-1][y] == -1 && m[x-1][y] == '.'){
      dis[x-1][y] = dis[x][y] +1;
      que.push(make_pair(x-1,y));
    }
    if(y>0 && dis[x][y-1] == -1 && m[x][y-1] == '.'){
      dis[x][y-1] = dis[x][y] +1;
      que.push(make_pair(x,y-1));
    }
    if(x<h-1 && dis[x+1][y] == -1 && m[x+1][y] == '.'){
      dis[x+1][y] = dis[x][y] +1;
      que.push(make_pair(x+1,y));
    }
    if(y<w-1 && dis[x][y+1] == -1 && m[x][y+1] == '.'){
      dis[x][y+1] = dis[x][y] +1;
      que.push(make_pair(x,y+1));
    }
  }
  if(m[0][0] == '#' || dis[h-1][w-1] == -1){
    cout << -1 << endl;
    return 0;
  }
  int ans = 0;
  for(int i=0; i<h; ++i) for(int j=0; j<w; ++j){
    if(m[i][j] == '.') ++ans;
  }
  ans -= dis[h-1][w-1];
  cout << ans << endl;
}

Measured memory_bytes: 3616
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
#define endl "\n"
#define pii pair<int,int> 
#define ff first
#define ss second
#define mii map<int,int>
#define si set<int>
#define sti stack<int>
#define qi queue<int>
#define vi vector<int>
#define pq priority_queue<int>
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
const int M=998244353;

void self_add(int &x,int &y){
	x=(x+y)%M;
}

void solve(){
	int n,s;
	cin>>n>>s;
	int a[n];
	for(int i=0;i<n;i++) cin>>a[i];
	int dp[n+1][s+1];
	memset(dp,0,sizeof(dp));
	dp[0][0]=1;
	for(int i=0;i<n;i++){
		for(int j=0;j<=s;j++){
			dp[i+1][j]=(dp[i+1][j]+2*dp[i][j])%M;
			if(j+a[i]<=s){
				self_add(dp[i+1][j+a[i]],dp[i][j]);
			}
		}
	}
	cout<<dp[n][s]<<endl;
}

int32_t main(){
	IOS;
	int t=1;
	//cin>>t;
	while(t--){
		solve();	
	}
}

Measured memory_bytes: 73964
import java.util.*;
import java.io.*;

public class Main{

static BufferedReader s1;
static BufferedWriter out;
static String read() throws IOException{String line="";while(line.length()==0){line=s1.readLine();continue;}return line;}
static int int_v (String s1){return Integer.parseInt(s1);}
static long long_v(String s1){return Long.parseLong(s1);}
static int[] int_arr() throws IOException{String[] a=read().split("\\s+");int[] b=new int[a.length];for(int i=0;i<a.length;i++){b[i]=int_v(a[i]);}return b;}
static long[] long_arr() throws IOException{String[] a=read().split("\\s+");long[] b=new long[a.length];for(int i=0;i<a.length;i++){b[i]=long_v(a[i]);}return b;}
static void assign(){s1=new BufferedReader(new InputStreamReader(System.in));out=new BufferedWriter(new OutputStreamWriter(System.out));}
static long Modpow(long a,long p,long m){long res=1;while(p>0){if((p&1)!=0){res=(res*a)%m;}p >>=1;a=(a*a)%m;}return res;}
static long Modmul(long a,long b,long m){return ((a%m)*(b%m))%m;}
static int gcd(int a,int b){if(b==0){return a;}return gcd(b,a%b);}
//......................................@uthor_Alx..............................................
static long mod=(long)1e9+7;
static void spf(int n, int[] spf){
        for(int i=2;i<=(int)Math.sqrt(n);i++){
          if(spf[i]!=0) continue;
          spf[i]=i;
          for(int j=i*i;j<=n;j+=i){
            if(spf[j]!=0) continue;
            spf[j]=i;
          }
        }
        for(int i=1;i<=n;i++){
          if(spf[i]==0){spf[i]=i;}
        }
    }
public static void main(String[] args) throws  IOException{
                assign();
               int[] x=int_arr();
               int n=x[0];//,m=x[1];
               int[] a=int_arr();
               int[] spf=new int[1000001];
               spf[1]=1;
               spf(1000000,spf);
               int gg=a[0];
               boolean[] b=new boolean[1000001];
               boolean bb=true;
               for(int z:a){gg=gcd(gg,z);}
                for(int i=0;i<n;i++){
                    int ce=a[i],cf=spf[ce];
                    while(ce!=1){
                        if(cf==0) break;
                        while(ce%cf==0){
                            if(b[cf]) bb=false;
                            ce/=cf;
                        }
                        b[cf]=true;
                        cf=spf[ce];
                    }
                }
                if(bb){out.write("pairwise coprime");}
                else if(gg==1) out.write("setwise coprime");
                else out.write("not coprime");
                out.flush();

    }
}

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

int main(){
  int n;
  cin >> n;
  vector<string> vec(n);
  string s = "Three";
  
  for(int i = 0;i < n;i++){
    cin >> vec.at(i);
  }
  for(int j = 0;j < n;j++){
    if(vec.at(j) == "Y"){
      s = "Four";
      break;
    }
  }
  cout << s << endl;
}

Measured memory_bytes: 256
program tax_increase
  implicit none
  integer :: a, b, x, n, i
  read(*,*) a, b
  n = 10*b
  do i = 0, 9
    x = n+i
    if (2*x/25 == a) then
      write(*,'(i0)') x
      stop
    end if
  end do
  write(*,'(i0)') -1
end program tax_increase

Measured memory_bytes: 768
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int K = sc.nextInt();

		if (K % 2 == 0){
			System.out.println(K/2 * K/2);
		} else {
			System.out.println(((K+1)/2) * (K/2));
		}
	}
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
int N,M,AB[55][2],CD[55][2];
int main(){
    cin>>N>>M;
    for(int i=0;i<N;i++)cin>>AB[i][0]>>AB[i][1];
    for(int i=0;i<M;i++)cin>>CD[i][0]>>CD[i][1];
    for(int i=0;i<N;i++){
        int x=AB[i][0],y=AB[i][1],z=1e9,w=-1;
        for(int j=0;j<M;j++){
            int zz=abs(x-CD[j][0])+abs(y-CD[j][1]);
            if(zz<z){
                z=zz;
                w=j;
            }
        }
        cout<<w+1<<endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());
#define PAU system("pause")

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vb> vvb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 28);
const double PI = acos(-1);

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	vi V(3);
	REP(i, 3)cin >> V[i];
	so(V);
	cout << V[2] * 10 + V[1] + V[0] << endl;
	PAU;
	return 0;
}


Measured memory_bytes: 892
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.*;

public class Main {
    private static final int MOD = (int) Math.pow(10, 9);

    public static void main(String[] args) {
        FastReader sc = new FastReader();
        long a = sc.nextLong();
        long b = sc.nextLong();

        long g = gcd(a, b);


            System.out.println((a * b) / g);


        System.exit(0);
    }

    static private long gcd(long m, long n) {
        if (m < n) { return gcd(n, m); }
        if (m % n == 0) { return n; }
        return gcd(n, m%n);
    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException  e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

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

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

        String nextLine() {
            String str = "";
            try{
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 21204
#include <bits/stdc++.h>
#define rep(var,cnt) for(int (var)=0; (var)<(int)(cnt); ++(var))
#define Rep(var,init,cnt) for(int (var)=(init); (var)<(cnt); ++(var))
#define ran(var,vec) for(auto &(var):(vec))
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define SORT(v) sort(all(v))
#define RSORT(v) sort(rall(v))
#define SUM(v) accumulate(all(v),0)
#define tget(tp,idx) get<idx>(tp)
#define TF(flag) (flag)?1:0
using namespace std;

using ll = long long;
using ull = unsigned long long;
using pi = pair<int,int>;
using pl = pair<ll,ll>;
using ti = tuple<int,int,int>;
using tl = tuple<ll,ll,ll>;

template<typename T>
using vec = vector<T>;
template<typename T>
using mat = vector<vec<T>>;
template<typename T>
using cub = vector<mat<T>>;
template<typename T>
using val = valarray<T>;

template<typename T>
using pq = priority_queue<T>;
template<typename T>
using rpq = priority_queue<T,vec<T>,greater<T>>;

template<typename T1,typename T2>
ostream &operator<<(ostream &os, const pair<T1,T2> &p){
  os<<"P("<<p.first<<", "<<p.second<<") ";
  return os;
}

template<typename T1,typename T2>
istream &operator>>(istream &is, pair<T1,T2> &p){
  is>>p.first>>p.second;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  cout<<"V{";
  for(int i=0; i<(int)v.size(); ++i){
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  cout<<"}";
  return os;
}

template<typename T>
istream &operator>>(istream &is, vector<T> &v){
  for(T &in:v) is>>in;
  return is;
}

template<typename T>
ostream &operator<<(ostream &os, const valarray<T> &v){
  cout<<"V{";
  for(int i=0; i<(int)v.size(); ++i){
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  cout<<"}";
  return os;
}

template<typename T>
istream &operator>>(istream &is, valarray<T> &v){
  for(T &in:v) is>>in;
  return is;
}

// Usual Template End ================================================

// Template End ======================================================

constexpr int MOD=1e9+7;

int main(void){
  string a,b,c; cin>>a>>b>>c;
  if(a[a.size()-1]==b[0]&&b[b.size()-1]==c[0]) cout<<"YES"<<endl;
  else cout<<"NO"<<endl;
}













Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
const long long INF = 1LL << 60;
const int MOD = 1000000007;
signed main(void){
    int s; cin>>s;
    int x1=0,y1=0,x2=0,y2 =0, x3=0,y3=0;
    if(s<=1000000000) {cout<<x1<<' '<<y1<<' '<<s<<' '<<y2<<' '<<x3<<' '<<1<<endl; return 0;}
    x1 = 1000000000;
    x2 = 1;
    for(int y2 = 1;y2<=1000000000;y2++){
        if(y2*x1>=s){
            y1 = abs(s - y2*x1);
            printf("0 0 %lld %lld %lld %lld", x1, y1, x2 , y2); return 0;
        }
    }
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <cmath>
#include <iomanip>

using ll = long long int;
using P = std::pair<int, ll>;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int a[123],b[123],dv[123],d[123],p[123],cnt[123];
std::vector<int> g[123];
std::queue<int> que;

P bfs(void){
	int u,v,j,i,m=0;
	ll ret = 1ll;
	std::fill(cnt,cnt+123,0);
	while(!que.empty()){
		u = que.front();
		que.pop(); i = 0;
		m = std::max(m,d[u]);
		for(j=(g[u].l_ength()-1); j>=0; --j){
			v = g[u][j];
			if(v==p[u]){
				continue;
			}
			p[v] = u;
			d[v] = d[u] + 1; ++i;
			que.push(v);
		}
		cnt[d[u]] = std::max(cnt[d[u]],i);
	}
	for(i=0; i<m; ++i){
		ret *= cnt[i];
	}
	return P(m+1,ret);
}

int main(void){
	int n,i,j,u,v;
	P tmp,ans=P(INF,INFLL);
	scanf("%d",&n);
	for(i=1; i<n; ++i){
		scanf("%d%d",&a[i],&b[i]);
		--a[i]; --b[i];
		g[a[i]].push_back(b[i]);
		g[b[i]].push_back(a[i]);
		++dv[a[i]]; ++dv[b[i]];
	}
	for(i=0; i<n; ++i){
		p[i] = n; d[i] = 0;
		que.push(i);
		tmp = bfs();
		if(dv[i]==1){
			++tmp.second;
		}
		ans = std::min(ans,tmp);
	}
	for(i=1; i<n; ++i){
		p[a[i]] = b[i]; p[b[i]] = a[i];
		d[a[i]] = 0; d[b[i]] = 0;
		que.push(a[i]); que.push(b[i]);
		tmp = bfs();
		tmp.second *= 2;
		ans = std::min(ans,tmp);
	}
	printf("%d %lld\n",ans.first,ans.second);
	return 0;
}


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

int main(){
    ll A,B,M;
    cin >> A >> B >>M;
    vector<ll> a(A),b(B),c(M),d(M),e(M);
    ll mina=1e11, minb=1e11;
    rep(i,A){
        cin >> a[i];
        mina = min(mina,a[i]);
    }
    rep(i,B){
        cin >> b[i];
        minb = min(minb,b[i]);
    }
    rep(i,M){
        cin >> c[i] >> d[i] >> e[i];
        c[i]--;
        d[i]--;
    }
    ll mind = 1e12;
    rep(i,M){
        mind = min(mind, a[c[i]] + b[d[i]] - e[i]);
    }

    cout << min(mina+minb,mind) << endl;
}


Measured memory_bytes: 4224
#include <iostream>
#include <vector>
#include <algorithm>
#include <deque>
#include <string>
#include <cmath>

using namespace std;

using s64 = long long int;

int N, M;

// sw[i][j] = true => i番目の電球はsw[j]に反応する
bool sw[10][10];
std::vector< int > p;

bool is_ok(int state){
    int b[10] = {};

    for(int i=0;i<N;i++){
        if(state & (1 << i)){
            for(int j=0;j<M;j++){
                if(sw[j][i])
                    b[j]++;
            }
        }
    }

    for(int i=0;i<M;i++){
        // cout << "b[" << i << "] : " << b[i];
        // cout << " p[" << i << "] : " << p[i] << endl;
        if(b[i] % 2 != p[i])
            return false;
    }

    return true;
}

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

    for(int m=0;m<M;m++){
        int k;
        cin >> k;
        for(int i=0;i<k;i++){
            int tmp;
            cin >> tmp;
            tmp--;
            //cout << "sw[" << m << "][" << tmp << "] = true;" << endl;;
            sw[m][tmp] = true;
        }
    }

    for(int m=0;m<M;m++){
        int pp;
        cin >> pp;
        p.push_back(pp);
    }

    // for(int m=0;m<M;m++){
    //     for(int n=0;n<N;n++){
    //         cout << sw[m][n] << " ";
    //     }
    //     cout << endl;
    // }

    int n = static_cast<int>(pow(2, N));

    int ans = 0;

    for(int i=0;i<n;i++){
        bool ok = is_ok(i);
        //cout << i << " :" << ok << endl;
        if(ok)
            ans++;
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 256
#include <cstdio>
#define MAXN 100005 
int a[MAXN];
int main() {
	int n, cnt = 1, flag = 1, now;
	scanf("%d", &n);
	for(int i = 1; i <= n; i++) 
		scanf("%d", &a[i]);
	now = a[1];
	while(now != 2) {
		now = a[now];
		cnt++;
		if(cnt > n) {
			flag = 0;
			break;
		}
	}
	if(!flag) cnt = -1;
	printf("%d\n", cnt);
	return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
int main()
{
    int i,j,l,n,x,y,tmp=0,c=0;
    scanf("%d",&n);
    int p[n];
    for(i=1;i<=n;i++)
    {
        scanf("%d",&p[i]);
    }
    for(i=1;i<=n;i++)
    {
        if(p[i]!=i)
        {
            x=p[i];
            break;
            }
    }
    for(j=i+1;j<=n;j++)
    {
        if(p[j]!=j)
        {
            y=p[j];
            break;
            }
    }
    tmp=p[i];
    p[i]=p[j];
    p[j]=tmp;
    for(l=1;l<=n;l++)
    {
        if(p[l]==l)
            {
            c++;
        }
    }
    if(c==n)
        {
        printf("YES\n");
    }
    else
        printf("NO\n");

    return 0;
}

Measured memory_bytes: 1656
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ll long long
#define P pair<ll,ll>
#define all(v) (v).begin(),(v).end()

const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);


int main(void)
{
    ll a,b,k; cin>>a>>b>>k;
    rep(i,k){
        if(i%2){
            if(b%2) b--;
            a += b/2;
            b/=2;
        }else{
            if(a%2) a--;
            b += a/2;
            a/=2;
        }
    }
    cout << a << " " << b << endl;
    return 0;
}

Measured memory_bytes: 3572
#include<iostream>
#include<string>
using namespace std;
int main(){
    string str1;
    string str2;
    string b;
    int count=0,a;
    cin>>str1;
    while(true){
        b="";
        cin>>str2;
        a=str2.size();
        if(str2=="END_OF_TEXT") break;
        for(int i=0;i<a;i++){
            b+=tolower(str2[i]);
        }
        if(str1==b) count+=1;
    }cout<<count<<endl;
    return 0;
}


Measured memory_bytes: 3188
#include<stdio.h>

static const int MAX = 500;
static const int INFTY=(1<<21);

int main( ){
  int i,j,n,u,adj,k;
  int G[MAX][MAX];
  int d[MAX],p[MAX],v[MAX];
  int min,sum;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      scanf("%d",&k);
      G[i][j] = (k ==-1)?INFTY:k;
    }
  }

  for(i=0;i<n;i++){
    d[i] = INFTY;
    p[i] = -1;
    v[i] = 0;
  }
  d[0] = 0;

  while(1){
    min = INFTY;
    u = -1;
    for(i=0;i<n;i++){
      if(min>d[i]&&!v[i]){
	u=i;
	min=d[i];
      }
    }
    if(u==-1)break;
    v[u]=1;
    for(adj=0;adj < n;adj++){
      if(!v[adj] && G[u][adj]!=INFTY){
	if(d[adj]>G[u][adj]){
	  d[adj]=G[u][adj];
	  p[adj]=u;
	}
      }
    }
  }
  sum=0;
  for(i=0;i<n;i++){
    if(p[i]!=-1)sum+=G[i][p[i]];
  }
  printf("%d\n",sum);
  return 0;
}



Measured memory_bytes: 2040
#include <bits/stdc++.h>
using namespace std;
#define MAX 100000
typedef long long llong;

int n, k;
llong T[MAX];

int check(llong P)
{
    int i=0;
    for (int j=0; j < k; ++j) {
        llong s=0;
        while (s + T[i] <= P) {
            s += T[i];
            i++;
            if (i == n) return n;
        }
    }
    return i;
}

int solve(void)
{
    llong left = 0;
    llong right = 100000 * 10000;
    llong mid;
    while (right - left > 1) {
        mid = (left + right) / 2;
        int v = check(mid);
        if (v >= n) right = mid;
        else left = mid;
    }
    return right;
}

main()
{
    cin >> n >> k;
    for (int i = 0; i < n; i++) cin >> T[i];
    llong ans = solve();
    cout << ans << endl;
}



Measured memory_bytes: 3896
#include<bits/stdc++.h>
#define lln long long int
#define llu unsigned lln
#define sc(n) scanf("%d",&n);
#define scl(n) scanf("%lld",&n);
#define scd(n) scanf("%lf",&n);
#define pf(res) printf("%d\n",res);
#define pfl(res) printf("%lld\n",res);
#define pfd(res) printf("%lf\n",res);
#define maxii 100005
using namespace std;
typedef pair<int,int> pii;
typedef pair<lln,lln> pll;
typedef vector<int> vi;
typedef vector<lln> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;


int arr[maxii];
int arr2[maxii];
int gcd(int a,int b)
{
    if(b==0){
      return a;
     }
    return gcd(b,a%b);
}
int lcm(int a,int b)
{
    int res=(a*b)/gcd(a,b);
    return res;
}
int po(int a,int b)
{
    int res=1;
    while(b)
    {
        if(b%2!=0)
        {
            res*=a;
            b--;
        }
        else
        {
            a*=a;
            b/=2;
        }
    }
    return res;
}

lln modMul(lln  a, lln b,lln mod){
    lln ans = 0;
    a = a % mod;
    while (b > 0){
        if ( b % 2 )ans = (ans%mod+ a%mod) % mod;
        a = (a%mod * 2%mod) % mod;
        b /= 2;
    }
    return ans % mod;
}
lln powerMod(lln a,lln b,lln mod){
	if(b==0)return 1LL%mod;
	lln x=powerMod( a,b/2,mod );
	x = ( x%mod * x%mod ) % mod;
	if( b%2==1 )x = ( x%mod * a%mod ) % mod;
	return x%mod;
}

int main()
{
   string a,b,c;
   cin>>a>>b>>c;
   a[0]=a[0]-32;
   b[0]=b[0]-32;
   c[0]=c[0]-32;
   cout<<a[0];
   cout<<b[0];
   cout<<c[0];

}






Measured memory_bytes: 3604
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"

using namespace std;

const long long int MOD = 1000000007;

long long int N, M, K, H, W, L, R;

void sw(vector<int>& v, int l, int r) {
	for (int i = l, j = r; i < j; i++, j--) {
		swap(v[i], v[j]);
	}
	return;
}

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

	cin >> N >> M >> K;
	if (N > M*K) {
		cout << -1 << endl;
		return 0;
	}
	vector<int>v(N + 1);
	for (int i = 1; i <= N; i++) {
		v[i] = i;
	}
	sw(v, 1, K);
	M--;
	int index = K + 1;
	if (M > N - K) {
		cout << -1 << endl;
		return 0;
	}
	while (M) {
		int amari = N - index + 1;
		int num = min(K, amari - (M - 1));
		sw(v, index, index + num - 1);
		index += num;
		M--;
	}
	for (auto i : v) {
		if (i) {
			cout << i << " ";
		}
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define int long long
#define ll long long
#define INF LLONG_MAX/3
#define eps LDBL_EPSILON
#define moder 1000000007
#define pie 3.141592653589793238462643383279
#define rep(i,n) for(int i=0;i<n;i++)
#define P std::pair<int,int>
#define prique priority_queue<int,vector<int>,greater<int>>
using namespace std;
int n;
double p[3010];
double dp[3010][3010];
signed main(){
	cin>>n;
	rep(i,n)cin>>p[i];
	rep(i,n){
		rep(j,i+2){
			if(!i){
				dp[i][0]=1-p[i];
				dp[i][1]=p[i];
			}
			else if(!j){
				dp[i][j]=dp[i-1][j]*(1-p[i]);
			}
			else dp[i][j]=dp[i-1][j]*(1-p[i])+dp[i-1][j-1]*p[i];
		}
	}
	double ans=0;
	for(int i=(n+1)/2;i<=n;i++){
		ans+=dp[n-1][i];
	}
	printf("%.12lf\n",ans);
    return 0;
}

Measured memory_bytes: 69120
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <math.h>
using namespace std;
typedef long long ll;

int main() {
  ll N, K;
  cin >> N >> K;
  cout << min(N % K, abs(N % K - K)) << endl;
  return 0;
}

Measured memory_bytes: 256