akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 

ll n,cnt,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};
ll rui[ohara];
ll tate[ohara];
deque<ll> ans;

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>n>>k;
    if(n==0){
        if(k==0)Cout("0 0");
        else Cout(-1);
    }
    else if(n==1){
        if(k==0)Cout("0 0 1 1");
        else Cout(-1);
    }
    else{
    cnt=2;
    rui[0]=1;
    rrep(i,1,46){
        rui[i]=cnt;
        cnt*=2;
    }
    if(k==0){
        rep(i,rui[n]){
            if(i==rui[n]-1){
                cout<<i<<" "<<i<<"\n";
            }
            else cout<<i<<" "<<i<<" ";
        }
        return 0;
    }
    tmp=k;
    while(1){
        rrrep(i,45,0){
            if(rui[i]<=tmp){
                tmp-=rui[i];
                tate[i+1]++;
                break;
            }
        }
        if(tmp==0)break;
    }
    if(rui[n]<=k)Cout(-1);
    else{
        ans.push_back(0);
        ans.push_back(k);
        ll judge=0;
        rrep(i,1,rui[n]){
            if(i==k||i==0)continue;
            ans.push_front(i);
            ans.push_back(i);
            judge=(judge xor i);
        }
        ans.push_front(0);
        ans.push_back(k);
        if(judge==k){
            rep(i,Size(ans)){
                if(i==Size(ans)-1)Cout(ans[i]);
                else cout<<ans[i]<<" ";
            }
        }
        else{
            Cout(-1);
        }
    }
    }
    return 0;
}


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

using namespace std;

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

#define debug(a) cout << #a << ": " << a << endl
#define debuga1(a, l, r) fto(i, l, r) cout << a[i] << " "; cout << endl
#define fdto(i, r, l) for(int i = (r); i >= (l); --i)
#define fto(i, l, r) for(int i = (l); i <= (r); ++i)
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define sz(a) (int)a.size()

const double PI = acos(-1.0);

double fRand(double fMin, double fMax)
{
    double f = (double)rand() / RAND_MAX;
    return fMin + f * (fMax - fMin);
}

template <class T>
T min(T a, T b, T c) {
    return min(a, min(b, c));
}

template <class T>
T max(T a, T b, T c) {
    return max(a, max(b, c));
}

const int MAXN = 1e5 + 5;
int n, a[MAXN];

int main () {
    scanf("%d", &n);
    fto(i, 0, n-1) scanf("%d", &a[i]);

    vector<pii> choice[2];
    fto(r, 0, 1) {
        map<int, int> m;
        for(int i = r; i < n; i += 2)
            ++m[a[i]];

        vector<pii> freq;
        for(pii p: m)
            freq.pb({p.ss, p.ff});
        freq.pb({0, MAXN + r});

        sort(freq.begin(), freq.end(), greater<pii>());
        fto(i, 0, 1)
            choice[r].pb(freq[i]);
    }

//    fto(r, 0, 1) {
//        debug(r);
//        for(pii p: choice[r])
//            printf("%d %d\n", p.ff, p.ss);
//    }

    int ans = n;
    fto(i, 0, 1)
        fto(j, 0, 1)
            if (choice[0][i].ss != choice[1][j].ss)
                ans = min(ans, n - choice[0][i].ff - choice[1][j].ff);

    printf("%d", ans);

    return 0;
}



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

int main() {
  int N,Y;
  cin >> N >> Y;
  Y/=1000;
  for(int i=0;i<N+1;i++){
    int M=N-i;
    for(int j=0;j<M+1;j++){
      if(Y==9*i+4*j+N){
        cout << i << " " << j << " " << N-i-j << endl;
        return 0;
      }
    }
  }
  cout << -1 << " " << -1 << " " << -1 << endl;
}


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

int main() {
	// your code goes here
	string s;
	cin>>s;
	int cn=0;
	for(int i=0;i<3;i++)
	{
		if(s[i]=='1')
		{
			cn++;
		}
	}
	cout<<cn;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<long long,long long> pll;
#define pb push_back
#define mp make_pair
#define rep(i,n) for(int i=0;i<(n);++i)
constexpr int mod=1000000007;
constexpr int mod1=998244353;
vector<int> dx={0,1,0,-1},dy={-1,0,1,0};
bool inside(int y,int x,int h,int w){
	if(y<h && y>=0 && x<w && x>=0) return true;
	return false;
}





int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int a,b;
	char c;cin >> a >> c >> b;
	if(c == '+') cout << a + b << endl;
	else cout << a - b << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int a[4];
	for(int i=0;i<4;i++)cin>>a[i];
	sort(a,a+4);
	if(a[0]==a[1]&&a[2]==a[3])cout<<"yes"<<endl;
	else cout<<"no"<<endl;
	return 0;
}

Measured memory_bytes: 3008
#include <cstdio>
#include <algorithm>

using namespace std;

typedef pair<char,int> pci;

int N;
pci A[100], B[100], C[100];

void print(pci X[]) {
  for (int i=0; i<N; i++) {
    if (i > 0) putchar(' ');
    printf("%c%d", X[i].first, X[i].second);
  }
  putchar('\n');
}

bool same(pci X[], pci Y[]) {
  for (int i=0; i<N; i++) {
    if (X[i].first != Y[i].first) return false;
  }
  return true;
}

void bubbleSort(pci X[]) {
  for (int i=0; i<N; i++) {
    bool loop = false;
    for (int j=N-1; j>i; j--) {
      if (X[j-1].second > X[j].second) {
        swap(X[j-1], X[j]);
        loop = true;
      }
    }
    if (!loop) break;
  }
}

void selectionSort(pci X[]) {
  for (int i=0; i<N; i++) {
    int minI = i;
    for (int j=i+1; j<N; j++) {
      if (X[j].second < X[minI].second) minI = j;
    }
    if (minI != i) swap(X[minI], X[i]);
  }
}

