akhauriyash/Code-Regression huggingface dataset:
# F - I hate Matrix Construction

n = int(input())
s = list(map(int, input().split()))
t = list(map(int, input().split()))
u = list(map(int, input().split()))
v = list(map(int, input().split()))
assert len(s) == len(t) == n
assert len(u) == len(v) == n

nbits = 64
AND = 0
OR  = 1

A = [[u[i]] * n for i in range(n)]
for i in range(n):
    for j in range(n):
        if t[j] == AND:
            A[i][j] |= v[j]  # v[j]で1のビットは1
        else:
            A[i][j] &= v[j]  # v[j]で0のビットは0
        # conflict check
        if (s[i] == AND and t[j] == OR  and  u[i] & ~v[j]) or \
           (s[i] == OR  and t[j] == AND and ~u[i] &  v[j]):
            print(-1)
            exit()

# 1であるビット数を数える
ucount = [[0] * nbits for i in range(n)]
vcount = [[0] * nbits for j in range(n)]
for i in range(n):
    for j in range(n):
        for k in range(nbits):
            if A[i][j] & (1 << k):
                ucount[i][k] += 1
                vcount[j][k] += 1

for k in range(nbits):
    mask = 1 << k
    for i in range(n):
        if s[i] == OR and u[i] & (1 << k) and ucount[i][k] == 0:
            # いずれかの列の第kビットを1にする
            for j in range(n):
                if (t[j] == OR  and v[j] & mask) or \
                   (t[j] == AND and v[j] & mask == 0 and vcount[j][k] < n - 1):
                    A[i][j] |= mask
                    ucount[i][k] += 1
                    vcount[j][k] += 1
                    break
            else:
                print(-1)
                exit()
        if s[i] == AND and u[i] & mask == 0 and ucount[i][k] == n:
            # いずれかの列の第kビットを0にする
            for j in range(n):
                if (t[j] == AND and v[j] & mask == 0) or \
                   (t[j] == OR  and v[j] & mask and vcount[j][k] > 1):
                    A[i][j] &= ~mask
                    ucount[i][k] -= 1
                    vcount[j][k] -= 1
                    break
            else:
                print(-1)
                exit()
    for j in range(n):
        if t[j] == OR and v[j] & mask and vcount[j][k] == 0:
            for i in range(n):
                if (s[i] == OR  and u[i] & mask) or \
                   (s[i] == AND and u[i] & mask == 0 and ucount[i][k] < n - 1):
                    A[i][j] |= mask
                    ucount[i][k] += 1
                    vcount[j][k] += 1
                    break
            else:
                print(-1)
                exit()
        if t[j] == AND and v[j] & mask == 0 and vcount[j][k] == n:
            for i in range(n):
                if (s[i] == AND and u[i] & mask == 0) or \
                   (s[i] == OR  and u[i] & mask and ucount[i][k] > 1):
                    A[i][j] &= ~mask
                    ucount[i][k] -= 1
                    vcount[j][k] -= 1
                    break
            else:
                print(-1)
                exit()

for i in range(n):
    print(' '.join(map(str, A[i])))


Measured memory_bytes: 91988
#include <cstdio>
#include <algorithm>
using namespace std;

long long arr[3];

int main() {
  bool get = false;
  for(int i = 0 ; i < 3 ; i++){
    scanf("%lld", &arr[i]);
    if(arr[i] % 2 == 0) get = true;
  }
  sort(arr, arr+3);
  if(get) puts("0");
  else{
    printf("%lld\n", arr[0] * arr[1]);
  }
  return 0;
}


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

#define fi first
#define se second

const int N = 100100;

using namespace std;

int main()
{
        ios_base::sync_with_stdio(0);

        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);

        string s;
        cin >> s;
        int A = s.size() & 1;
        int B = (s[0] == s.back());
        if(A ^ B){
                cout << "First" << "\n";
        } else{
                cout << "Second" << "\n";
        }
}


Measured memory_bytes: 512
N, P = map(int, input().split())
S = input()

if P == 2 or P == 5:
    def solve25(N, P, S):
        c = 0
        for i in range(N-1, -1, -1):
            if int(S[i]) % P == 0:
                # 以降桁を増やしてもOK
                c += i+1
        return c
    print(solve25(N, P, S))
else:
    def solve(N, P, S):
        rcounts = [0] * P
        rcounts[0] = 1 # sそのものが割り切れた場合に引き算する相手がいないから
        ints = 0
        for i, s in enumerate(S[::-1]):
            ints += int(s) * pow(10, i, P)
            r = ints % P
            rcounts[r] += 1
        c = 0
        for v in rcounts:
            c += v*(v-1)//2
        return c
    print(solve(N, P, S))

Measured memory_bytes: 3628
#include<iostream>
using namespace std;
int V[101][10001];
int v[101],w[101];
int main()
{
    int N,W;
    cin>>N>>W;
    
    for(int i=1;i<N+1;i++)
    {
        cin>>v[i]>>w[i];
    }
    
    for(int i=0;i<101;i++)
        V[i][0]=0;
    for(int i=0;i<10001;i++)
        V[0][i]=0;
    
    for(int i=1;i<N+1;i++)
    {
        for(int j=1;j<W+1;j++)
        {
            if(w[i]>j)
                V[i][j]=V[i-1][j];
            else
                V[i][j]=max(v[i]+V[i-1][j-w[i]],V[i-1][j]);
        }
    }
    cout<<V[N][W]<<endl;
}

Measured memory_bytes: 6988
a,b,n=map(int,input().split())

nb=n//b

#xmax=0
if n<b:
    xmax=a*n//b
else:
    xmax=0
#    for xb in range(nb):
#        xv=(a*xb*b+a*(b-1))//b-a*xb
#        xmax=max(xmax,xv)
    xb=nb-1
    xv=(a*xb*b+a*(b-1))//b-a*xb
    xmax=max(xmax,xv)
    xb=nb
    xv=(a*xb*b+a*n%b)//b-a*xb
    xmax=max(xmax,xv)

print(xmax)    

Measured memory_bytes: 9204
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner s = new Scanner(System.in);
		int[] a = {s.nextInt(), s.nextInt(), s.nextInt(), s.nextInt(), s.nextInt()};
		Arrays.sort(a);
		int k = s.nextInt();
		if (a[4] - a[0] > k)	System.out.println(":(");
		else System.out.println("Yay!");
		/*
		1 2 4 8 9 15 ->Yay!
		15 18 26 35 36 18 -> :(
		*/
	}
}
 

Measured memory_bytes: 23636
n = int(input())
ans = 0
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    divisors.sort()
    return divisors

divs = make_divisors(n)
# print(divs)
for div in divs[::-1]:
    if div - 1 >= 2 and div - 1 > n/div:
        ans += div - 1
