akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.math.BigInteger;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    int[] height = new int[n];
    for (int i = 0; i < n; i++) {
      height[i] = sc.nextInt();
    }
    boolean[] isBadSpot = new boolean[n];
    for (int i = 0; i < m; i++) {
      int a = sc.nextInt();
      int b = sc.nextInt();
      if (height[a-1] < height[b-1]) {
        isBadSpot[a-1] = true;
      } else if (height[a-1] > height[b-1]) {
        isBadSpot[b-1] = true;
      } else {
        isBadSpot[a-1] = true;
        isBadSpot[b-1] = true;
      }
    }
    int ans = 0;
    for (boolean spot: isBadSpot) {
      if (!(spot)) ans++;
    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 59552
import numpy as np
N,D = map(int,input().split())

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

x = np.array(X)
print(sum([np.linalg.norm(x[i]-x[j]).is_integer() for i in range(N-1) for j in range(i+1,N)]))


Measured memory_bytes: 12484
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int n, x;
    scanf("%d", &n);
    
    for (int i=1; i<=n; i++) {
        x = i;
        if (x%3 == 0) {
            printf(" %d", i);
        }else{
            while (x!=0) {
                if(x%10 == 3){
                    printf(" %d", i);
                    break;//一つでも3を検出したら，この数字のチェックを終える
                }
                x/=10;
            }
        }
        
    }
    printf("\n");
    
    return 0;
}