int main() {
  scanf("%d", &N);
  for (int i=0; i<N; i++) {
    getchar();
    A[i].first = getchar();
    A[i].second = getchar() - '0';
    B[i] = C[i] = A[i];
  }
  bubbleSort(B); print(B);
  puts("Stable");
  selectionSort(C); print(C);
  if (same(B, C)) puts("Stable");
  else puts("Not stable");
  return 0;
}

Measured memory_bytes: 2668
class Kruskal_UnionFind():
    def __init__(self, N):
        self.edges = []
        self.rank = [0] * N
        self.par = [i for i in range(N)]
        self.counter = [1] * N

    def add(self, u, v, d):
        """
        u = from, v = to, d = cost
        """
        self.edges.append([u, v, d])

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

    def unite(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x != y:
            z = self.counter[x] + self.counter[y]
            self.counter[x], self.counter[y] = z, z
        if self.rank[x] < self.rank[y]:
            self.par[x] = y
        else:
            self.par[y] = x
            if self.rank[x] == self.rank[y]:
                self.rank[x] += 1

    def size(self, x):
        x = self.find(x)
        return self.counter[x]

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

    def Kruskal(self):
        """
        return: 最小全域木のコストの和
        """
        edges = sorted(self.edges, key=lambda x: x[2])  # costでself.edgesをソートする
        res = 0
        for e in edges:
            if not self.same(e[0], e[1]):
                self.unite(e[0], e[1])
                res += e[2]
        return res
N = int(input())
G = Kruskal_UnionFind(N)
x = []
y = []
for i in range(N):
    xx,yy = map(int,input().split())
    x.append([i,xx])
    y.append([i,yy])

x = sorted(x,key=lambda t:t[1])
y = sorted(y,key=lambda t:t[1])

for i in range(N-1):
    G.add(x[i][0],x[i+1][0],abs(x[i+1][1] - x[i][1]))
    G.add(y[i][0],y[i+1][0],abs(y[i+1][1] - y[i][1]))

print(G.Kruskal())


Measured memory_bytes: 125856
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define REP(i,n) for(int i=0;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<29
#define LINF LLONG_MAX/3
#define DINF DBL_MAX/3
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define ALL(v) (v).begin(),(v).end()
#define all(v) ALL(v)
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
#define CININIT cin.tie(0),ios::sync_with_stdio(false)
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }

constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

void solve(int n,int m,int p,int a,int b){
    vi t(n);
    rep(i,n) cin>>t[i];
    vector<vector<int>> g(m,vi(m,INF));
    rep(i,p){
        int x,y,z;cin>>x>>y>>z;
        x--;
        y--;
        g[x][y]=z;
        g[y][x]=z;
    }
    sort(all(t));
    vector<vector<double>> d(m,vector<double>(1<<n,DINF));
    using P = pair<double,pair<int,int>>;                    // <distance , <node,used>>
    priority_queue<P,vector<P>,greater<P>> que;
    que.push(P(0,pii(a,0)));
    d[a][0] = 0;
    while(!que.empty()){
        auto p = que.top();que.pop();
        double dist = p.first;
        int v=p.second.first;
        int kip=p.second.second;

        if(dist>d[v][kip]) continue;

        for(int i=0;i<n;i++){       //i?????????????¬?????????¨
            if((kip>>i)&1) continue;
            int nkip = (kip | (1<<i));
            for(int j=0;j<m;j++){
                if(g[v][j]==INF) continue;
                double cost=dist+(g[v][j]/(double)t[i]);
                if(cost<d[j][nkip]){
                    d[j][nkip] = cost;
                    que.push(P(cost,pii(j,nkip)));
                }
            }
        }
    }

    double ans = DINF;
    rep(i,(1<<n)){
        ans = min(ans,d[b][i]);
    }
    if(abs(DINF-ans)<0.00001) cout << "Impossible" << endl;
    else printf("%.20lf\n",ans);
}

int main(){/*{{{*/
    int n,m,p,a,b;
    while(cin>>n>>m>>p>>a>>b){
        if(n==0 and m==0 and p==0 and a==0 and b==0) break;
        a--;
        b--;
        solve(n,m,p,a,b);
    }
}/*}}}*/

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

#define fr first
#define sc second
#define pb push_back
#define mp make_pair
#define for1(i, n) for (int i = 1; i <= n; ++i)
#define for0(i, n) for (int i = 0; i < n; ++i)
#define sz(x) ((int) (x).size())
#define all(x) (x).begin(), (x).end()

#define next qwerty1
#define left qwerty2
#define right qwerty3
#define y1 qwerty4
#define y0 qwerty5

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;







int main() {
	int a;
	string s;
	cin >> a >> s;
	if (a >= 3200) cout << s;
	else cout << "red";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;
int solve( vector<vector<int> > &a,int i,int j){
    if (a.at(i).at(j) > -1)
    {
        return a.at(i).at(j) ;
    }else
    {
        if (i>0 && j>0)
        {
            /* code */
            a.at(i).at(j) = a.at(i-1).at(j) + a.at(i).at(j-1) ;
        }else if (i==0)
        {
            /* code */
            a.at(i).at(j) = a.at(i).at(j-1) ;
        }else
        {
            a.at(i).at(j) = a.at(i-1).at(j) ;
        }
        
        
        
        return a.at(i).at(j) ;
    }
    
        
}

int main(){
    //どうせ(0,0)が来れば終わるので終了時はbreakする
    while(1){
    int a,b ;
    cin >> a >> b ;
    if (a == 0 && b == 0)
    {
        /* code */
        break ;
    }
    
    int q ;
    cin >> q ;
    vector< vector<int> > road(a,vector<int>(b,-1)) ;
    int s1 ,s2 ;
    for (size_t i = 0; i < q; i++)
    {
        /* code */
        cin >> s1 >> s2 ;
        road.at(s1-1).at(s2-1) = 0 ;
    }
    road.at(0).at(0) = 1 ;
    for (size_t i = 0; i < a; i++)
    {
        for (size_t j = 0; j < b; j++)
        {
            road.at(i).at(j) = solve(road,i,j) ;
            //cout << road.at(i).at(j) <<endl;
        }
        
    }
    int ans = road.at(a-1).at(b-1) ;
    cout << ans << endl ;
    }
}


Measured memory_bytes: 3024
<?php
fscanf(STDIN, '%d', $N);
$line = trim(fgets(STDIN));
$arr = explode(' ', $line);

$bubbleArr = BubbleSort($arr,$N);
echo(implode(' ',$bubbleArr).PHP_EOL."Stable".PHP_EOL);
$selectionArr = SelectionSort($arr,$N);
echo implode(" ",$selectionArr) . PHP_EOL;
if(isStable($bubbleArr, $selectionArr)==true){
    echo("Stable".PHP_EOL);
} else {
    echo("Not stable".PHP_EOL);
}

function BubbleSort($arr,$N)
{
    for ($i = 0; $i<$N; ++$i) {
        for ($j = $N-1; $j>$i; --$j) {
            if ($arr[$j][1] < $arr[$j-1][1]) {
                $tmp = $arr[$j];
                $arr[$j] = $arr[$j - 1];
                $arr[$j - 1] = $tmp;
            }
        }
    }
 
    return $arr;
}

function SelectionSort($arr, $N){
    for ($i=0; $i<$N; ++$i){
        $mini = $i;
        for ($j=$i; $j<$N; ++$j){
            if ($arr[$j][1] < $arr[$mini][1]){
                $mini = $j;
            }
        }
        if($mini!=$i){
            $tmp = $arr[$i];
            $arr[$i] = $arr[$mini];
            $arr[$mini] = $tmp;
        }
    }
    return $arr;
}

function isStable($bubbleArr, $selectionArr){
    $result = array_diff_assoc($bubbleArr, $selectionArr);
    if(count($result)==0){
        return true;
    } else {
        return false;
    }
}


Measured memory_bytes: 9344
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)

using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF = 100000000;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int main(){
  ll x,y;
  cin >> x >>  y;
  int res=0;
  //if(x<=y) cout <<"AAAAA" << endl;
  while(x<=y){
    x *= (ll)2;
    //cout << x << endl;
    res++;
  }
  cout << res << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
long long a[3][100001];
int main()
{
	int n;
	long long total = 0;
	scanf("%d", &n);
	for(int i = 0; i < 3; ++i)
	{
		for(int j = 0; j < n; ++j)
		{
			scanf("%lld", &a[i][j]);
		}
		sort(a[i], a[i] + n);
	}
	for(int i = 0; i < n; ++i)
	{
		total += (distance(a[0], lower_bound(a[0], a[0] + n, a[1][i]))) * distance(upper_bound(a[2], a[2] + n, a[1][i]), a[2] + n);
	}
	printf("%lld\n", total);
}

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

int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if(a>b)swap(a,b);
    if(a>c)swap(a,c);
    if(b>c)swap(b,c);
    cout<<a+b;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

void judge_right_triangle(int a, int b, int c);

int main(void)
{
    int number;
    scanf("%d", &number);
    for (int i = 0; i < number; ++i) {
        int a;
        int b;
        int c;
        scanf("%d %d %d", &a, &b, &c);
        judge_right_triangle(a, b, c);
    }
    return 0;
}
void judge_right_triangle(int a, int b, int c)
{
    if (a * a + b * b == c * c) {
        printf("YES\n");
        return;
    }
    if (b * b + c * c == a * a) {
        printf("YES\n");
        return;
    }
    if (c * c + a * a == b * b) {
        printf("YES\n");
        return;
    }
    printf("NO\n");
    return;
}

Measured memory_bytes: 1008
def read_line(*types): return [f(a) for a, f in zip(input().split(), types)]

a, b, c, d = read_line(int, int, int, int)

if (abs(b - a) <= d and abs(c - b) <= d) or abs(c - a) <= d:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define F first
#define S second

using namespace std;
typedef pair<int,int> P;

const int MOD=1000000007;
int INF=100100100100100;

int a[100010];
int neg;
int ans=0;
vector<P> res;
signed main(){
  int n;cin>>n;
  rep(i,n)cin>>a[i];
  sort(a,a+n);
  
  if(a[0]>0){
    for(int i=1;i<=n-2;i++){
      res.pb(P(a[0],a[i]));
      a[0]-=a[i];
    }
    res.pb(P(a[n-1],a[0]));
    ans=a[n-1]-a[0];
  }
  
  else if(a[n-1]<0){
    for(int i=n-2;i>=0;i--){
      res.pb(P(a[n-1],a[i]));
      a[n-1]-=a[i];
    }
    ans=a[n-1];
  }
  
  else{
    int ima=n-2;
    while(a[ima]>0){
      res.pb(P(a[0],a[ima]));
      a[0]-=a[ima];
      ima--;
    }
    rep(i,ima+1){
      res.pb(P(a[n-1],a[i]));
      a[n-1]-=a[i];
    }
    ans=a[n-1];
  }
  cout<<ans<<endl;
  rep(i,n-1){
    cout<<res[i].F<<" "<<res[i].S<<endl;
  }
  return 0;
}

Measured memory_bytes: 4336
#include <algorithm>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 2147483647 / 2;
const long long int llINF = 9223372036854775807 / 2;

using namespace std;
using ll = long long int;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;

typedef pair<ll, ll> pll;
bool paircomp(const pll &a, const pll &b) {
  if (a.first == b.first)
    return a.second < b.second;
  return a.first < b.first;
}

#define REP(i, n) for (ll i = 0; i < (n); i++)
#define RREP(i, n) for (ll i = (n)-1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end())
#define MIN(vec) *std::min_element(vec.begin(), vec.end())
#define ARGMAX(vec)                                                            \
  std::distance(vec.begin(), std::max_element(vec.begin(), vec.end()))
#define ARGMIN(vec)                                                            \
  std::distance(vec.begin(), std::min_element(vec.begin(), vec.end()))
#define REV(T) greater<T>()
#define PQ(T) priority_queue<T, vector<T>, greater<T>>
#define VVL(a, b, c) vector<vector<ll>>(a, vector<ll>(b, c))
#define VVVL(a, b, c, d)                                                       \
  vector<vector<vector<ll>>>(a, vector<vector<ll>>(b, vector<ll>(c, d)))
#define SP(a) setprecision(a)
#define SQRT(a) sqrt((long double)(a))
#define DPOW(a, b) pow((long double)(a), (long double)(b))
#define UNIQUE(vec)                                                            \
  do {                                                                         \
    sort(ALL((vec)));                                                          \
    (vec).erase(std::unique(ALL((vec))), (vec).end());                         \
  } while (0)

ll POW(ll n, ll m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = POW(n, m / 2);
    return (tmp * tmp);
  } else {
    return (n * POW(n, m - 1));
  }
}

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

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll N;
  cin >> N;
  vector<pair<long double, pll>> p(N);
  REP(i, N) {
    ll x, y;
    cin >> x >> y;
    p[i] = make_pair(atan2(y, x), make_pair(x, y));
  }
  sort(ALL(p));
  ll ans = 0;
  REP(i, N) {
    ll x = 0, y = 0;
    REP(j, N) {
      x += p[(i + j) % N].second.first;
      y += p[(i + j) % N].second.second;
      ans = max(ans, (x * x) + (y * y));
    }
  }
  // cout << atan2(10, -10) << endl;
  cout << SP(30) << sqrt((long double)ans) << endl;

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,m,w;
	cin>>n;
	vector<int> s(n);
	for (int i=0; n>i; i++){
		cin>>s.at(i);
		s.at(i)--;
	}
	m=s.at(0);
	w=1;
	for(;n>=w;){
		if(m==1){
			break;
		}
		if(w==n){
			w=-1;
			break;
		}
		m=s.at(m);
		w++;
	}
	cout<<w<<endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
char s[10];
int main(){
	int ans=0;
	for(int i=0;i<3;i++){
		s[i]=getchar();
		if(s[i]=='A')ans++;
		else ans--;
	}
	if(ans==3||ans==-3)cout<<"No";
	else cout<<"Yes";
	return 0;
}



Measured memory_bytes: 256
import sys
import itertools
# import numpy as np
import time
import math
 
sys.setrecursionlimit(10 ** 7)
 
from collections import defaultdict
 
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
 
from functools import reduce
# from math import *
from fractions import *
H, W = map(int, readline().split())
S = [0 for i in range(H)]
for i in range(H):
    S[i] = readline().decode().strip()
 
from collections import deque
def bfs(start, H, W):
    INF = 10 ** 9
    visited = [False] * (H * W)
    q = deque([(start[0], start[1], 0)])
    max_d = 0
    while q:
        (i, j, d) = q.popleft()
        max_d = max(max_d, d)
        if visited[i * W + j]:
            continue
        visited[i * W + j] = True
        for dy in range(-1, 2):
            for dx in range(-1, 2):
                if dx * dy != 0:
                    continue
                if dx == dy:
                    continue
                if i + dy < 0 or i + dy >= H or j + dx < 0 or j + dx >= W:
                    continue
                if S[i + dy][j + dx] == '#':
                    continue
                if visited[(i + dy) * W + j + dx]:
                    continue
                q.append((i + dy, j + dx, d + 1))
    return max_d
 
ans = 0
for i in range(H):
    for j in range(W):
        if S[i][j] == '#':
            continue
        start = (i, j)
        ans = max(ans, bfs(start, H, W))
print(ans)

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

int main()
{
 int N,sum=0;
 cin>>N;
 int V[N],C[N];
 for(int i=0;i<N;i++)
  cin>>V[i];

  for(int i=0;i<N;i++)
  cin>>C[i];
 
for(int i=0;i<N;i++)
{
  if(V[i]-C[i]>0)
   sum=sum+(V[i]-C[i]);
}
 
 cout<<sum;

 return 0;

}

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

#define int long long

#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e18;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

const int MAX_N = 8;
const int MAX_M = 4;
int dp[MAX_M][1<<MAX_N];

signed main(){
    int n, a, b, c;
    cin >> n >> a >> b >> c;
    vi l(n);
    rep(i, n) cin >> l[i];
    vi v{a, b, c};
    rep(i, 1<<MAX_N) rep(j, MAX_M) dp[j][i] = INF;
    dp[0][0] = 0;
    const int maxMask = (1<<n)-1;
    rep(i, 3) {
        rep(mask, 1<<n) {
            int rest = maxMask - mask;
            for(int sub = rest; sub > 0; sub = (sub-1)&rest) {
                int nxt = mask|sub;
                int tmp = 0, cnt = 0;
                rep(j, n) if((1<<j) & sub) {
                    tmp += l[j];
                    cnt++;
                }
                dp[i+1][nxt] = min(dp[i+1][nxt], dp[i][mask] + (cnt-1)*10 + abs(tmp - v[i]));
            }
        }
    }
    int ans = INF;
    rep(i, 1<<n) ans = min(ans, dp[3][i]);
    cout << ans << endl;

    // rep(i, MAX_M) {
    //     rep(j, 1<<n) {
    //         printf("%3lld", (dp[i][j] == INF ? -1LL : dp[i][j]));
    //     }
    //     cout << endl;
    // }
    return 0;
}

Measured memory_bytes: 256
import sys

def solve():
    n = int(input())
    a = [int(i) for i in input().split()]

    v = a[0] if a[0] > 0 else 1
    ans1 = abs(a[0] - v)

    for i in range(1, n):
        if v * (v + a[i]) < 0:
            v += a[i]
            continue
        else:
            if v < 0:
                ans1 += abs(v + a[i] - 1)
                v = 1
            else:
                ans1 += abs(v + a[i] + 1)
                v = -1

    v = a[0] if a[0] < 0 else -1
    ans2 = abs(a[0] - v)

    for i in range(1, n):
        if v * (v + a[i]) < 0:
            v += a[i]
            continue
        else:
            if v < 0:
                ans2 += abs(v + a[i] - 1)
                v = 1
            else:
                ans2 += abs(v + a[i] + 1)
                v = -1

    ans = min(ans1, ans2)

    print(ans)

if __name__ == '__main__':
    solve()

Measured memory_bytes: 14468
#include<bits/stdc++.h>
using namespace std;
string st;
int s[300030],t[300030],i,j,k;
int main(){
	cin>>k>>st;
	while(i<k)
	  s[i]=(st[i]=='W')?1:0,
	  t[i]=1-s[i],i++;
	i=0;while(++i<k)s[i]+=s[i-1];
	i--;while(--i)t[i]+=t[i+1];t[0]+=t[1];
	j=0x3f3f3f,i=-1;while(++i<k)
	  j=min(j,s[i-1]+t[i+1]);
	printf("%d",j);
	return 0;
}

Measured memory_bytes: 2948
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
//二項係数の計算
int nCr(int A, int B) {
    ll ans = 1;
    for (int i = 0; i < B; i++) {
        ans *= A - i;
    }
    for (int i = 0; i < B; i++) {
        ans /= i + 1;
    }
    return ans;
}
int main() {
   int N;
   cin>>N;
   vector<int>A(N);
   vector<bool>C(N);
   vector<int>B(N-1);
   rep(i,N-1){
       cin>>B[i];
       if(C[i]==false){
           C[i]=true;
           A[i]=B[i];
       }
       if(C[i+1]==false){
           C[i+1]=true;
           A[i+1]=B[i];
       }
       if(B[i]<A[i]){
           A[i]=B[i];
       }
       if(B[i]<A[i+1]){
           A[i+1]=B[i];
       }
   }
   int ans=0;
   rep(i,N){
       ans+=A[i];
   }
   cout<<ans<<endl;
}

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	cout<<max({a*c,a*d,b*c,b*d})<<endl;
	return 0;
}