print(ans)

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

# define C continue;
# define R return

# define D double
# define I insert
# define ll long long
# define ld long double

# define ull unsigned long long
# define ui unsigned int

# define pb push_back
# define pf push_front

# define vi vector < int >
# define vc vector < char >
# define vs vector < string >
# define vb vector < bool >
# define vd vector < D >
# define vll vector < ll >
# define vull vector < ull >
# define vld vector < ld >

# define vvi vector < vector < int > >
# define vvb vector < vector < bool > >
# define vvc vector < vector < char > >
# define vvll vector < vector < ll > >
# define vvd vector < vector < D > >
# define vvld vector < vector < ld > >

# define all(v) (v).begin() , (v).end()
# define allrev(v) (v).rbegin() , (v).rend()
# define allcomp(v) v.begin() , v.end() , comp
# define allrevcomp(v) v.rbegin() , v.rend() , comp

# define pii pair < int , int >
# define pll pair < ll , ll >
# define pld pair < ld , ld >
# define pDD pair < D , D >

# define vpld vector < pld >
# define vpii vector < pii >
# define vpll vector < pll >
# define vpDD vector < pDD >

# define vvpii vector < vector < pii > >
# define F first
# define S second
# define mp make_pair

# define dist(a,b,p,q) sqrt((p-a)*(p-a) + (q-b)*(q-b))

# define pp(n) printf("%.10Lf",n);
# define line cout<<"\n";
# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);

string vow = "aeiou";

const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};

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

const ld pie = 3.14159265358979 ;
const ll mod = 1e9 + 7 ;

void solve ( int test_case )
{
    string s ; cin >> s ;
    int n = s.size() ;

    string temp = "AGTC" ;
    int j = 0 ;

    int ans = 0 ;
    for ( int i=0 ; i < n ; i++ )
    {
        int f = 0 ;
        for ( ; f < 4 && temp[f] != s[i] ; f ++ ) ;

        if ( f < 4 ) C ;
        ans = max ( ans , i - 1 - j + 1 ) ;

        j = i + 1 ;
    }

    ans = max ( n-1-j + 1 , ans ) ;
    cout << ans ; line


}

int main()
{
    int t = 1;
    // cin >> t;

    for ( int i=0 ; i < t ; i++ ) solve(i);
    return 0;
}


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

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

int R, C, N;
int size[20];
int table[12][12];

int ans[12][12];
int ans_num;

void dfs(int depth) {
//       REP(r, R) {
//         cout << table[r][0];
//         for(int c = 1; c < C; c++) cout << ' ' << table[r][c];
//         cout << endl;
//       }
//       cout << endl;
  
  if( depth > N ) {
    bool same = true;
    REP(r, R) REP(c, C) if( ans[r][c] != table[r][c] ) same = false;
    if( !same ) {
      ans_num++;
      REP(r, R) REP(c, C) ans[r][c] = table[r][c];
    }
    return;
  }
  if( ans_num >= 2 ) return;
  int r, c;
  REP(i, R) REP(j, C) if( table[i][j] == depth ) {
    r = i;
    c = j;
  }
  
  table[r][c] = 0;
  for(int r1 = 0; r1 <= r; r1++)
    for(int r2 = r; r2 < R; r2++)
      if( size[depth] % (r2 - r1 + 1) == 0 )
        for(int c1 = 0; c1 <= c; c1++)
          for(int c2 = c; c2 < C; c2++)
            if( (r2 - r1 + 1) * (c2 - c1 + 1) == size[depth] ) {
              
              
              bool go = true;
              for(int i = r1; i <= r2; i++)
                for(int j = c1; j <= c2; j++)
                  if( table[i][j] != 0 )
                    go = false;
              
              if( go ) {
                for(int i = r1; i <= r2; i++)
                  for(int j = c1; j <= c2; j++)
                    table[i][j] = depth;
                
                dfs(depth + 1);
                
                for(int i = r1; i <= r2; i++)
                  for(int j = c1; j <= c2; j++)
                    table[i][j] = 0;
              }
            }
  table[r][c] = depth;
}

int main() {
  for(;;) {
    cin >> C >> R >> N;
    if( C == 0 && R == 0 && N == 0 ) break;
    REP(i, N) {
      int x, c; cin >> x >> c;
      size[x] = c;
    }
    REP(r, R) REP(c, C) {
      int v; cin >> v; table[r][c] = v;
    }

    REP(i, R) REP(j, C) ans[i][j] = -1;
    ans_num = 0;
    dfs(1);
    if( ans_num == 1 ) {
      REP(r, R) {
        cout << ans[r][0];
        for(int c = 1; c < C; c++) cout << ' ' << ans[r][c];
        cout << endl;
      }
    }else
      cout << "NA" << endl;
  }
  return 0;
}

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


int main() {
    ll n;
    cin >> n;
    int i=1 ;
    int sum = 1000 ;
    while (i*1000<n)
    {
        i++ ;
        sum = 1000*i ;
    }

    cout << sum-n << endl;
}

Measured memory_bytes: 3572
#include <iostream>
using namespace std;
int main(void){
  string s,t,u;
  int a,b;
  cin>>s>>t;
  cin>>a>>b;
  cin>>u;
  if(s==u) cout<<a-1<<" "<<b<<endl;
  else cout<<a<<" "<<b-1<<endl;
  return 0;
}

Measured memory_bytes: 256
n=int(input())
t=[[int(num)for num in input().split(':')]for i in range(n)]
for i in range(n):
    h=t[i][0]
    m=t[i][1]
    an_s=h*30+m/2
    an_l=m*6
    dif=0
    if abs(an_s-an_l)<180:dif=abs(an_s-an_l)
    else:dif=360-abs(an_s-an_l)
    if dif<30:
        print("alert")
    elif dif<90:
        print("warning")
    else:
        print("safe")

Measured memory_bytes: 7784
#include<iostream>
#include<string.h>
#include<math.h>
using namespace std;
int a[100005];
int b[100005];
int main()
{
	int i,n,sum=0;
	scanf("%d",&n);
	a[0]=0;
	a[n+1]=0;
	for(i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		b[i]=abs(a[i]-a[i-1]);
		sum+=b[i];
	}
	b[n+1]=abs(a[n+1]-a[n]);
	sum+=b[n+1];
	for(i=1;i<=n;i++)
	{
		printf("%d\n",sum-b[i]-b[i+1]+abs(a[i+1]-a[i-1]));
	}
	return 0;
}