Measured memory_bytes: 2100
#include<iostream>
using namespace std;
int main(int argc, const char * argv[]) {
    int A,B,C;
    cin>>A>>B>>C;
    if(A==B){
        cout<<C<<endl;
    }
    else if(A==C)
    {
        
    cout<<B<<endl;
    }
    else{
        cout<<A<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
function Main(input) {
input = input.split("\n");//行ごとに分解して配列にする。一行の時は"\n"を" "にして三行目を消そう

var a = input[0]
count = 0;

for(i=1; i< a; i++){

  for(j=1; j<a; j++){
  	if(i*j < a){
    	count++; 
    }else{
    	break; 
    }
  }
}
console.log(count);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));//おまじない

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

using i64 = int64_t;

#define rep(i, x, y) for (i64 i = i64(x), i##_max_for_repmacro = i64(y); i < i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf = 1.01e9;
const i64 inf64 = 2.01e18;
const double eps = 1e-9;

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

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>
bool chmin(T &a, const T &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

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

template<typename T, size_t size> void fill(T (&ary)[size], const T& val){
    fill_n((T*)ary, size, val);
}

void solve() {
    //const i64 mod = 1'000'000'007;

    i64 N;
    cin >> N;
    vector<long double> x(N),y(N);
    vector<char> d(N);
    rep(i,0,N) cin >> x[i] >> y[i] >> d[i];

    vector<pair<long double,long double>> intervals={make_pair(0,inf64)};

    random_device rnd;
    mt19937 mt(rnd());
    uniform_real_distribution<> rand(0, 4.1e8);
    i64 trial=20;
    while(intervals.size()<trial){
        auto l=rand(mt);
        auto r=rand(mt);
        if(l>r) swap(l,r);
        intervals.emplace_back(make_pair(l,r));
    }

    auto f=[&](long double t){
        long double xmin=inf64,xmax=-inf64,ymin=inf64,ymax=-inf64;
        rep(i,0,N){
            long double xx=x[i],yy=y[i];
            if(d[i]=='R') xx+=t;
            else if(d[i]=='L') xx-=t;
            else if(d[i]=='U') yy+=t;
            else yy-=t;
            chmin(xmin,xx);
            chmax(xmax,xx);
            chmin(ymin,yy);
            chmax(ymax,yy);
        }

        return (xmax-xmin)*(ymax-ymin);
    };

    auto ans=f(0);

    for(auto& p:intervals) {
        long double lb = p.first, ub = p.second;
        rep(i, 0, 200) {
            if(ub-lb<=1) break;
            auto a = (lb + lb + ub) / 3;
            auto b = (lb + ub + ub) / 3;
            if (f(a) > f(b)) {
                lb = a;
            } else {
                ub = b;
            }
        }
        i64 t=i64(lb);
        vector<long double> ts;
        rep(i,-3,4){
            auto s=t+0.5*i;
            if(s<0) continue;
            ts.emplace_back(s);
        }
        for(auto t:ts) chmin(ans,f(t));
    }

    cout << ans << endl;
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 3456
#include <bits/stdc++.h>
const int MAXN = 1e6 + 19;
int root, ind;
int son[MAXN][26], cnt[MAXN][26], vist[26];
void insert(int &node, char *str, int len){
	if(!node) node = ++ind;
//	std::printf("insert %c in %d\n", *str, node);
	if(len > 1)
		insert(son[node][*str - 'a'], str - 1, len - 1);
	vist[*str - 'a'] = 1;
	for(int i = 0; i < 26; ++i)
		if(vist[i])
			++cnt[node][i];
}
int query(int node, char *str, int len){
	if(!node) return 0;
	if(len == 1)
		return cnt[node][*str - 'a'];
	else return query(son[node][*str - 'a'], str - 1, len - 1);
}
int n;
char s[MAXN], *beg[MAXN], *end[MAXN];
int main(){
	std::scanf("%d", &n);
	end[0] = s;
	for(int i = 1; i <= n; ++i){
		beg[i] = end[i - 1];
		std::scanf("%s", beg[i]); int len = std::strlen(beg[i]);
		end[i] = beg[i] + len;
		std::memset(vist, 0, sizeof vist);
		insert(root, end[i] - 1, len);
	}
//	for(int i = 0; i < 26; ++i) std::printf("%c%d\n", 'a' + i, cnt[root][i]);
	long long ans = 0ll;
	for(int i = 1; i <= n; ++i){
//		std::printf("%d\n", query(root, end[i] - 1, end[i] - beg[i]));
		ans += query(root, end[i] - 1, end[i] - beg[i]);
	}
	std::printf("%lld\n", ans-n);
}

Measured memory_bytes: 234632
#include <bits/stdc++.h>
#define ALL(a)  (a).begin(),(a).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
template <typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template <typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
const int INT_INF = 1 << 30;
#define MOD 1000000007LL
#define endl "\n"

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  ll N, T;
  cin >> N >> T;
  vll A(N);
  ll mini = INF;
  map<ll, ll> ma;
  for(int i = 0; i < N; i++){
    cin >> A.at(i);
    chmin(mini, A.at(i));
    if(!ma.count(A.at(i) - mini)) ma[A.at(i) - mini] = 1LL;
    else ma[A.at(i) - mini]++;
  }
  auto ite = ma.end(); ite--;
  cout << ite -> second << endl;
}

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

int main() {
  int n;
  cin >> n;
  double a = n;
  if(n % 2 == 0) cout << 0.5000000000 << endl;
  else{
    cout << fixed << setprecision(10) << (a+1)/(2*a) << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <set>
using namespace std;
typedef long long int ll;

class UnionFind{
public:
	vector<int> par,num;

	int find(int v){
		return (par[v]==v)? v: (par[v]=find(par[v]));
	}
	explicit UnionFind(int N):par(N),num(N,1){
		iota(par.begin(),par.end(),0);
	}
	void unite(int u,int v){
		u=find(u),v=find(v);
		if(u==v)return ;
		if(num[u]<num[v])swap(u,v);
		num[u] += num[v];
		par[v] = u;
	}
	bool same(int u,int v){
		return find(u) == find(v);
	}
	bool ispar(int v){
		return v=find(v);
	}
	int size(int v){
		return num[find(v)];
	}
};

int main(){
	int n,m; cin >> n >> m;
	vector<int> v[m];
	for(int i=0;i<n;i++){
		int k; cin >> k;
		for(int j=0;j<k;j++){
			int l; cin >> l;
			v[l-1].push_back(i);
		}
	}
	UnionFind uf(n);
	for(int i=0;i<m;i++){
		for(int j=1;j<v[i].size();j++){
			uf.unite(v[i][0],v[i][j]);
		}
	}
	set<int> par;
	for(int i=0;i<n;i++){
		par.insert(uf.find(i));
	}
	if(par.size()==1){
		cout << "YES" << endl;
	}
	else{
		cout << "NO" << endl;
	}
}


Measured memory_bytes: 4608
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rrep(i, n) for(int i = 1; i <= (int)(n); i++)
#define drep(i, n) for(int i = (n)-1; i >= 0; i--)
#define ALL(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;

// Mod int
const int mod = 1000000007;
// const int mod = 998244353;
struct mint {
  ll x;
  mint():x(0){}
  mint(ll x):x((x%mod+mod)%mod){}
  // mint(ll x):x(x){}
  mint& fix() { x = (x%mod+mod)%mod; return *this;}
  mint operator-() const { return mint(0) - *this;}
  mint& operator+=(const mint& a){ if((x+=a.x)>=mod) x-=mod; return *this;}
  mint& operator-=(const mint& a){ if((x+=mod-a.x)>=mod) x-=mod; return *this;}
  mint& operator*=(const mint& a){ (x*=a.x)%=mod; return *this;}
  mint operator+(const mint& a)const{ return mint(*this) += a;}
  mint operator-(const mint& a)const{ return mint(*this) -= a;}
  mint operator*(const mint& a)const{ return mint(*this) *= a;}
  bool operator<(const mint& a)const{ return x < a.x;}
  bool operator==(const mint& a)const{ return x == a.x;}
};
istream& operator>>(istream&i,mint&a){i>>a.x;return i;}
ostream& operator<<(ostream&o,const mint&a){o<<a.x;return o;}
//



int main() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  rep(i, h) cin >> s[i];
  vvi cnt(h, vi(w));
  rep(i, h) {
    vi done(w);
    rep(j, w){
      if (s[i][j] == '#') continue;
      if (done[j]) continue;
      int l = 0;
      while (j+l < w) {
        if (s[i][j+l] == '#') break;
        ++l;
      }
      rep(k, l) {
        cnt[i][j+k] += l;
        done[j+k] = l;
      }
    }
  }
  rep(j, w) {
    vi done(h);
    rep(i, h) {
      if (s[i][j] == '#') continue;
      if (done[i]) continue;
      int l = 0;
      while (i+l < h) {
        if (s[i+l][j] == '#') break;
        ++l;
      }
      rep(k, l) {
        cnt[i+k][j] += l;
        done[i+k] = l;
      }
    }
  }
  int ans = 0;
  rep(i, h) rep(j, w) {
    ans = max(ans, cnt[i][j]-1);
  }
  cout << ans << endl;
}

Measured memory_bytes: 26492
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, n) for(int i=0; i<int(n); i++)
#define RNG(i, f, t) for(int i=int(f); i<=int(t); i++)
#define REV(i, f, t) for(int i=int(f); i>=int(t); --i)
#define ALL(v) (v).begin(), (v).end()
bool RELAXED = false;
template<int,typename T> struct MINMAX{ T val; MINMAX(T val) : val(val) {} };
template<typename T> MINMAX<1,T> MAX(T val) { return MINMAX<1,T>(val); };
template<typename T> MINMAX<2,T> MIN(T val) { return MINMAX<2,T>(val); };
template<typename T, typename U> inline T& operator|=(T &lhs, MINMAX<1,U> rhs) { return lhs = (rhs.val > lhs ? (RELAXED=true,rhs.val) : (RELAXED=false,lhs)); }
template<typename T, typename U> inline T& operator|=(T &lhs, MINMAX<2,U> rhs) { return lhs = (rhs.val < lhs ? (RELAXED=true,rhs.val) : (RELAXED=false,lhs)); }
template<typename T> inline vector<T> readVector(int n) { vector<T> vec(n); FOR(i,n) cin>>vec[i]; return vec; }
template<typename T> void EXIT(T answer) { cout<<answer<<endl; exit(0); }
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;
typedef signed long long int ll;

const int MAXB = 1<<20;
ll dp[MAXB+5];
ll score[MAXB+5];
int adj[20][20];

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

    int n; cin>>n;
    const int ALL = (1<<n)-1;
    FOR(i,n) FOR(j,n)
        cin>>adj[i][j];

    RNG(bm,1,ALL) {
        FOR(i,n) FOR(j,n)
            if((bm&(1<<i)) && (bm&(1<<j)))
                score[bm] += adj[i][j];
    }

    FOR(i,1<<n)
    REV(j,i,0) {
        j &= i;
        dp[i] |= MAX(dp[j] + score[i^j]);
    }

    cout<<dp[ALL]/2<<endl;

    return 0;
}



Measured memory_bytes: 2816
import java.util.Scanner;

class Main {
    public static void main(final String[] args) {
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int[] a = new int[n+1];
        int[] b = new int[n];
        for (int i = 0; i < n + 1; i++) {
            a[i] = scan.nextInt();
        }
        for (int i = 0; i < n; i++) {
            b[i] = scan.nextInt();
        }
        long ans = 0;
        for (int j = 0; j < n; j++) {
            int x = Math.min(a[j], b[j]);
            ans += x;
            a[j] -= x;
            b[j] -= x;
            int y = Math.min(a[j + 1], b[j]);
            ans += y;
            a[j + 1] -= y;
            b[j] -= y;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 84856
using System;
using System.Collections.Generic;

namespace abc162
{
    class Program
    {
        static void Main(string[] args)
        {
            var k = int.Parse(Console.ReadLine());
            var total = 0L;
            var dListTable = new Dictionary<int, List<int>>();
            var dTable = new Dictionary<int, Dictionary<int, int>>();
            for (var n = 1; n <= k; ++n)
            {
                dListTable.Add(n, new List<int>());
                dTable.Add(n, new Dictionary<int, int>());
                for (var i = 1; i <= n; ++i)
                {
                    if (n % i == 0)
                    {
                        dListTable[n].Add(i);
                        dTable[n].Add(i, 0);
                    }
                }
            }
            for (var a = 1; a <= k; ++a)
            {
                for (var b = 1; b <= k; ++b)
                {
                    for (var c = 1; c <= k; ++c)
                    {
                        total += GetGcd(dListTable[a], dTable[b], dTable[c]);
                    }
                }
            }
            Console.WriteLine(total);
        }

        private static int GetGcd(List<int> a, Dictionary<int, int> b, Dictionary<int, int> c)
        {
            for (var i = a.Count - 1; i >= 0; --i)
            {
                if (b.ContainsKey(a[i]) && c.ContainsKey(a[i]))
                {
                    return a[i];
                }
            }
            return 0;
        }
    }
}


Measured memory_bytes: 27976
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f

#include <iostream>
#include <cstdio>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
  
using namespace std;
  
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P> PP;
  
static const double EPS = 1e-8;
  
static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};

static const int FACT_MAX = 1500;

void multiply(int res[5001],int num){
  int carry = 0;
  for(int i=0;i<5001;i++){
    int sum = res[i] * num + carry;
    carry = sum / 10;
    res[i] = sum % 10;
  }
}

void add(int res[5001],int num){

  int tmp[5001];
  memset(tmp,0,sizeof(tmp));

  for(int i=0;i<5001;i++){
    tmp[i] = num % 10;
    num /= 10;
  }
  
  int carry = 0;
  for(int i=0;i<5001;i++){
    res[i] += tmp[i] + carry;
    carry = res[i] / 10;
    res[i] %= 10;
  }
}

void printNum(int res[5001]){
  bool flag = false;
  for(int i=5000;i>=0;i--){
    if(res[i] != 0){
      flag = true;
    }
    if(flag){
      printf("%d",res[i]);
    }
  }
  printf("\n");
}

int main(){

  int n;
  while(~scanf("%d",&n)){
    int res[5001];
    memset(res,0,sizeof(res));
    res[0] = 1;
    for(int i=1;i<=FACT_MAX;i++){
      multiply(res,i);
    }

    add(res,2);
    printNum(res);
    for(int i=0;i<n;i++){
      printf("%d\n",i+2);
    }
  }
}

Measured memory_bytes: 1236
import math
k,a,b=map(int,input().split())
s=1
if b-a<=2 or k-1<2:
    print(k+1)
else:
    ans=a
    k-=a-1
    if k%2==1:
        ans+=1
        k-=1
    ans+=(b-a)*(k//2)
    print(ans)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = pow(10, 9) + 7;
//const int MOD = 998244353;
//const int MOD = ;
int mod(int A, int M) {return (A % M + M) % M;}
const int INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
int myctoi(char C) {return C - '0';}
char myitoc(int N) {return '0' + N;}
#define FINALANS(A) {cout << A << endl; exit(0);}

template <class A> class unionfind
{
public:
  vector<int> parent;
  vector<int> rank;
  vector<A> diffw;

  unionfind(int N, A U = 0)
  {
    parent = vector<int>(N, -1);
    rank = vector<int>(N, 0);
    diffw = vector<A>(N, U);
  }

  int root(int X)
  {
    if (parent.at(X) < 0) return X;
    int R = root(parent.at(X));
    diffw.at(X) += diffw.at(parent.at(X));
    return parent.at(X) = R;
  }

  int size(int X)
  {
    return -parent.at(root(X));
  }

  A weight(int X)
  {
    root(X);
    return diffw.at(X);
  }

  A diff(int X, int Y)
  {
    return weight(Y) - weight(X);
  }

  bool same(int X, int Y)
  {
    return (root(X) == root(Y));
  }

  bool unite(int X, int Y, A W = 0)
  {
    W += weight(X);
    W -= weight(Y);

    X = root(X);
    Y = root(Y);
    if (X == Y) return false;
    
    if (rank.at(X) < rank.at(Y)) 
    {
      swap(X, Y);
      W = -W;
    }
    if (rank.at(X) == rank.at(Y)) rank.at(X)++;
    parent.at(X) += parent.at(Y);
    parent.at(Y) = X;
    diffw.at(Y) = W;
    return true;
  }
};

signed main()
{
  int N, K, L;
  cin >> N >> K >> L;

  unionfind<int> uf0(N), uf1(N);

  for (int i = 0; i < K; i++)
  {
    int p, q;
    cin >> p >> q;
    p--, q--;
    uf0.unite(p, q);
  }
  for (int i = 0; i < L; i++)
  {
    int r, s;
    cin >> r >> s;
    r--, s--;
    uf1.unite(r, s);
  }

  map<pair<int, int>, int> mp;
  for (int i = 0; i < N; i++)
  {
    mp[make_pair(uf0.root(i), uf1.root(i))]++;
  }
  for (int i = 0; i < N; i++)
  {
    cout << mp[make_pair(uf0.root(i), uf1.root(i))];
    if (i == N - 1)
      cout << endl;
    else
      cout << " ";
  }
}

Measured memory_bytes: 21120
D = int(input())
cl = list(map(int, input().split()))
sl = [list(map(int, input().split())) for _ in range(D)]
tl = [int(input()) for _ in range(D)]

def score(d, ti, last):
    s = sl[d-1][ti]
    for i in range(len(cl)):
        c = cl[i]
        s -= c*(d-last[i])
    return s

s = 0
last = [0]*26
for d in range(D):
    t = tl[d] - 1
    last[t] = d+1
    s += score(d+1,t,last)
    print(s)



Measured memory_bytes: 74212
import java.util.*;

public class Main{

    String[][] set,color;

    void solve(){
        Scanner sc = new Scanner(System.in);

        while(true){
            int n = sc.nextInt();
            if(n==0) break;
            set = new String[n][6];
            color = new String[n][4];
            int cnt = 0;
            for(int i=0; i<n; i++){
                for(int j=0; j<6; j++) set[i][j] = sc.next();
                getColor(i);
                for(int j=0; j<i; j++){
                    boolean same = false;
                    for(int k=0; k<4; k++){
                        for(int l=0; l<4; l++){
                            if(!color[i][l].equals(color[j][(l+k)%4])){
                                same = false;
                                break;
                            }
                            same = true;
                        }
                        if(same) break;
                    }
                    if(same){
                        cnt++;
                        break;
                    }
                }
            }

            System.out.println(cnt);
        }
    }

    void getColor(int idx){
        int num = 0;
        for(int i=0; i<6; i++){
            if(set[idx][i].equals("Cyan")) num = i;
        }

        if(num==0){
            color[idx][0] = set[idx][1];
            color[idx][1] = set[idx][2];
            color[idx][2] = set[idx][4];
            color[idx][3] = set[idx][3];
        }else if(num==1){
            color[idx][0] = set[idx][5];
            color[idx][1] = set[idx][2];
            color[idx][2] = set[idx][0];
            color[idx][3] = set[idx][3];
        }else if(num==2){
            color[idx][0] = set[idx][1];
            color[idx][1] = set[idx][5];
            color[idx][2] = set[idx][4];
            color[idx][3] = set[idx][0];
        }else if(num==3){
            color[idx][0] = set[idx][1];
            color[idx][1] = set[idx][0];
            color[idx][2] = set[idx][4];
            color[idx][3] = set[idx][5];
        }else if(num==4){
            color[idx][0] = set[idx][0];
            color[idx][1] = set[idx][2];
            color[idx][2] = set[idx][5];
            color[idx][3] = set[idx][3];
        }else if(num==5){
            color[idx][0] = set[idx][1];
            color[idx][1] = set[idx][3];
            color[idx][2] = set[idx][4];
            color[idx][3] = set[idx][2];
        }
    }

    public static void main(String[] args){
        new Main().solve();
    }
}

Measured memory_bytes: 12000
#include<stdio.h>
int main(){int H,W,h,w;scanf("%d%d%d%d",&H,&W,&h,&w);if(H%h||W%w){puts("Yes");for(int i=1;i<=H;++i,puts("")) for(int j=1;j<=W;++j)printf("%d ",(i%h||j%w)?1000:-1000*(h*w-1)-1);}else puts("No");return 0;}

Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
int main() {
    int N;
    cin >> N;
    vector<ll> t(N), a(N);
    REP(i, N) { cin >> t[i] >> a[i]; }
    ll A = 1;
    ll T = 1;
    REP(i, N) {
        ll n = max((T + t[i] - 1) / t[i], (A + a[i] - 1) / a[i]);
        T = n * t[i];
        A = n * a[i];
    }
    cout << T + A << endl;
}

Measured memory_bytes: 384
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#include<string.h>
#include<iostream>
using namespace std;
int main() {
  int a;
  string str1, str2;
  cin >> a;
  cin >> str1 >> str2;
  rep(i,a) {
    cout << str1.at(i) << str2.at(i) ;
  }
  return 0;
}

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

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<bool> VB;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef pair<int, int> PII;
typedef long long LL;
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 SQ(a) ((a)*(a))
#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())
#define LB lower_bound
#define UB upper_bound

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

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const LL INF = 1e9;
const LL MOD = 1e9+7;

//other
//-------------------------------------------
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define FI first
#define SE second

//memo
// setprecision()

int main() {
  string S;
  cin >> S;
  if(S == "SUN") cout << 7 << endl;
  else if(S == "MON") cout << 6 << endl;
  else if(S == "TUE") cout << 5 << endl;
  else if(S == "WED") cout << 4 << endl;
  else if(S == "THU") cout << 3 << endl;
  else if(S == "FRI") cout << 2 << endl;
  else cout << 1 << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000


int main(){
   unsigned short *A, *B;
   int C[VMAX+1];
  int n, i, j;

  scanf("%d", &n);

   A = malloc(sizeof(short)*n+1);
   B = malloc(sizeof(short)*n+1);



  for(i = 0; i < n; i++){
    scanf("%d",&A[i]);
  }

  for(i = 0; i < VMAX+1; i++){
    C[i] = 0;
  }

  for(i = 0 ;i < n;i++){
    C[A[i]]++;
  }

  for(i = 1; i < VMAX+1; i++){
    C[i] = C[i] + C[i-1];
  }

  for(i = n-1; i >= 0; i--){
    B[C[A[i]]-1] = A[i];
    C[A[i]]--;
  }


  
  for(i = 0; i < n ; i++){
 
    if(i == n-1){
      printf("%d\n",B[i]);
      break;
    }
    printf("%d ",B[i]);
  }

  return 0;
}



Measured memory_bytes: 9584
#include <stdio.h>
int main(void){
    long long a,b,x;
    //long long loop1;
    scanf("%lld%lld%lld",&a,&b,&x);
    long long fb=(b/x)+1;
    long long fam1=((a-1)/x)+1;
    if(a==0)fam1=0;
    printf("%lld\n",fb-fam1);
    
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

int main() {
  string s;
  cin >> s;
  ll n=s.size()-1;
  ll ans=0;
  for(ll i=0;i<(1<<n);i++) {
    bitset<11> bit(i);
    ll tans=0;
    ll tmp=(s[0]-'0');
    for(ll i=0;i<n;i++) {
      if(bit.test(i)) {
        tans+=tmp;
        tmp=(s[i+1]-'0');
      }
      else {
        tmp*=10;
        tmp+=(s[i+1]-'0');
      }
    }
    tans+=tmp;
    ans+=tans;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repp(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define per(i,n) for (long long i = (n); i >= 0; --i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//ミョ(-ω- ?)
int main() {
    int x,y;
    cin >> x >> y;
    if(y%2){
        cout << "No\n";
        return 0;
    }
    if( 2*x <= y &&  y  <= x*4 ){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

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

int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	long long a[n];
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
	}
	if (a[0]!=0LL)
	{
		cout<<"-1\n";
		return 0;
	}
	int f=1;
	long long ans=0LL;
	for (int i = 1; i < n; ++i)
	{
		if (a[i-1]<a[i]-1)
		{
			f=0;
			break;
		}
		if (a[i-1]>=a[i])
		{
			ans+=a[i-1];
		}
	}
	if (f==0)
	{
		cout<<"-1\n";
		return 0;
	}
	ans+=a[n-1];
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
#define mod 998244353
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pi pair<ll,ll>
using namespace std;
const ll N=500010;

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

	ll n,a,b;
	cin>>n>>a>>b;
	ll ans=a*(n/(a+b));
	ll left=n%(a+b);
	ans+=min(left,a);
	cout<<ans;

	return(0);
}


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

#define EPS (1e-10)
#define equals(a,b) ((fabs(a)-(b)) < EPS)
#define dle(a,b) (equals(a,b) || a<b)

class Point {
public:
  double x, y;
  
  Point (double x = 0, double y = 0) : x(x), y(y) {}
  
  Point operator+ (Point p) { return Point(x + p.x, y + p.y); }
  Point operator- (Point p) { return Point(x-p.x, y-p.y); }
  Point operator* (double k) { return Point(x*k, y*k); }
  Point operator/ (double k) { return Point(x/k, y/k); }
  
  double norm() { return x*x + y*y; }
  double abs() { return sqrt(norm()); }

  bool operator< (const Point &p) const {
    return x != p.x ? x < p.x : y < p.y;
  }
};

typedef Point Vector;

typedef vector<Point> Polygon;

double norm( Vector a ) { return a.x*a.x+a.y*a.y; }
double abs( Vector a ) { return sqrt(norm(a)); }
Point polar( double a, double r ) { return Point(cos(r)*a, sin(r)*a); }
double getDistance( Vector a, Vector b ) { return abs(a-b); }
double dot( Vector a, Vector b ) { return a.x*b.x + a.y*b.y; }
double cross( Vector a, Vector b ) { return a.x*b.y - a.y*b.x; }

static const int COUNTER_CLOCKWISE = 1;
static const int CLOCKWISE = -1;
static const int ONLINE_BACK = 2;
static const int ONLINE_FRONT = -2;
static const int ON_SEGMENT = 0;

int ccw( Point p0, Point p1, Point p2 ) {
  Vector a = p1-p0;
  Vector b = p2-p0;

  if( cross(a, b) > EPS ) return COUNTER_CLOCKWISE;
  if( cross(a, b) < EPS ) return CLOCKWISE;
  if( dot(a, b) < -EPS ) return ONLINE_BACK;
  if( norm(a) < norm(b)  ) return ONLINE_FRONT;
  return ON_SEGMENT;
}

bool yxCmp( const Point &p1, const Point &p2 ) {
  return (p1.y == p2.y) ? p1.x < p2.x : p1.y < p2.y;
}

class PolarAngleCmp {
public:
  Point o;
  PolarAngleCmp( Point o ) : o(o) {}
  bool operator() ( const Point &p1, const Point &p2 ) const {
    Vector a = Vector(p1.x-o.x, p1.y-o.y);
    Vector b = Vector(p2.x-o.x, p2.y-o.y);
    double c = cross(a, b);
    if(c == 0) return abs(a) < abs(b);
    return c > 0;
  }
};

Polygon grahamScan( Polygon &s ) {
  Polygon h;
  Point lm = *min_element(s.begin(), s.end(), yxCmp);
  sort(s.begin(), s.end(), PolarAngleCmp(lm));
  for(int i=0; i<=2; i++) h.push_back(s[i]);
  for(int i=3; i<s.size(); i++) {
    while(h.size()>=2 && ccw(h[h.size()-2], h.back(), s[i]) == CLOCKWISE)
      h.pop_back();
    h.push_back(s[i]);
  }
  return h;
}

int main() {
  char ch;
  int n;
  
  while(cin>>n, n) {
    Polygon pl, all;
    double x,y;
    for(int i=0; i<n; i++) {
      cin >> x >> ch >> y;
      pl.push_back(Point(x,y));
    }
    all = grahamScan(pl);
    cout << pl.size() - all.size() << endl;
  }
  return 0;
}

Measured memory_bytes: 1244
private fun readLongs() = readLine()!!.split(" ").map { it.toLong() }

fun main(args: Array<String>) {
    val (N, M) = readLongs()
    val ab = Array(N.toInt()) { readLongs() }

    var need = M
    var ans = 0L
    for ((price, amount) in ab.sortedBy { it[0] }) {
        if (amount < need) {
            ans += price * amount
            need -= amount
        } else {
            ans += price * need
            break
        }
    }

    println(ans)
}

Measured memory_bytes: 85668
import sys
readline = sys.stdin.buffer.readline

import math
X = int(readline())


def is_prime(n) -> bool:
    if n == 2:
        return True

    for i in range(2, int(math.sqrt(n)) + 1):
        if n % i == 0:
            return False

    return True


while True:
    if is_prime(X):
        print(X)
        break

    X += 1


Measured memory_bytes: 9160
#include<iostream>
#include<cstdio>

using namespace std;

int A[7][4][4]={
  
  {
    {1,1,0,0},
    {1,1,0,0},
    {0,0,0,0},
    {0,0,0,0},
  },
  
  {
    {1,0,0,0},
    {1,0,0,0},
    {1,0,0,0},
    {1,0,0,0},
  },
  
  {
    {1,1,1,1},
    {0,0,0,0},
    {0,0,0,0},
    {0,0,0,0},
  },
  
  {
    {0,1,0,0},
    {1,1,0,0},
    {1,0,0,0},
    {0,0,0,0},
  },
  
  {
    {1,1,0,0},
    {0,1,1,0},
    {0,0,0,0},
    {0,0,0,0},
  },
  
  {
    {1,0,0,0},
    {1,1,0,0},
    {0,1,0,0},
    {0,0,0,0},
  },
  
  {
    {0,1,1,0},
    {1,1,0,0},
    {0,0,0,0},
    {0,0,0,0},
  },
},
  
  a[12][12];

string s="ABCDEFG";

bool check(int x, int y, int n){
  
  for(int k=0;k<4;k++){
    for(int l=0;l<4;l++){
      int nx=x+k,ny=y+l;
      if(A[n][k][l]==1){
	if(a[nx][ny]!=A[n][k][l]){
	  return false;
	}
	if(nx<0||nx>7||ny<0||ny>7){
	  return false;
	}
      }
    }
  }
  return true;
}


int main(void){

  char ch;

  while(true){

    for(int i=0;i<12;i++)
      for(int j=0;j<12;j++)
	a[i][j]=0;
    
    for(int i=0;i<8;i++){
      for(int j=0;j<8;j++){
	if(scanf(" %c",&ch)==EOF)return 0;
	a[i][j]=ch-'0';
      }
    }
    bool fg=true;
    for(int k=0;fg && k<7;k++){
      for(int i=0;fg && i<8;i++){
	for(int j=0;fg && j<8;j++){
	  if(check(i,j,k)){
	    cout << s[k] << endl;
	    fg=false;
	  }
	}
      }
    }
  }

  return 0;
}

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

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

typedef long long  ll;

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

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





int main() {
    ll a,b;
    cin>>a>>b;
    if(a==1 || b==1){
        cout<<1<<endl;
        return 0;
    }
    cout<<(a*b+1)/2<<endl;



    return 0;
}


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

int main(void){
  int a,b;
  cin >> a >> b;
  if(abs(a-b)>=2)cout<<2*max(a, b)-1<<endl;
  else if(abs(a-b)==1)cout<<2*max(a, b) -1<<endl;
  else cout<< 2*max(a, b)<<endl;

  return 0;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
#define ll long long int 
#define MOD 998244353
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl "\n"
#define all(x) (x).begin(), (x).end()
#define tr(x,it) for(auto it = x.begin();it!=x.end();++it)
#define fpresent(x,c) ((c).find(x) != (c).end())  //set,map
#define present(c,x) (find(all(c),x) != (c).end()) //vector
#define pb push_back 
#define mp make_pair
#define ff first
#define ss second
#define setv(ar, val) memset(ar, val, sizeof(ar));
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << endl;
    err(++it, args...);
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); //use mt19937_64 for 64 bit random no.

const ll N = 200005;

ll fact[N], invfact[N];

ll pow(ll a, ll b, ll m)
{
    ll ans=1;
    while(b)
    {
        if(b&1)
            ans=(ans*a)%m;
        b/=2;
        a=(a*a)%m;
    }
    return ans;
}

ll modinv(ll k)
{
    return pow(k, MOD-2, MOD);
}

void precompute()
{
    fact[0]=fact[1]=1;
    for(ll i=2;i<N;i++)
    {
        fact[i]=fact[i-1]*i;
        fact[i]%=MOD;
    }
    invfact[N-1]=modinv(fact[N-1]);
    for(ll i=N-2;i>=0;i--)
    {
        invfact[i]=invfact[i+1]*(i+1);
        invfact[i]%=MOD;
    }
}

ll nCr(ll x, ll y)
{
    if(y>x)
        return 0;
    ll num=fact[x];
    num*=invfact[y];
    num%=MOD;
    num*=invfact[x-y];
    num%=MOD;
    return num;
}


int main()
{
    // freopen("input.in","r",stdin);
    // freopen("output.in","w",stdout);
    fastio;
    cin.tie(NULL);
    ll n,m,i,j,k,ans=0;
    cin>>n>>m>>k;
    precompute();
    error(nCr(2,0));

    for(i=0;i<=k;i++){
        ans += (((nCr(n-1, i)*m)%MOD)*(pow(m-1, n - i - 1, MOD)))%MOD;
        ans %= MOD;
    }

    cout<<ans<<endl;

    return 0;
}


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

int main()
{
  int N, K; cin >> N >> K;
  int ans = 0;
  rep(i, N) {
    int h; cin >> h;
    if (h >= K) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
N,K = map(int,input().split())
p = list(map(int,input().split()))

s = 0
for i in range(0,K):
    s = s + p[i]
t = s
for j in range(0,N-K):
    u = s + p[j+K] - p[j]
    if u > t:
        t = u
    s = u
print((t+K)/2)

Measured memory_bytes: 25060
#include <iostream>
 
using namespace std;
 
int main(){
  int n;
  long sum = 1;
 
  cin >> n;
  for(int i = 1;i <= n;i++){
    sum*=i;
    sum %= 1000000000+7;
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main()
{
	int i,j,lena,lenb,lenc;
	char a[100],b[100],c[100];
	scanf("%s%s%s",a,b,c);
	lena=strlen(a),lenb=strlen(b),lenc=strlen(c);
	if(a[lena-1]==b[0]&&b[lenb-1]==c[0]){
		printf("YES\n");
	}
	else printf("NO\n");
	return 0;
}

Measured memory_bytes: 128
s = input()

count = 1

alphabets = {}

alphabets[s[0]] = 1

for i in range(1, len(s)):
    for char, char_count in alphabets.items():
        if char != s[i]:
            count += char_count

    if s[i] in alphabets:
        alphabets[s[i]] += 1
    else:
        alphabets[s[i]] = 1

print(count)


Measured memory_bytes: 3500
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < (n);i++)
#define lint long long
const lint mod=1e9+7;
const lint inf=2.19e15+1;
const long double eps=1e-10;
template <class T,class U>bool chmin(T& a,U b){if(a>b){a=b;return true;}return false;}
template <class T,class U>bool chmax(T& a,U b){if(a<b){a=b;return true;}return false;}

signed main(){
    string s;
    cin >> s;
    if (s[0] == 'R' and s[0] == s[1] and s[1] == s[2]){
        cout << 3 << endl;
        return 0;
    }
    for (int i=0; i<2; i++){
        if (s[i] == 'R' and s[i + 1] == 'R'){
            cout << 2 << endl;
            return 0;
        }
    }
    for (int i = 0; i<3; i++){
        if (s[i] == 'R'){
            cout << 1 << endl;
            return 0;
        }
    }
    cout << 0 << endl;
}

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

int main(){
string a;
  cin >> a;
  int counta=0,countb=0;
  for(int i=0;i<a.size();i++){
  	if(a.at(i)=='0')counta++;
    if(a.at(i)=='1')countb++;
  }
  counta=min(counta,countb);
  cout << 2*counta << endl;
}

Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<algorithm>

using namespace std;

int main(){
  int i,n,d,c=1;
  vector <int> v;
  
  cin>>n;
  for(i=0;i<n;i++){
    cin>>d;
    v.push_back(d);
  }
  sort(v.begin(),v.end());
  
  for(i=0;i<n-1;i++){
    if(v[i]!=v[i+1])
      c++;
  }
  cout<<c<<endl;
  return 0;
  
}

Measured memory_bytes: 256
import java.util.*;

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

        long n = sc.nextLong();

        if (n%2==1){
            System.out.println(0);
            return;
        }

//        n /= 10;
//        n *= 10;

        long ans = 0;

        long len = String.valueOf(n).length();

        if (len==1){
            System.out.println(0);
            return;
        }


        for (int i=1; i<=26; i++){
            ans += n/(long)Math.pow(5,i)/2;

        }
        System.out.println(ans);

    }

}


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

using namespace std;

int N;
vector<vector<int>> table;
vector<int> visited;

void dfs(int node)
{
	// 訪問済みにする
	visited[node] = 1;

	for (int i = 0; i < N; i++)
	{
		// 指定のノードからi番目のノードに行けるか調べる
		auto &v = table[node];
		if (find(v.begin(), v.end(), i) == v.end())
		{
			continue;
		}

		// i番目のノードが未訪問ならそのノードからまた探索
		if (visited[i] == 0)
		{
			dfs(i);
		}
	}
}

int main()
{
	int M;
	int ans = 0;
	cin >> N >> M;

	table.resize(N);
	visited.resize(N, 0);
	vector<pair<int, int>> edges;

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

		// グラフテーブルを作成
		table[a].push_back(b);
		table[b].push_back(a);

		// 辺を保管
		edges.push_back(make_pair(a, b));
	}

	for (int i = 0; i < M; i++)
	{
		a = edges[i].first;
		b = edges[i].second;

		// i番目の辺を削除
		table[a].erase(find(table[a].begin(), table[a].end(), b));
		table[b].erase(find(table[b].begin(), table[b].end(), a));

		// 訪問状況を初期化
		fill(visited.begin(), visited.end(), 0);
		
		// 適当なノードから探索
		dfs(0);

		// 未探索ノードがあったらi番の目の辺は橋
		for (auto it : visited)
		{
			if (it == 0)
			{
				ans++;
				break;
			}
		}

		// 削除した辺を戻す
		table[a].push_back(b);
		table[b].push_back(a);
	}

	cout << ans << endl;

	return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

int main(){
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cout<<setprecision(32);

	int n, m;
	cin>>n>>m;
	vector<int> s[m];
	for(int i = 0; i < m; i++){
		int k, x; cin>>k;
		while(k--){
			cin>>x; x--;
			s[i].push_back(x);
		}
	}
	vector<int> p(m);
	for(auto &x : p){
		cin>>x;
	}
	int ans = 0;
	for(int mask = 0; mask < (1<<n); mask++){
		int nmask = 0;
		for(int i = 0; i < m; i++){
			int cnt = 0;
			for(auto x : s[i]){
				if(mask&(1<<x))cnt ^= 1;
			}
			if(cnt == p[i])nmask ^= (1<<i);
		}
		if(nmask + 1 == (1<<m))ans++;
	}
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define vii vector<vi>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;

int main(){
	 //cin.tie(0);
	//ios::sync_with_stdio(false);
	//std::cout << std::fixed;
	//std::cout << std::setprecision(12);
	//std::cout << std::defaultfloat;
  int n,m;
  cin>>n>>m;
  vector<vector<int>> g(n,vector<int>());
  FOR(i,0,m){
    int s,t;
    cin>>s>>t;
    g[s-1].PB(t-1);
  }
  int s,t;
  cin>>s>>t;
  s--;t--;
  vector<vector<int>> dp(n,vector<int>(3,mod));
  dp[s][0]=0;
  priority_queue<pii> pq;
  pq.push(MP(0,s));
  cerr<<"test"<<endl;
  while(pq.size()){
    pii pr=pq.top();
    pq.pop();
    int nw=pr.ND;
    int c=-pr.ST+1,mc=c%3;
    if(c-1>dp[nw][(c+2)%3])continue;
    for(const auto& x:g[nw]){
      if(dp[x][mc]>c){
        dp[x][mc]=c;
        pq.push(MP(-c,x));
      }
    }

  }
  if(dp[t][0]==mod){
    cout<<-1<<endl;
  }else{
    cout<<dp[t][0]/3<<endl;
  }

	return 0;
}


Measured memory_bytes: 11136
#include<iostream>
using namespace std;
int main() {
	long long n, a, b; cin >> n;
	long long test[123] = { 0 }, dp[21] = { 0 };
	for (int h = 1; h < n; h++) {
		cin >> a; test[h] = a;
		if (h == 1) {
			dp[a]++;
		}
	}
	cin >> b;
	for (int h = 2; h < n; h++) {
		long long afterdp[21] = { 0 };
		for (int i = 0; i < 21; i++) {
			if (dp[i] != 0) {
				if (i - test[h] >= 0) {
					afterdp[i - test[h]] += dp[i];
				}
				if (i + test[h] <= 20) {
					afterdp[i + test[h]] += dp[i];
				}
			}
		}
		for (int i = 0; i < 21; i++) {
			dp[i] = afterdp[i];
		}
	}
	cout << dp[b] << endl;
}


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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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

template<typename T>
void print1(T begin, T end) {
  while (begin != end) {
    cout << (*begin) << " ";
    *begin++;
  }
  cout << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
  for (int i = 0; i < height; i++) {
    for (int j = 0; j < width; j++) {
      cout << " " << Array[i][j];
    }
    cout << endl;
  }
}

void print() { std::cerr << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
  std::cerr << head << " ";
  print(std::forward<Tail>(tail)...);
}

template<class T>
void Add(T &a, const T &b, const T &mod=1000000007) {
  int val = ((a % mod) + (b % mod)) % mod;
  if (val < 0) { val += mod; }
  a = val;
}

// ------------------------------------------------------------------------------------------

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

long long lcm(long long a, long long b) {
   return a / gcd(a, b) * b;
}


signed main() {
  int n;
  cin >> n;
  vector<int> v(n);
  rep (i, n) {
    cin >> v[i];
  }
  int ans = v[0];
  repp (i, 1, n) {
    ans = gcd(ans, v[i]);
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1024
n=int(input())
a=list(map(int,input().split()))
from numpy import cumsum
left_cumsum=cumsum(a)
a.reverse()
right_cumsum=cumsum(a)
ans=10000000000
for i in range(n-1):
    ans=min(ans,abs(left_cumsum[i]-right_cumsum[-i-2]))
print(ans)


Measured memory_bytes: 38312
import java.io.*;

class Main
{
 public static void main(String args[])throws IOException
 {
  BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
  for(;;)
  {
   int cnt=0;
   String str_n = br.readLine();
   if(str_n==null) break;
   int n = Integer.parseInt(str_n);
   for(int a = 0; a <= 9; a++)
   {
    for(int b = 0; b <= 9; b++)
    {
     for(int c = 0; c <= 9; c++)
     {
      for(int d = 0; d <= 9; d++)
      {
       if(a+b+c+d==n)
        cnt++;
      }
     }
    }
   }
   System.out.println(cnt);
  }
 }
}

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

using namespace std;

typedef long long ll;

#define mod 1000000007
#define siz 100001

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	string s;
	cin >> s;
	
//	cout << s[0] - 65 << "\n";
	(s[0] - 65) < 32 ? cout << "A" << "\n" : cout << "a" << "\n";
}

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


int main(void) {
    unsigned long long pow = 1;
    unsigned N;
    cin >> N;
    for (int i = 1; i <= N; i++) {
        pow = (pow*i) % 1000000007;
    }
     cout<< pow <<endl;

    return 0;
}



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


int main() {
    int a, b;
    cin >> a >> b;
    if(a%b == 0){
        cout << a/b;
    }
    else
    {
        cout << a/b+1;
    }
    
    
    cout << endl;
}


Measured memory_bytes: 256