Measured memory_bytes: 3640
import collections
n,k=input().split()
n=int(n)
k=int(k)
z=[]
for i in range(k):
    d=int(input())
    x=list(input().split())
    for i in range(d):
        z.append(x[i])
c = collections.Counter(z)
y=n-(len(c))
print(y)

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

#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
#define pb push_back

using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;

const int inf = 1e9;

int main()
{

    //ifstream cin("input.txt");
    //ofstream cout("triangles.out");

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

    int n, m;
    cin >> n >> m;

    vector<vector<int> > edges(n, vector<int>(n, inf));
    vector<vector<int> > dist(n, vector<int>(n, inf));
    for (int i = 0; i < n; ++i) {
        dist[i][i] = 0;
    }

    while (m--) {
        int u, v, cost;
        cin >> u >> v >> cost;
        --u, --v;
        dist[u][v] = dist[v][u] = cost;
        edges[u][v] = edges[v][u] = cost;
    }

    for (int k = 0; k < n; ++k) {
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < n; ++j) {
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }

    int ans = 0;

    for (int u = 0; u < n; ++u) {
        for (int v = u + 1; v < n; ++v) {
            bool used = false;
            if (edges[u][v] == inf) {
                continue;
            }
            for (int x = 0; x < n; ++x) {
                for (int y = 0; y < n; ++y) {
                    if (dist[x][y] == dist[x][u] + edges[u][v] + dist[v][y]) {
                        used = true;
                        break;
                    }
                }
                if (used) {
                    break;
                }
            }
            if (!used) {
                ++ans;
            }
        }
    }

    cout << ans << "\n";

}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
constexpr ll mod = 1e9 + 7;
#define endl '\n'
 