Measured memory_bytes: 2048
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#define PB push_back
#define MP make_pair
#define FIR first
#define SEC second
#define ll long long
using namespace std;
template <class T>
inline void rd(T &x) {
	x=0; char c=getchar(); int f=1;
	while(!isdigit(c)) { if(c=='-') f=-1; c=getchar(); }
	while(isdigit(c)) x=x*10-'0'+c,c=getchar(); x*=f;
}
const int N=1e5+10;
int n;
vector<int> G[N];
int mxd,cur;
void dfs1(int u,int last,int d) {
	if(d>mxd) mxd=d,cur=u;
	for(int i=0;i<G[u].size();++i)
		if(G[u][i]!=last) dfs1(G[u][i],u,d+1);
}
int st[N],top;
int mk[N];
vector<int> L;
void dfs2(int u,int last,int T) {
	st[++top]=u;
	if(u==T) {
		for(int i=1;i<=top;++i) mk[st[i]]=1,L.PB(st[i]);
	}
	for(int i=0;i<G[u].size();++i)
		if(G[u][i]!=last) dfs2(G[u][i],u,T);
	top--;
}
void sol(int *P) {
	int m=0;
	P[++m]=1;
	for(int i=1;i+1<L.size();++i) {
		int l=m+1,r=m+G[L[i]].size()-1;
		P[++m]=r;
		for(int j=l;j<r;++j) P[++m]=j;
	}
	P[++m]=n;
}
int P[N],Q[N];
int main() {
	rd(n);
	for(int i=1,x,y;i<n;++i) rd(x),rd(y),G[x].PB(y),G[y].PB(x);
	mxd=-1; dfs1(1,0,0); int L1=cur;
	mxd=-1; dfs1(cur,0,0); int L2=cur;
	dfs2(L1,0,L2);
	for(int i=1;i<=n;++i) {
		int flg=mk[i];
		for(int j=0;!flg&&j<G[i].size();++j)
			flg|=mk[G[i][j]];
		if(!flg) {
			printf("-1");
			return 0;
		}
	}
	sol(P);
	reverse(L.begin(),L.end());
	sol(Q);
	for(int i=1;i<=n;++i)
		if(P[i]!=Q[i]) {
			if(P[i]>Q[i]) swap(P,Q);
			break;
		}
	for(int i=1;i<=n;++i) Q[P[i]]=i;
	for(int i=1;i<=n;++i) printf("%d ",Q[i]);
	return 0;
}

Measured memory_bytes: 14584
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;

string s;

int main(){
  ios_base::sync_with_stdio(false);

  cin >> s;
  s[3] = '8';
  cout << s << endl; 

  return 0;
}

Measured memory_bytes: 384
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <cstdio>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <cmath>
#include <set>
#include <map>
using ll = long long;
using itn = int;
using namespace std;
int GCD(int a, int b){
    return b ? GCD(b, a%b) : a;
}
int main(){
    int a,b;
    cin >> a >>b;
    if(a>8 || b>8){
        puts(":(");
    }else{
        puts("Yay!");
    }
}

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