int main() {
  ios::sync_with_stdio(0); cin.tie(0);
 
  ll n,m,X;
  cin >> n >> m >> X;
  vector<vector<ll>> A(n, vector<ll>(m));
  vector<ll> C(n);
  for (int i = 0; i < n; ++i) {
    cin >> C[i];
    for (auto& _b : A[i]) cin >> _b;
  }
  ll ans = INT_MAX;
  vector<ll> cur(m);
  for (int state = 0; state < (1 << n); ++state) {
    int v = state;
    ll cost = 0;
    fill(cur.begin(), cur.end(), 0);

    while (v) {
      int i = ffs(v)-1;
      for (int j = 0; j < m; ++j) cur[j] += A[i][j];
      cost += C[i];
      v &= v-1;
    }
    if (cost >= ans) continue;
    bool good = true;
    for (int j = 0; j < m; ++j) {
      if (cur[j] < X) {
        good = false;
        break;
      }
    }
    if (good) {
      ans = cost;
    }
  }
  if (ans == INT_MAX) ans = -1;
  cout << ans << endl;
}


Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
    string s, t;
    cin >> s >> t;
 
    int n = s.size();
    for(int i=0; i<n; ++i){
        if(s == t){
            cout << "Yes" << endl;
            return 0;
        }
        rotate(s.begin(), s.begin() + 1, s.end());
    }
 
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> //ライブラリ全読み込み
using namespace std; //std:を省略できる

int main(){
    int a,b,c;
    int count = 0;
    cin >> a >> b >> c;
    for(int x=a; x<=b;x++){
        if(c%x==0)count++;
    };
    cout<<count<<endl;
    return 0;
}


Measured memory_bytes: 3116
H = []
W = []
i = 0
while True:
  h, w = map(int, input().split())
  H.append(h)
  W.append(w)
  if H[i] == 0 and W[i] == 0:
    break
  i += 1

i = 0
while True:
  if H[i] == 0 and W[i] == 0:
    break
  for k in range(W[i]):
    print("#", end = "")
  print()
  for j in range(H[i] - 2):
    print("#", end = "")
    for k in range(W[i] - 2):
      print(".", end = "")
    print("#")
  for k in range(W[i]):
    print("#", end = "")
  print()
  print()
  i += 1

Measured memory_bytes: 8964
// https://atcoder.jp/contests/abcXXX/tasks/abcXXX_x

#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using pll = pair<ll, ll>;

static const ll INF = 1001001001;
static const ll LLINF = 1001001001001001001;

#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define RANGE(i, m, n) for(ll i = (m); i <= (n); ++i)

void debug_out() {}
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 1
#endif

int run(istream& in, ostream& out) {
    ll N;
    in >> N;
    vector<ll> v(N);
    unordered_map<ll, ll> map{};
    REP(i, N) {
        in >> v[i];
        map[v[i]]++;
        if(map[v[i]] > 1) {
            out << "NO" << endl;
            return 0;
        }
    }
    out << "YES" << endl;
    return 0;
}