using namespace std;
const int maxn = 5005;
typedef long long ll;
int dp[2][maxn],sum[maxn];
int main() {
	int n,mod,rt = 0;
	cin>>n>>mod;
	dp[rt][0] = 1;
	for(int i = 1;i < n;++i) {
		rt ^= 1;
		int s = i;
		if(n%2 == 1&& s > n/2 + 1) s = (n-i+1);
		if(n%2 == 0 && s > n/2) s = (n-i+1);
		memset(dp[rt],0,(n+1)<<2);
		for(int j = 0;j < n; ++j) {
			ll temp = 0;
			int k = 0;
			for(k = 0;k < n&&j-(k+32)*s>=0; k += 16) {
				temp += dp[rt^1][j-k*s];
				temp += dp[rt^1][j-(k+1)*s];
				temp += dp[rt^1][j-(k+2)*s];
				temp += dp[rt^1][j-(k+3)*s];
				temp += dp[rt^1][j-(k+4)*s];
				temp += dp[rt^1][j-(k+5)*s];
				temp += dp[rt^1][j-(k+6)*s];
				temp += dp[rt^1][j-(k+7)*s];
				temp += dp[rt^1][j-(k+8)*s];
				temp += dp[rt^1][j-(k+9)*s];
				temp += dp[rt^1][j-(k+10)*s];
				temp += dp[rt^1][j-(k+11)*s];
				temp += dp[rt^1][j-(k+12)*s];
				temp += dp[rt^1][j-(k+13)*s];
				temp += dp[rt^1][j-(k+14)*s];
				temp += dp[rt^1][j-(k+15)*s];
				k += 16;
				temp += dp[rt^1][j-k*s];
				temp += dp[rt^1][j-(k+1)*s];
				temp += dp[rt^1][j-(k+2)*s];
				temp += dp[rt^1][j-(k+3)*s];
				temp += dp[rt^1][j-(k+4)*s];
				temp += dp[rt^1][j-(k+5)*s];
				temp += dp[rt^1][j-(k+6)*s];
				temp += dp[rt^1][j-(k+7)*s];
				temp += dp[rt^1][j-(k+8)*s];
				temp += dp[rt^1][j-(k+9)*s];
				temp += dp[rt^1][j-(k+10)*s];
				temp += dp[rt^1][j-(k+11)*s];
				temp += dp[rt^1][j-(k+12)*s];
				temp += dp[rt^1][j-(k+13)*s];
				temp += dp[rt^1][j-(k+14)*s];
				temp += dp[rt^1][j-(k+15)*s];
			}
			for(;k < n &&j - k*s >= 0; ++k) temp += dp[rt^1][j-k*s];
			dp[rt][j] = temp%mod;
		}
	}
	ll ans = 0;
	for(int i = 0;i < n; ++i) {
		int j = n-i-1;
		ans += 1ll*(j+1)* dp[rt][i];
		ans %= mod;
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#ifdef DEBUG
#define FPEN freopen("in.txt", "r", stdin);
#define TEST(...)                                                              \
    { printf("! "), printf(__VA_ARGS__); }
#else
#define TEST(...)
#define FPEN
#endif
const int maxn = 200009;
typedef long long i64;
typedef pair<i64, i64> pi64;
typedef pair<int, int> pi;
const i64 MOD = 119 << 23 | 1;
class {
  public:
    int n, c[maxn];
    int sz[maxn], a[maxn], vis[maxn];
    vector<int> V[maxn];
    i64 ans[maxn];
    void solve() {
        cin >> n;
        for (int i = 1; i <= n; ++i)
            cin >> c[i], vis[c[i]] = 1;
        for (int i = 1; i < n; ++i) {
            int u, v;
            cin >> u >> v;
            V[u].push_back(v);
            V[v].push_back(u);
        }
        dfs(1, 0);
        for (int i = 1; i <= n; ++i) {
            ans[c[i]]++;
            if (vis[i]) {
                ans[i] += 1ll * n * (n - 1) / 2;
                ans[i] -= 1ll * (n - a[i]) * (n - a[i] - 1) / 2;
            }
        }
        for (int i = 1; i <= n; ++i) {
            cout << ans[i] << " ";
        }
        cout << "\n";
    }
    void dfs(int u, int fa) {
        sz[u] = 1;
        int pre = a[c[u]], res = a[c[u]];
        for (int v : V[u]) {
            if (v == fa)
                continue;
            dfs(v, u);
            sz[u] += sz[v];
            int b = a[c[u]] - pre;
            ans[c[u]] -= 1ll * (sz[v] - b) * (sz[v] - b - 1) / 2;
            pre = a[c[u]];
        }
        a[c[u]] = res + sz[u];
    }
} NSPACE;
int main() {
    FPEN;
    ios_base::sync_with_stdio(false);
    cout.tie(0);
    cin.tie(0);
    NSPACE.solve();
}

Measured memory_bytes: 37920
n = int(input())

mod = int(1e9+7)

have_any = 1
not_have_0 = 1
not_have_9 = 1
not_have_09 = 1

for _ in range(n):
    have_any *= 10
    have_any %= mod

    not_have_0 *= 9
    not_have_0 %= mod

    not_have_09 *= 8
    not_have_09 %= mod

not_have_9 = not_have_0

ans = have_any - not_have_0 - not_have_9 + not_have_09
ans %= mod
print(ans)


Measured memory_bytes: 9176
#include <iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include <stdio.h>
using namespace std;
//const long long N = 100005;
//int cm[N];
int main()
{
	ios::sync_with_stdio(0); cin.tie(0);
	long long a, b, c, d, e, k;
	cin >> a >> b >> c >> d>>e>>k;
	if (abs(a - b) > k || abs(a - c) > k || abs(a - d) > k || abs(a - e) > k || abs(b - c) > k || abs(b - d) > k || abs(b - e) > k || abs(c - d) > k || abs(c - e) > k || abs(d - e) > k) {
		cout << ":(";
	}
	else cout << "Yay!";
	
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    int n,m,x,i,j,ans=1200001,check=1;
    int c[12],a[12][12];
    cin >> n >> m >> x;
    for(i=0;i<n;i++){
        cin >> c[i];
        for(j=0;j<m;j++) cin >> a[i][j];
    }
    for(i=0;i<(1<<n);i++){
        vector<int> b(m);
        int cost=0;
        for(j=0;j<n;j++){
            if(i&(1<<j)){
                cost += c[j];
                for(int k=0;k<m;k++) b[k] += a[j][k];
            }
        }
        int f=1;
        for(j=0;j<m;j++){
            if(b[j]<x){
                f=0;
                break;
            }
        }
        if(f){
            ans = min(ans,cost);
            check=0;
        }
    }
    if(check) cout <<"-1";
    else cout << ans;
}

Measured memory_bytes: 3628
#include <iostream>

long long int S(long long int N) {
  int s = 0;

  for (long long int n = N; n > 0; n /= 10) {
    s += n % 10;
  }

  return s;
}

int main() {
  long long int K;
  std::cin >> K;

  long long int s = 1, d = 1;

  for (int i = 0; i < K; i++) {
    std::cout << s << std::endl;

    while (1.0 * (s + d) / S(s + d) > 1.0 * (s + 2 * d) / S(s + 2 * d)) {
      d *= 10;
    }

    s += d;
  }
}


Measured memory_bytes: 256
import java.util.*;
import java.awt.geom.*;
import java.io.*;
public class Main{
	//2320 start
	//2345 end
	//2356 sample match
	int [] vx = {0,1,0,-1};
	int [] vy = {1,0,-1,0};
	int w,h;
	int INF = 1 << 24;
	
	class C{
		int x,y,s,hp;

		public C(int x, int y, int s, int hp) {
			this.x = x;
			this.y = y;
			this.s = s;
			this.hp = hp;
		}

		@Override
		public String toString() {
			return "C [x=" + x + ", y=" + y + ", s=" + s + ", hp=" + hp + "]";
		}
		
	}
	
	private void doit(){
		Scanner sc = new Scanner(System.in);
		while(true){
			w = sc.nextInt();
			h = sc.nextInt();
			if((w|h) == 0) break;
			int [][] data = new int[h][w];
			int sx = -1, sy = -1;
			for(int i = 0; i < h; i++){
				for(int j = 0; j < w; j++){
					data[i][j] = sc.nextInt();
					if(data[i][j] == 2){
						data[i][j] = 1;
						sx = j;
						sy = i;
					}
				}
			}
			
			LinkedList<C> open = new LinkedList<C>();
			open.add(new C(sx,sy,0,6));
			boolean [][][] close = new boolean[h][w][7];
			Arrays.fill(close[sy][sx], true);
			
			int ans = INF;
			boolean flg = false;
			while(! open.isEmpty()){
				C now = open.removeFirst();
				//System.out.println(now);
				//System.out.println("debug = " + close[4][2][6] + " " + close[4][2][5]);
				for(int i = 0; i < 4; i++){
					int xx = now.x + vx[i];
					int yy = now.y + vy[i];
					int nextHP = now.hp - 1;
					int nexts = now.s + 1;
					if(nextHP == 0) break;
					if(! isOK(xx,yy)) continue;
					if(data[yy][xx] == 0) continue;
					if(close[yy][xx][nextHP])continue;
					
					if(data[yy][xx] == 3){
						ans = nexts;
						flg = true;
						break;
					}
					
					if(data[yy][xx] == 4){
						nextHP = 6;
					}
					//NextHp以下をtrueにすればよい？
					for(int j = nextHP; j >= 0; j--){
						//System.out.println("yy = " + yy + " xx = " + xx +  " " + nextHP);
						close[yy][xx][j] = true;
					}
					open.add(new C(xx,yy,nexts,nextHP));
				}
				if(flg) break;
			}
			System.out.println(ans == INF ? -1 : ans);
		}
		
		
	}

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

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

Measured memory_bytes: 12000
import bisect
from operator import itemgetter
import math
import copy
import collections
import functools
import itertools
import numpy as np
import sys
MAX_INT = int(10e10)
MIN_INT = -MAX_INT
mod = 1000000007
sys.setrecursionlimit(1000000)
def IL(): return list(map(int,input().split()))
def SL(): return input().split()
def I(): return int(sys.stdin.readline())
def S(): return input()

N,A,B = IL()

print(min(N*A,B))

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

using namespace std;

#define MOD 1000000007
#define ll long long int
#define ld long double
#define pb push_back
#define mkp make_pair
#define pii pair<int, int> 
#define pll pair<long long int, long long int>
#define sci(x) scanf("%d", &x)
#define scl(x) scanf("%lld", &x)
#define fi first
#define sc second
#define deb 0

int A[1000000];

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

	int n, i, j, k, x;

	i = 300000;
	j = i+1;

	cin >> n;
	for (k = 0; k < n; ++k) {
		cin >> x;
		if (k&1) A[i--] = x;
		else A[j++] = x;
	}

	if (n&1) {
		for (k = j-1; k > i; --k) cout << A[k] << " ";
		cout << endl;
	} else {
		for (k = i+1; k < j; ++k) cout << A[k] << " ";
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 2944
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
  int n,k,h[200001];
  long long int ans=0;
  cin>>n>>k;
  if(n<=k)ans=0;
  else{
    
    for(int i=0;i<n;i++){
      cin>>h[i];
    }
 
    sort(&h[0],&h[n]);
    for(int i=0;i<n-k;i++){
      ans+=h[i];
    }
  }
  cout<<ans<<endl;
  return 0;
}

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

using namespace std;

const int maxn = 2e5 + 10;
int a[maxn], n;

int main()
{
    ios::sync_with_stdio(false);
    cin >> n;

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

    int ans = n + 1;
    for (int i = 0, need = 1; i < n; i++)
        if (a[i] == need)
            ans = need++;

    cout << n - ans;

    return 0;
}


Measured memory_bytes: 1024
#atcoder template
def main():
    import sys
    imput = sys.stdin.readline
    if sys.argv[-1] == 'ONLINE_JUDGE':
        import numba
        from numba.pycc import CC
        i8 = numba.int64
        cc = CC('my_module')
 
        def cc_export(f, signature):
            cc.export(f.__name__, signature)(f)
            return numba.njit(f)
 
            fact_table = cc_export(fact_table, (i8, i8))
            main = cc_export(main, (i8, i8, i8))
            cc.compile()

    #文字列入力の時は上記はerrorとなる。
    #ここにコード
    #input
    n, m = map(int, input().split())

    #output
    mod = pow(10, 9) + 7

    n_ = 5 * pow(10, 5) + 5
    fun = [1] * (n_+1)
    for i in range(1, n_+1):
        fun[i] = fun[i-1] * i % mod
    rev = [1] * (n_+1)
    rev[n_] = pow(fun[n_], mod-2, mod)
    for i in range(n_-1, 0, -1):
        rev[i] = rev[i+1] * (i+1) % mod
    def cmb(n,r):
        if n < 0 or r < 0 or r > n: return 0
        return fun[n] * rev[r] % mod * rev[n-r] % mod
    def perm(n, r):
        if n < 0 or r < 0 or r > n: return 0
        return fun[n] * rev[n-r] % mod

    #Aを1, 2, ..., nとする。
    #求める写像の総数をs(n, m)とする。
    #s(n, m) = sum(k=0, n)(cmb(n, k)* (-1)^k * cmb(m-k, n-k)*(n-k)!)

    import math
    answer = 0
    for i in range(n+1):
        temp = perm(n, i) * cmb(m, i) * pow(perm(m-i, n-i), 2)
        temp %= mod
        if i % 2 == 0:
            answer += temp
        else:
            answer -= temp
    print(answer % mod)

    #N = 1のときなどcorner caseを確認！
if __name__ == "__main__":
    main()


Measured memory_bytes: 48400
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define LI list<int>
#define vct vector
#define D(a) (double)(a)
#define vi vct<int>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vvi vct<vi>
#define vll vct<ll>
#define vvll vct<vll>
#define vpii vct<pii>
#define vpll vct<pll>
#define vb vct<bool>
#define vs vector<string>
#define all(a) a.begin(),a.end()
#define allr(a) a.rbegin(),a.rend()
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define ff first
#define ss second
#define bg begin()
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define ft cout<<"for test"<<endl;
#define read(v,a,n) for(int i=a; i<n; i++)cin>>v[i];
#define print(v) for(auto it:v)cout<<it<<' '; cout<<endl;
#define PI acos(-1.0)
#define yes cout<<"YES"<<endl
#define no cout<<"NO"<<endl
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define t_c int test,cs=1;cin>>test;while(test--)
#define rt return true
#define rf return false
///................function.....................///
#define siz(s) (int)(s.size())
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define mod 1000000007
int main()
{
    FIO;
    ll x,k,d;
    cin>>x>>k>>d;
    if(x==0)
    {
        if(k&1)
            cout<<d<<endl;
        else cout<<0<<endl;
        return 0;
    }
    ll dis = abs(x);
    dis/=d;
    if(k<=dis)
    {
        (x<0)?x+=k*d:x-=k*d;
        cout<<abs(x)<<endl;
    }
    else
    {
        k-=dis;
        (x<0)?x+=dis*d:x-=dis*d;
        if(k&1)
        {
            (x<0)?x+=d:x-=d;
            cout<<abs(x)<<endl;
        }
        else
        {
            cout<<abs(x)<<endl;
        }
    }
}


Measured memory_bytes: 3636
# import bisect
# from collections import Counter, deque
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter
# import math

import sys

# import numpy as np

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)

def main():
    n, a, b = list(map(int,ipti().split()))
    ab = a + b

    c = n // ab
    d = n % ab

    ans = c * a + min(a, d)
    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 38384
n = int(input())
a = list(map(int, input().split()))

s = sum(a)
sodd = 0
for i in range(n):
    if i % 2 == 1:
        sodd += a[i]

x = [0] * n

x[0] = s - 2 * sodd

for i in range(1, n):
    x[i] = 2 * a[i - 1] - x[i - 1]

print(*x)

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

#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
#define REP(i,a,b) for (int i = a; i <= b; i++)
using namespace std;
long long maxv = 1e9;

int main()
{
    typedef vector<int> vi;

    int N,M;
    cin>>N>>M;
    vi arr(M);
    if(N>M){
        cout<<0;
        return 0;
    }else{
        REP(i,0,M-1){
            cin>>arr[i];
        }
        sort(arr.begin(), arr.end());
        vi diff(M-1);
        REP(i,0,M-1-1){
            diff[i]=arr[i+1]-arr[i];
        }
        sort(diff.begin(), diff.end());
        int ans=0;
        REP(i,0,M-N-1){
            ans+=diff[i];
        }
        cout<<ans;
    }
}

Measured memory_bytes: 3928
#include <iostream>
#include<algorithm>
#include<set>
#include<queue>
#define rep(i,j,n) for(int i=j;i<n;i++)
using namespace std;
#define int long long
int mul[214514];
int divi[214514];
#define inf 1000000007
int bit[114514],n;
struct edge{int u,v,cost;};
edge es[214514];
int zero=0;
string alph("abcdefghijklmnopqrstuvwxyz");
signed main(){
    int n,h;cin>>n>>h;
    int a[114514],b[114514];
    int maxi=-1;
    int key=-1;
    int count=0;
    rep(i,0,n){
        cin>>a[i]>>b[i];
        if(maxi<a[i]){
            maxi=a[i];
            key=i;
        }
    }
    sort(b,b+n);
    reverse(b,b+n);
    rep(i,0,n){
        if(b[i]>=maxi){
            count++;
            h-=b[i];
        }
        if(h<=0){
            cout<<count<<endl;
            return 0;
        }
    }
    int  de=(h+maxi-1)/maxi;
    cout<<count+de<<endl;
    return 0;
}


Measured memory_bytes: 1792
import java.util.*;

public class Main {

	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		String n = sc.next();
		int a = n.charAt(0) - '0';
		int b = n.charAt(1) - '0';
		int c = n.charAt(2) - '0';
		int d = n.charAt(3) - '0';
		int[] v = new int[]{1, -1};
		String[] op = new String[]{"+", "-"};
		for (int i = 0; i < v.length; i++) {
			for (int j = 0; j < v.length; j++) {
				for (int k = 0; k < v.length; k++) {
					if (a + b * v[i] + c * v[j] + d * v[k] == 7) {
						StringBuilder sb = new StringBuilder();
						sb.append(a).append(op[i]).append(b).append(op[j]).append(c).append(op[k]).append(d).append("=7");
						System.out.println(sb);
						return;
					}
				}
			}
		}
	}
}


Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
struct edge {
    long long from;
    long long to;
    long long cost;
};

void funcD() {
    bool inf = false;
    int N, M;
    cin >> N >> M;

    vector<edge> E(M);
    vector<long long> d(N + 1, LONG_LONG_MAX);
    d[1] = 0;
    for(int i = 0; i < M; i++) {
        cin >> E[i].from >> E[i].to >> E[i].cost;
        E[i].cost *= -1;
    }
    long long prev_d = 0;
    rep(i, N) {
        rep(j, E.size()) {
            if(d[E[j].from] != LONG_LONG_MAX &&
               d[E[j].to] > d[E[j].from] + E[j].cost) {
                d[E[j].to] = d[E[j].from] + E[j].cost;
                if(i == N - 1 && E[j].to == N) {
                    inf = true;
                }
            }
        }
    }

    if(inf) {
        cout << "inf";
    } else {
        cout << -d[N];
    }
}

int main() {

    funcD();

    return 0;
}

Measured memory_bytes: 256
w,h,n=gets.split.map &:to_i;
$a=Array.new(w).map{Array.new(h,1)};
n.times{
	x,y,t=gets.split.map &:to_i;
	if t==1 then
		(0...x).map{|i|
			(0...h).map{|j|
				$a[i][j]=0;
			}
		}
	elsif t==2 then
		(x...w).map{|i|
			(0...h).map{|j|
				$a[i][j]=0;
			}
		}
	elsif t==3 then
		(0...y).map{|j|
			(0...w).map{|i|
				$a[i][j]=0;
			}
		}
	elsif t==4 then
		(y...h).map{|j|
			(0...w).map{|i|
				$a[i][j]=0;
			}
		}
	end
}
c=0;
(0...w).map{|i|
	(0...h).map{|j|
		c+=$a[i][j];
	}
}
p c

Measured memory_bytes: 6268
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <iostream>

const int N = 1e5 + 7;

int n, k;
std::vector<int> adj[N];
int answer = 0;
int dist[N];

int dfs(int u) {
	dist[u] = 0;
	for (auto v : adj[u]) {
		dfs(v);
		if (dist[v] + 1 == k && u != 1) {
			//printf("v = %d\n", v);
			dist[v] = -1;
			answer++;
		} else {
			dist[u] = std::max(dist[u], dist[v] + 1);
		}
	}
}

int main() {
	scanf("%d %d", &n, &k);
	for (int i = 1; i <= n; i++) {
		int target;
		scanf("%d", &target);
		if (i == 1) {
			answer += (target != 1);			
		} else {
			adj[target].push_back(i);
		}
	}
	
	dfs(1);
	std::cout << answer << std::endl;
	return 0;
}

Measured memory_bytes: 10752
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
 /* #ifndef ONLINE_JUDGE
      // for getting input from input.txt
      freopen("input.txt", "r", stdin);
      // for writing output to output.txt
      freopen("output.txt", "w", stdout);
  #endif*/
fast();
//ll  t;cin>>t;while(t--)
{
  int a,b;
  cin>>a>>b;
  cout<<(a+b)%24<<endl;

}
return 0;
}


Measured memory_bytes: 256
macro_rules! get {
    (Vec<$t:ty>) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let N = get!(i64);
    let a = get!(Vec<usize>);

    let mut dp = vec!(0; 100001);
    for x in a {
        dp[x] += 1;
        dp[x + 1] += 1;
        if x >= 1 {
            dp[x - 1] += 1;
        }
    }
    let ans = dp.iter().max().unwrap();

    println!("{}", ans);
}

Measured memory_bytes: 6396
object Main extends App {
    var get = readLine
    var n = get.split(" ")(0).toInt
    var m = get.split(" ")(1).toInt
    var c = get.split(" ")(2).toInt

    var get2 = readLine
	val b = new Array[Int](m)
    var get3 = readLine
    var a = new Array[Int](m)
    var ans=0
  	for(loop <- 0 to m - 1) {
	  b(loop)=get2.split(" ")(loop).toInt
    }
  	for(loop <- 0 to n - 1){
      var sum=0
      for(loop2 <- 0 to m - 1){
        sum+=b(loop2)*get3.split(" ")(loop2).toInt
      }
      if(sum+c>0)
      	ans+=1
      get3 = readLine
    }      
  println(ans)
}

Measured memory_bytes: 27328
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <cstring>
#include <map>
#include <queue>
#include <cmath>
#include <complex> // complex<double> a(1.2 , 2.3);// real(): 1.2, imag()2.3
using namespace std;