int main() {
    return run(cin, cout);
}


Measured memory_bytes: 10056
#include <iostream>
#include <queue>
#include <algorithm>
#include <vector>
#define ll long long
using namespace std;

int main(void){
    int n, a[300005];
    long long sum_front=0, sum_back=0;
    
    vector<ll> sf, sb;
    priority_queue<ll, vector<ll>, greater<ll> > que_front;
    priority_queue<ll> que_back;
    
    cin >> n;

    for( int i = 0; i< 3 * n; i++ ){
        cin >> a[i];
        if(i < n){
            sum_front += a[i];
            que_front.push(a[i]);
        }else if( 2*n <= i ){
            sum_back += a[i];
            que_back.push(a[i]);
        }
    }

    sf.push_back(sum_front);
    sb.push_back(sum_back);
    
    for( int i = 0; i < n ; i++ ){
        que_front.push(a[i+n]);
        sum_front += a[i+n];
        sum_front -= que_front.top();
        que_front.pop();
        sf.push_back(sum_front);

        que_back.push(a[2*n-1-i]);
        sum_back += a[2*n-1-i];
        sum_back -= que_back.top();
        que_back.pop();
        sb.push_back(sum_back);
    }
    reverse(sb.begin(), sb.end());
    long long ans = sf[0] - sb[0];
    for( int i = 1; i <= n; i++ ){
        ans = max(ans, sf[i] - sb[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5364
///Bismillahir Rahmanir Rahim
#include<bits/stdc++.h>

#define                           int                         long long
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<int,int>
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);




using namespace std;

const int inf=1e18;
const int mod=1e9+7;
const int M=1002;
inline int bigmod(int B,int P){int R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}

int h,n;
int dp[10009];
vector<pi>vec;
int Magic(int baki)
{
    if(baki<=0)return 0;
    int &ret=dp[baki];
    if(ret!=(-1))return ret;
    ret=inf;
    f(i,0,n-1)
    {
        ret=min(ret,Magic(baki-vec[i].fi)+vec[i].si);
    }
    return ret;
}
 main()

{
    memset(dp,-1,sizeof dp);
    scanf("%lld%lld",&h,&n);
    f(i,1,n)
    {   int x,y;
        scanf("%lld%lld",&x,&y);
        vec.pb(mp(x,y));
    }
    int ses=Magic(h);
    printf("%lld\n",ses);

















    return 0;

}













Measured memory_bytes: 640
program poker;
var
	a, b : integer;
begin
	readln(a,b);
	if a=b then
		writeln('Draw')
	else if b=1 then
		writeln('Bob')
	else if a=1 then
		writeln ('Alice')
	else if a>b then
		writeln('Alice')
	else if b>a then
		writeln('Bob')
end.

Measured memory_bytes: 128
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, k int
	fmt.Scan(&n, &k)

	as := make([]int, n)
	for i := 0; i < n; i++ {
		tmp := -1
		fmt.Scan(&tmp)
		as[tmp-1]++
	}

	sort.Ints(as)

	indexOver0 := 0
	for i, a := range as {
		if a > 0 {
			indexOver0 = i
			break
		}
	}

	ans := 0
	for i := indexOver0; n-i > k; i++ {
		ans += as[i]
	}

	fmt.Println(ans)
}


Measured memory_bytes: 4992
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

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

#include <iostream>

using namespace std;
typedef long long int ll;
#define mod ll(1e9+7)

int main()
{
    int n,k;
    cin>>n>>k;
    long long int i,j,l,sum=0;
    for(i=k;i<=n+1;i++) {
        j=((i*(i-1))/2)%mod;
        l=n*i-j;
        sum=(sum+l-j+1)%mod;
    }
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 3636
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Deque;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		new Main().run();
	}

	private void run() {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			w = scanner.nextInt();
			h = scanner.nextInt();
			if ((w | h) == 0)
				break;
			ice = new int[h * w];
			hit = new int[h * w];
			dist = new int[h][w];
			m = new char[h][w];
			v = new boolean[h][w];
			for (int i = 0; i < h; i++)
				for (int j = 0; j < w; j++) {
					dist[i][j] = -1;
					m[i][j] = '#';
				}
			for (int i = 0; i < h; i++) {
				char[] c = scanner.next().toCharArray();
				for (int j = 0; j < w; j++) {
					m[i][j] = c[j];
					if (m[i][j] == 'S') {
						m[i][j] = '.';
						si = i;
						sj = j;
					} else if (m[i][j] == 'G') {
						m[i][j] = '.';
						gi = i;
						gj = j;
					}
				}

			}
			ice[0] = INF;
			id = new int[h][w];
			int ID = 1;
			for (int i = 0; i < h; i++)
				for (int j = 0; j < w; j++) {
					if (m[i][j] != 'X' || id[i][j] > 0)
						continue;
					mark(i, j, ID);
					if (ice[ID] == 1)
						m[i][j] = '#';
					ID++;
				}
			dist[gi][gj] = 0;
			Deque<int[]> deque = new ArrayDeque<int[]>();
			deque.offer(new int[] { gi, gj });
			while (!deque.isEmpty()) {
				int[] V = deque.poll();
				int pi = V[0];
				int pj = V[1];
				for (int[] mo : d) {
					int ni = pi + mo[0];
					int nj = pj + mo[1];
					if (!isOK(ni, nj))
						continue;
					if (m[ni][nj] != '#' && dist[ni][nj] == -1) {
						dist[ni][nj] = dist[pi][pj] + 1;
						deque.offer(new int[] { ni, nj });
					}
				}
			}
			res = 0;
			v[si][sj] = true;
			while (!f(si, sj, 0,-100)) {
				Arrays.fill(hit, 0);
				for (int i = 0; i < h; i++)
					for (int j = 0; j < w; j++)
						v[i][j] = false;
				v[si][sj] = true;
				res++;
			}
			System.out.println(res);
		}
	}

	private boolean f(int i, int j, int depth,int pre) {
		if (res < depth + dist[i][j])
			return false;
		if (gi == i && gj == j)
			return true;
		for (int r = 0;r<4;r++) {
			int ni = i + d[r][0];
			int nj = j + d[r][1];
			if (!isOK(ni, nj))
				continue;
			if(Math.max(r, pre)-Math.min(r,pre)==2)
				continue;
			if (!v[ni][nj] && m[ni][nj] != '#') {
				if (ice[id[ni][nj]] /2 > hit[id[ni][nj]] ) {
					hit[id[ni][nj]]++;
					v[ni][nj] = true;
					if (f(ni, nj, depth + 1,r))
						return true;
					v[ni][nj] = false;
					hit[id[ni][nj]]--;
				}
			}
		}
		return false;
	}

	private void mark(int i, int j, int x) {
		id[i][j] = x;
		ice[x]++;
		for (int[] mo : d) {
			int ni = i + mo[0];
			int nj = j + mo[1];
			if (!isOK(ni, nj))
				continue;
			if (m[ni][nj] == 'X' && id[ni][nj] == 0)
				mark(ni, nj, x);
		}
	}

	private boolean isOK(int i, int j) {
		if (0 <= i && i < h && 0 <= j && j < w)
			return true;
		return false;
	}

	int w, h, si, sj, gi, gj, INF = 1 << 29, res;
	int[][] d = { { -1, 0 }, { 0, 1 }, { 1, 0 }, { 0, -1 } };
	int[] ice, hit;
	int[][] id, dist;
	char[][] m;
	boolean[][] v;
}

Measured memory_bytes: 34496
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const int INF=1e9;

int main(){
    int n; cin>>n;
    int sum=0,t[n];
    for(int i=0;i<n;i++){
        cin>>t[i];
        sum+=t[i];
    }
    int m; cin>>m;
    for(int i=0;i<m;i++){
        int p; cin>>p;
        int x; cin>>x;
        cout<<sum-t[--p]+x<<endl;
    }
}


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

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

    map<char, long long> mp;
    mp['R'] = 0;
    mp['G'] = 0;
    mp['B'] = 0;
    for (int i = 0; i < N; ++i) ++mp[S[i]];
    long long ans = mp['R'] * mp['G'] * mp['B'];

    for (int i = 0; i < N; ++i) {
        for (int j = i + 1; j < N; ++j) {
            if (2*j-i >= 0 && 2*j-i < N && S[i] != S[j] && S[j] != S[2*j-i] && S[2*j-i] != S[i]) --ans;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 3628
import bisect,collections,copy,heapq,itertools,math,string
import sys
sys.setrecursionlimit(1000000)
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())
K = I()
S = S()

if len(S) <= K:
    print(S)
    sys.exit()
else:
    li = "".join([S[0:K],"..."])
    print(li)

Measured memory_bytes: 86460
#include<iostream>
using namespace std;
int main()
{
	// 入力
	int h,a;

	cin >> h >> a;
	int answer = 0;
	while (1) {
		++answer;
		h -= a;
		if (h <= 0) {
			break;
		}
	}
	cout << answer << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#define N 17
#define NN 34567
#define NNN 15671000
typedef long long ll;
template<typename T> inline void read(T &x) {
	x = 0; char c = getchar();
	while (!isdigit(c)) c = getchar();
	while (isdigit(c)) x = (x << 1) + (x << 3) + (c ^ 48), c = getchar();
}
using namespace std;
const int P = 1e9 + 7;
ll mi[N * N];
int n, m, All;
int e[N][N];
int ecnt[N][NN];//ecnt[i][s] : i -> s
inline void init() {
	mi[0] = 1;
	for (int i = 1; i <= m; ++i)	mi[i] = (mi[i - 1] << 1) % P;
	for (int i = 0; i < n; ++i) {
		for (int s = 0; s <= All; ++s) {
			for (int j = 0; j < n; ++j) if ((s >> j) & 1) {
				ecnt[i][s] += e[i][j];
			}
		}
	}
}
inline ll calc1(int s, int t) {
	ll res = 1;
	for (int i = 0; i < n; ++i) if ((s >> i) & 1) {
		res = 1ll * res * mi[ecnt[i][t]] % P;
	}
	return res;
}
inline ll calc2(int s, int t) {
	ll res = 1;
	for (int i = 0; i < n; ++i) if ((s >> i) & 1) {
		res = 1ll * res * (mi[ecnt[i][t]] - 1) % P;
	}
	return res;
}
int f[NNN];
inline void work() {
	f[0] = 1;
	for (int s = 1; s <= All; ++s) if ((s & 1) == ((s >> 1) & 1)) {
		for (int t = s; t; t = (t - 1) & s) {
			f[s] = (f[s] + 1ll * calc1(t, s ^ t) * calc2(s ^ t, t) % P * f[s ^ t] % P) % P;
		}
	}
	ll ans = (mi[m] - f[All]) % P;
	printf("%lld\n", (ans % P + P) % P);
}
int main() {
	read(n), read(m); All = (1 << n) - 1;
	for (int i = 1; i <= m; ++i) {
		int u, v; read(u), read(v);
		--u; --v;
		e[u][v] = 1;
	}
	init();
	work();
	return 0;
}


Measured memory_bytes: 5336
#include <iostream>
#include <algorithm>
#include <fstream>
#include <vector>
#include <deque>
#include <assert.h>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <stdio.h>
#include <string.h>
#include <utility>
#include <math.h>
#include <bitset>
#include <iomanip>
#include <complex>
#include <ios>
#include <iomanip>
using namespace std;
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define IDX(vec, element_iter) distance((vec).begin(), element_iter)
#define print(x) cout<<(x)<<'\n'
#define print_vec(v) rep(i,v.size()){if(i!=0)cout<<" ";cout<<v[i];}cout<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<'\n'
#define pb push_back
#define mp make_pair
#define MOD 1000000007 //10^9+7
#define fi first
#define sc second
using ll=long long;
using pi=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
using vstr=vector<string>;

void solve() {
    int n; cin >> n;
    vector<vi> to(n);
    int u,k,v;
    rep(i,n){        
        cin >> u >> k;
        u--;
        rep(j,k){
            cin >> v;
            to[u].pb(--v);
        }
        // DEBUG_VEC(to[u]);
    }

    vi dist(n,-1);
    dist[0] = 0;
    queue<int> que;
    que.push(0);
    while(!que.empty()){
        int root = que.front();
        que.pop();
        // DEBUG(root);
        // DEBUG_VEC(to[root]);
        for(auto leaf:to[root]){
            if(dist[leaf] != -1) continue;
            dist[leaf] = dist[root]+1;
            que.push(leaf);
        }
    }

    rep(i,n){
        cout << i+1 << " " << dist[i] << '\n';
    }
}
 
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
	cout<<fixed<<setprecision(20);
    //int q; cin >> q;
	//while (q--)
		solve();
    return 0;
}


Measured memory_bytes: 3148
import java.util.*;
public class Main{
  public static void main(String[] args) {
    Scanner sc=new Scanner(System.in);
    int n=sc.nextInt();
    int a=sc.nextInt();
    int b=sc.nextInt();

    if ((n*a)>b) {
      System.out.println(b);
    }else{
      System.out.println(n*a);
    }
  }
}


Measured memory_bytes: 23124
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())