#define MOD 1000000007
#define ll long long
#define ld long double
#define FOR(i,a,b) for(ll i=(ll)a;i<(ll)b;i++)
#define rep(i,n) FOR(i,0,n)
#define pb push_back
#define mp make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rmsame(a) sort(all(a)),a.erase(unique(all(a)), a.end())
#define rmvector(a,b) rep(i,a.size())rep(j,b.size())if(a[i]==b[j]){a.erase(a.begin()+i);i--;break;}
template<typename X> bool exist(vector<X> vec, X item){return find(all(vec), item)!=vec.end();}
ll gcd(ll a, ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a, ll b){return a/gcd(a,b)*b;}


bool check[26];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);

  string str; cin >> str;

  rep(i, str.size())
    check[str[i]-'a'] = true;

  
  ll ans = 10000;
  rep(times,26){
    if(check[times] == false) continue;
    ll ret = 0;
    string now = str;
    
    
    while(1){
      string cpr = "";rep(i,now.size()){cpr += (times + 'a');}
      if(cpr == now) break;
      string nxt = "";
      rep(i,now.size()-1){
	if((now[i] == (times + 'a')) || (now[i+1] == times + 'a') )nxt += (times + 'a');
	else nxt += now[i];
      }
      now = "";
      now = nxt;
      ret ++;
    }
    ans = min(ans, ret);
  }

  cout << ans << endl;
  //cout << fixed << setprecision(16) << ans << endl;
  return 0;
}


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

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

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

int A, B, C;

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

    std::cin >> A >> B >> C;

    int res = (C / A) * B;
    std::cout << res << std::endl;
}


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

ll gcd(ll a,ll b){
    if(b == 0) return a;
    return(b,a%b);
}
/*
*/


int main() {
  ll R,G,B,N;
  cin >> R >> G >> B >> N;
  ll count = 0;
  for(ll r = 0;r<=3000;r++){
      for(ll g = 0;g<=3000;g++){
          ll b = (N - r*R - g*G)/B;
          if(b >= 0 && b <= 3000 && (N - r*R - g*G)%B == 0) count++;
      }
  }
  cout << count << endl;
 }

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int ar[200001];
int main() {
   
    int n, k;
    cin >> n >> k;
    
    for (int i = 0; i < n; i++) {
        int t;
        cin >> t;
        ar[t]++;
    }
    
    sort(ar+1, ar+n, greater<int>());
    
    int t = 0, ans = 0;
    for (int i = 1; i <= n; i++) {
        if (ar[i] != 0)
            t++;
        
        if (t == k) {
            for (int j = i +1; j <=n; j++)
                ans += ar[j];
            cout << ans << endl;
            return 0;
        }
    }
    if (t < k)
        cout << 0 << endl;
    
    return 0;
}


Measured memory_bytes: 1024
d=[[c=0]*26]
s=gets.chop.bytes.reverse.each{|c|*x=d[-1]
x[c-97]=x.min+1
d<<x}
(i=97+c=d[-1].index(d[-1].min);$><<i.chr;(c=s.pop;d.pop)while c&&c!=i)while c

Measured memory_bytes: 63288
#include<bits/stdc++.h>
using namespace std;
#define reg register
#define ll long long
#define maxn 200005
#define mo 1000000007
inline ll read()
{
	ll x=0,w=0;char ch=getchar();
	while(!isdigit(ch))w|=ch=='-',ch=getchar();
	while(isdigit(ch))x=(x<<3)+(x<<1)+(ch^48),ch=getchar();
	return w?-x:x;
}
vector<int>A[maxn];
vector<int>G[maxn];
int n,tot;
int jc[maxn],ans[maxn],inst[maxn];
int vis[maxn],vis1[maxn],fa[maxn],huan[maxn],size[maxn];
int headd[maxn],nextt[maxn<<1],to[maxn<<1],cntt;
inline int ksm(int x,int y)
{
    int a=1;
    while(y)
    {
        if(y&1)a=1ll*a*x%mo;
        x=1ll*x*x%mo;y>>=1;
    }return a;
}
inline void add(int u,int v)
{nextt[++cntt]=headd[u];headd[u]=cntt;to[cntt]=v;}
inline void dfs(int u,int f)
{
    vis[u]=tot;A[tot].push_back(u);fa[u]=f;inst[u]=1;
    for(reg int i=headd[u];i;i=nextt[i])
    {
        if(to[i]==f)continue;
        if(vis[to[i]]){if(inst[to[i]])huan[fa[to[i]]]=-1,huan[u]++;}
        else dfs(to[i],u),huan[u]+=huan[to[i]];
    }inst[u]=0;
}
inline void dfs1(int u,int f)
{
    for(reg int i=headd[u];i;i=nextt[i])
    {
        if(to[i]==f)continue;
        if(huan[to[i]]==1)continue;
        fa[to[i]]=u;dfs1(to[i],u);
    }
}
inline void dfs2(int u)
{
    reg int i,sz=G[u].size();
    size[u]=1;vis1[u]=1;
    for(i=0;i<sz;++i)
    {
        if(!vis1[G[u][i]])dfs2(G[u][i]);
        size[u]+=size[G[u][i]];
    }
}
inline void solve1()
{
    reg int i,j,u,sz=A[tot].size();
    for(j=0;j<sz;++j)
    {
        u=A[tot][j];G[u].clear();
        for(i=headd[u];i;i=nextt[i])
        {
            if(fa[to[i]]!=u)continue;
            if(to[i]<fa[u])G[u].push_back(to[i]);
        }
    }
    for(i=0;i<sz;++i)
        if(!vis1[A[tot][i]])
            dfs2(A[tot][i]);
    for(i=0;i<sz;++i)vis1[A[tot][i]]=0;
    reg int tmp=1;
    for(i=0;i<sz;++i)tmp=1ll*tmp*size[A[tot][i]]%mo;
    ans[tot]+=1ll*jc[sz]*ksm(tmp,mo-2)%mo;if(ans[tot]>=mo)ans[tot]-=mo;
}
inline void solve()
{
    reg int i,sz=A[tot].size(),fi,k;
    for(i=0;i<sz;++i)
        if(huan[A[tot][i]]==1){fi=A[tot][i];break;}
    k=fi;
    for(i=0;i<sz;++i)fa[A[tot][i]]=0;
    do
    {
        dfs1(k,0);
        for(i=headd[k];i;i=nextt[i])
            if(huan[to[i]]==1&&fa[to[i]]!=k){fa[k]=to[i];k=to[i];break;}
    }while(fi!=k);solve1();k=fi;
    for(i=0;i<sz;++i)fa[A[tot][i]]=0;
    do
    {
        dfs1(k,0);
        for(i=headd[k];i;i=nextt[i])
            if(huan[to[i]]==1&&fa[k]!=to[i]){fa[to[i]]=k;k=to[i];break;}
    }while(fi!=k);solve1();
}
int ha[maxn],ha1[maxn];
int main()
{
    n=read();reg int i,x,y;jc[0]=1;
    for(i=1;i<=2*n;++i)jc[i]=1ll*jc[i-1]*i%mo;
    for(i=1;i<=2*n;++i)
    {
        x=read(),y=read();ha[x]=1;ha1[y]=1;
        add(x,n+y),add(n+y,x);
    }
    for(i=1;i<=n;++i)if(!ha[i]){puts("0");return 0;}
    for(i=1;i<=n;++i)if(!ha1[i]){puts("0");return 0;}
    for(i=1;i<=n*2;++i)if(!vis[i])
        ++tot,dfs(i,0),solve();
    reg int sum=1,su=1;
    for(i=1;i<=tot;++i)sum=1ll*sum*ans[i]%mo;
    for(i=1;i<=tot;++i)su=1ll*su*jc[A[i].size()]%mo;
    sum=1ll*sum*jc[2*n]%mo*ksm(su,mo-2)%mo;
    printf("%d\n",sum);
	return 0;
}


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