const int MAX = 510000;
const int MOD = 1000000007;
struct Edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    Edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<Edge> >;



// 二部グラフ判定
vector<int> color;
bool dfs(const Graph &G, int v, int cur = 0) {
    color[v] = cur;
    for (auto next_v : G[v]) {
        //色確定ならスルー
        if(color[next_v.to] != -1) continue;
        // 隣接頂点の色を変えて、再帰的に探索 (一回でも false が返ってきたら false)
        if (!dfs(G, next_v.to , (cur - next_v.weight + 2) % 2)) return false;
    }
    return true;
}



int main() {
    // 頂点数と辺数
    int N; cin >> N;
    // グラフ
    Graph G(N);
    for (int i = 0; i < N - 1; ++i) {
        int from, to, weight;
        cin >> from >> to >> weight;
        from--; to--; weight%=2;
        G[from].push_back(Edge(to, weight));
        G[to].push_back(Edge(from, weight));
    }

    // 探索
    color.assign(N, -1);
    bool is_bipartite = true;
    for (int v = 0; v < N; ++v) {
        if (color[v] != -1) continue; // v が探索済みだったらスルー
        if (!dfs(G, v)) is_bipartite = false;
    }

    if(is_bipartite){
      rep(i,N){
        cout<<color[i]<<endl;
      }
    }
}


Measured memory_bytes: 8192
ls_blue = [input() for _ in range(int(input()))]
ls_red = [input() for _ in range(int(input()))]
set_all = set(ls_blue + ls_red)
dic_point = {}
for word in set_all:
    dic_point[word] = ls_blue.count(word) - ls_red.count(word)

max_point = max(dic_point.values())
if max_point < 0:
    print(0)
else:
    print(max_point)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "../../dump.hpp"
#else
#define dump(...)
#endif

#define int ll
#define rep(i, n) for (int i = 0, i##_cond = (n); i < i##_cond; ++i)
#define FOR(i, a, b) for (int i = (a), i##_cond = (b); i < i##_cond; ++i)
#define ROF(i, a, b)                                                           \
  for (int i = (a)-1, i##_cond = (b); i >= i##_cond; --i) // ROF(i,n,0)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend() // sortで降順
#define SUM(a) accumulate(all(a), int(0))
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;
constexpr ll inf = 1ll << 61;
constexpr ll mod = 1e9 + 7;
template <class T> bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T> T add(const T &a, const T &b) { return (a + b) % mod; }

signed main() {
  int x, y;
  cin >> x >> y;

  rep(i, x + 1) rep(j, x + 1) {
    if (i + j == x) {
      if (2 * i + 4 * j == y) {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
}

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

int c, r, g, b, n, x, y;

int main(){

	cin >> r >> g >> b >> n;

	for (int i = 0; i <= n / r; i++){
		x = n - (i * r);
		for (int j = 0; j <= x / g; j++){
			y = x - (j * g);
			if (y % b == 0) c++;
		}
	}

	cout << c << endl;

	return 0;
}

Measured memory_bytes: 256