int main() {
	int N; cin >> N;
  	int V[N], C[N];
  	for (int i = 0; i < N; ++i) {
      	int vv; cin >> vv;
    	V[i] = vv;
    }
  	for (int i = 0; i < N; ++i) {
      	int cc; cin >> cc;
    	C[i] = cc;
    }
    int ans = 0;
  	for (int i = 0; i < N; ++i) {
      	if (V[i] > C[i]) ans += V[i] - C[i];
    }
  	cout << ans << endl;
}

Measured memory_bytes: 256
#define _USE_NATH_DEFINES
#include<cstdio>
#include <iostream>
#include<sstream>
#include<fstream>
#include<iomanip>
#include<algorithm>
#include<cmath>
#include<complex>
#include <string>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<numeric>
#include<limits>
#include<climits>
#include<cfloat>
#include<functional>
#include<iterator>
using namespace std;

int main() {
	int m;
	cin >> m;
	cout << (24 - m) + 24 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>

using namespace std;

int abs(int a, int b){
if( a >= b){return a - b;}
  else{return b - a;}}


int main(){
  int N; cin >> N;
  vector<int> A(N);
  for(int i = 0 ; i < N; i++){
    cin >> A[i];}
  int max_diff = 0;
  for(int i = 0; i < N; i++){
    for(int j = 0; j < N; j++){
      max_diff = max(max_diff,abs(A[i],A[j]));}}
                     
                     cout << max_diff << endl;
                     
                     return 0;
                     }
                                  

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if(a+b==c+d){
    cout<<"Balanced"<<endl;
  }else if(a+b<c+d){
    cout<<"Right"<<endl;
  }else{
    cout<<"Left"<<endl;
  }

  return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <iomanip>

int main(){
    int n;
    std::cin >> n;

    std::cout << std::fixed << std::setprecision(10) << (double)(n - n / 2) / n << std::endl;

    return 0;
}

Measured memory_bytes: 3740
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=(a); i<(b); i++)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
typedef long long ll;
int main(){
    int n; cin >> n;
    vector<double> x(n),y(n);
    vector<int> v(n);
    double ans = 0.0;
    rep(i,n){
        cin >> x[i] >> y[i];
    }
    iota(ALL(v), 0);
    do{
        FOR(i,1,n) ans += (double)(sqrt((x[v[i]] - x[v[i-1]])*(x[v[i]] - x[v[i-1]]) + (y[v[i]] - y[v[i-1]])*(y[v[i]] - y[v[i-1]])));
    } while(next_permutation(ALL(v)));
    double r = 1.0;
    rep(i,n) r *= (double)(i+1);
    ans /= r;
    printf("%.10f\n", ans);
}

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

int main() {
  int N,L;
  cin>>N>>L;
  std::vector<string> v(N);
  for(int i=0;i<N;i++)cin>>v[i];
  sort(v.begin(),v.end());
  for(int i=0;i<N;i++)cout<<v[i];
  cout<<endl;
}


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

#define fi first
#define se second
#define be begin
#define en end
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ALL(a) (a).be() , (a).en()
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)        //repeat n times
#define REP2(i,s,n) for(int (i)=(s);(i)<(n);(i)++)   //repeat from s to n 
#define REPD(i,n) for(int (i)=(n);(i)>=0;(i)--)      //repeat from n to 0
#define REPD2(i,s,e) for(int (i)=(s);(i)>=(e);(i)--) //repeat from s to e
#define RANGE(i,v) for(auto &(i):v)                  //repeat range
#define ASIZE(a) (sizeof(a) / sizeof(a[0]))          //array size

using LL = long long;

const LL INFLL = 999999999999999LL;
const int INF = 1999999999;

template<typename T1,typename T2> using P = pair< T1, T2 >;
using Pii = P<int,int>;
using Pll = P<LL,LL>;

template<typename T> using V = vector< T >;
using Vi = V<int>;
using Vll = V<LL>;

struct edge{
	int src; int dst; LL weight;
	edge() : src(0), dst(0), weight(0) {}
	edge(int s, int d, LL w) : src(s), dst(d), weight(w) {}
};
 
using edges = V<edge>;
using graph = V<edges>;
 
void add_edge(edges &g,int s, int d, LL w=1){g.pb(edge(s,d,w));}
void add_edge(graph &g,int s, int d, LL w=1){g[s].pb(edge(s,d,w));}

 
Vll dijkstra(graph &g,int s){
	int i,j,k; int n=g.size(); int visit[n]; Vll dist(n);
	priority_queue<Pll,V<Pll>,greater<Pll>> q;
	REP(i,n){visit[i]=0; dist[i]=INFLL/2;}
	dist[s]=0;
	q.push(mp(0,s));
	int nv; LL min_cost=0;
	while(!q.empty()){
		LL d,t; tie(d,t)=q.top(); q.pop();
		if(visit[t]==1){continue;}
		visit[t]=1; dist[t]=d;
		for(auto &e:g[t]){
			if(dist[e.dst]<=d+e.weight){continue;}
			q.push(mp(d+e.weight,e.dst));
		}
	}
	return dist;
}
 
int main(){
	int n,m;
	scanf("%d %d",&n,&m);
	// cin>>n>>m;

	int l[m],r[m],c[m];
	for(int i=0; i<m; i++){
		// cin>>l[i]>>r[i]>>c[i];
		scanf("%d %d %d",&l[i],&r[i],&c[i]);
	}

	graph g(n);	

	for(int i=0; i<m; i++){
		add_edge(g,l[i]-1,r[i]-1,c[i]);	
	}

	for(int i=0; i<n-1; i++){
		add_edge(g,i+1,i,0);	
	}

	Vll dist = dijkstra(g,0);
	// cout<<endl;
	// for(int i=0; i<dist.size(); i++){
	// 	cout<<i<<" "<<dist[i]<<endl;
	// }
	if(dist[n-1]!=INFLL/2){
		printf("%lld\n",dist[n-1]);
		// cout<<dist[n-1]<<endl;
	}else{
		printf("%lld\n",-1LL);
		// cout<<-1<<endl;
	}

	return 0;
}

Measured memory_bytes: 11380
#include <bits/stdc++.h>
using namespace std;
int main() {
    string s;
    int sum = 0;
    cin >> s;
    while(s.at(0) != '0') {
        for(int i=0;i<s.size();i++) sum += s.at(i) - '0';
        printf("%d\n", sum);
        sum = 0;
        cin >> s;
    }
}


Measured memory_bytes: 3352