akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();

		if(A == B ) {
			System.out.println(C);
		} else if(B == C) {
			System.out.println(A);
		} else {
			System.out.println(B);
		}


	}
}

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define POSSIBLE cout << ((n) ? "POSSIBLE\n" : "IMPOSSIBLE\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int64 a,b;
  int32 bl,br;
  char c;
  cin >> a >> bl >> c >> br;
  b = bl * 100 + br;
  int64 ans = a * b;
  ans /= 100;
  ANS(ans);
  return 0;
}

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

using namespace std;

  int n,p,a[51];

bool check(int x){
  for(int i=0;i<n;i++)if(a[i]>0 && i!=x)return false;
  return true;
}

int main(void){

  while(cin >> n >> p,n|p){
    fill(a,a+51,0);

    for(int i=0;i<1000001;i++){

      if(p>0)p--,a[i%n]++;
      else if(p==0 ){
	if(check(i%n)){
	  cout << i%n << endl;
	  break;
	}
	p=a[i%n],a[i%n]=0;
      }
    }
  }

  return 0;
}

Measured memory_bytes: 1160
#include <iostream>
using namespace std;
string S;
long cnt[2019];
int main() {
  cin>>S;
  int now=0;
  long ans=0,p=1,pi=1;
  cnt[0]=1;
  for (int i=S.size();i--;) {
    now = (now+(S[i]-'0')*p) % 2019;
    ans += cnt[now]++;
    p = p * 10%2019;
  }
  cout<<ans<<endl;
  return 0;
}

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

int main(){
    int N, K;
    cin >> N >> K;
    vector<long long> tests(N);
    for (int i = 0; i < N; i++) {
        cin >> tests[i];
    }

    for (int i = K; i < N; i++) {
        if (tests[i] > tests[i-K]) cout << "Yes" << endl;
        else cout << "No" << endl;
    }

}

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

using namespace std;

const int N = 1e5 + 10;

long long a[N];
long long dp[N];

int main() {

    int n;
    cin >> n;
    for(int i = 1 ; i <= n ; i++)cin >> a[i];
 
    dp[2] = abs(a[2] - a[1]);
    for(int i = 3 ; i <= n ; i++) {
        dp[i] = min(dp[i - 1] + abs(a[i] - a[i - 1]), dp[i - 2] + abs(a[i] - a[i - 2]));
    }

    cout << dp[n] << '\n';

    return 0;
}

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

int main()
{
    int k, x;
    cin >> k >> x;

    vector<int> ans(2*k-1);
    for(int i=0; i<2*k-1; ++i)
        ans[i] = x - k + 1 + i;

    cout << ans[0];
    for(int i=1; i<2*k-1; ++i)
        cout << ' ' << ans[i];
    cout << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<algorithm>
#include<cassert>
#include<vector>
#include<cstring>
using namespace std;

int dp[1000], catsum[20010];
vector<pair< int, int > > cats;
vector<int> foods;
int N,M,lmost;

bool isable(int mid) {
    memset(dp, -1, sizeof(dp));

    for(int i=M-1; i>=0; --i) {
        if(i == M-1) {
            dp[i] = 0;
            continue;
        }
        int ret = 1<<29;
        for(int j=i+1; j<M; ++j) {
            int right = catsum[foods[j]] - catsum[(foods[i]+foods[j])/2];;
            int left = catsum[(foods[i]+foods[j])/2] - catsum[foods[i]];

            //cout<<i<<" "<<j<<" "<<right<<" "<<left<<endl;
            if(right + dp[j] <= mid) ret = min(left, ret);
        }
        dp[i] = ret;
    }
    if(dp[0] + lmost <= mid) return true;
    return false;
}

int main() {
    int x,y,c,totalcats = 0;
    while(cin>>N>>M, N|M) {

        memset(catsum, 0, sizeof(catsum));
        foods.clear();
        cats.clear();
        totalcats = 0;

        for(int i=0; i<N; ++i) {
            cin>>x>>y>>c;
            x += 10000;
            totalcats += c;
            cats.push_back(make_pair(x,c));
        }

        for(int i=0; i<M; ++i) {
            cin>>c;
            foods.push_back(c+10000);
        }

        if(M == 1) {
            cout<<totalcats<<endl;
            continue;
        }

        sort(cats.begin(), cats.end());
        sort(foods.begin(), foods.end());

        //êÔ¶Ì¦³¢êæè¶ÌLð¦³¢êÌªÉ í¹é
        //Eà¯l
        lmost = 0;
        for(int i=0; i<N; ++i) {

            if(cats[i].first <= foods[0]) {
                cats[i].first = foods[0];
                lmost += cats[i].second;
            }
            if(cats[i].first >= foods[M-1]) cats[i].first = foods[M-1];
            catsum[cats[i].first] += cats[i].second;
            //cout<<"add "<<cats[i].first<<endl;
        }

        int ss = 0;
        for(int i=0; i<20010; ++i) {
            ss += catsum[i];
            catsum[i] = ss;
        }

        int low = -1,hi = totalcats;
        while(low+1<hi) {
            int mid = (low+hi)/2;
            //cout<<mid<<" "<<low<<" "<<hi<<endl;
            if(isable(mid)) hi = mid;
            else low = mid;
        }
        cout<<hi<<endl;
    }
}

Measured memory_bytes: 1020
from collections import defaultdict


N,K = map(int, input().split())
A = list(map(int, input().split()))

d = defaultdict(int)
# 先頭からiビット目に1が立っている個数を数え上げる
for a in A:
    for i in range(50):
        if a & (1 << i):
            d[i] += 1
dp = [[-1 for _ in range(2)] for _ in range(51)]
dp[0][0] = 0

# 頭からi桁
for i in range(50):


    # 先頭からi番目の位置の数字
    if K & (1 << (50-i-1)):
        digit = 1
    else:
        digit = 0

    # i桁目に1を選んだ時
    use_1 = (N-d[50-i-1]) * (1 << (50-i-1))
    # i桁目に0を選んだ時
    use_0 = d[50-i-1] * (1 << (50-i-1))

    if K < (1 << (50-i-1)):
        use_1 = 0

    """
    i-1桁までがKより小さい場合、0,1どちらも選択可能
    dp[i][1] == -1 だとそれは起こりえない
    """
    if dp[i][1] != -1:
        dp[i+1][1] =  dp[i][1] + max(use_0, use_1)

    """
    i-1桁まで同じで、i桁目でKより小さくなる場合（Kのi桁目が1で0を選択）
    ここでmax(dp[i+1][1], ～)にしてあげないと、上で決めたものが上書きされてしまう
    """
    if dp[i][0] != -1:
        if digit == 1:
            dp[i+1][1] = max(dp[i+1][1], dp[i][0] + use_0)

    """
    i-1桁まで同じで、i桁目でKとまた一致する場合
    ここのmax~はいらないと思う
    """
    if dp[i][0] != -1:
        if digit == 1:
            dp[i+1][0] = max(dp[i+1][0], dp[i][0] + use_1)
        else:
            dp[i+1][0] = max(dp[i+1][0], dp[i][0] + use_0)

print(max(dp[-1]))


Measured memory_bytes: 68696
#include <stdio.h>
#define MAX 100000

int Partition(int A[] ,int ,int );
int A[MAX];

int main(){

  int n,x,i,j;

  scanf("%d",&n);

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

  x = Partition(A,0,n-1);

  for(i=0;i<n;i++){
    if(i!=0) printf(" ");
    if(i==x) printf("[%d]",A[i]);
    else printf("%d",A[i]);
  }
 
  printf("\n");

  return 0;
}
int Partition(int A[] ,int p,int r){

  int x,tmp,i,j;

  x = A[r];
  i = p-1;

  for(j=p;j<r;j++){
    if(A[j]<=x){
      i++;
      tmp = A[i];
      A[i] = A[j];
      A[j] = tmp; 
    }
  }
    tmp=A[i+1];
    A[i+1]=A[r];
    A[r]=tmp;

    return i+1;
}

Measured memory_bytes: 988
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define zero_pad(num) setfill('0') << std::right << setw(num)
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;

int main() {
	int n;
	cin >> n;
	if (n < 1000) cout << "ABC" << endl;
	else cout << "ABD" << endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb          emplace_back
#define ll          long long
#define fi          first
#define se          second
#define mp          make_pair

using namespace std;

const int N = 507;
typedef pair<int, int> pii;
const int mod = int(1e9) + 7;

int mul(int x, int y) {return 1ll * x * y % mod;}
void add(int& x, int y) {
    x += y;
    if(x >= mod) x -= mod;
    if(x < 0) x += mod;
}
int Pow(int x, int y) {
    int res = 1;
    while(y) {
        if(y & 1) res = mul(res, x);
        x = mul(x, x); y >>= 1;
    }
    return res;
}

int Sum[N][N], f[N][N];
int n, c, a[N], b[N];

int Get(int l, int r, int c) {
    int res = Sum[c][r];
    add(res, -Sum[c][l - 1]);
    return res;
}

int32_t main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    #define Task        "test"
    if(fopen(Task".inp", "r")) {
        freopen(Task".inp", "r", stdin);
        freopen(Task".out", "w", stdout);
    }
    for(int j = 0; j <= 400; ++j) {
        for(int i = 1; i <= 400; ++i) {
            Sum[j][i] = Sum[j][i - 1];
            add(Sum[j][i], Pow(i, j));
        }
    }
    cin >> n >> c;
    for(int i = 1; i <= n; ++i) cin >> a[i];
    for(int i = 1; i <= n; ++i) cin >> b[i];
    f[0][0] = 1;
    for(int i = 1; i <= n; ++i) {
        for(int j = 0; j <= c; ++j) {
            for(int k = 0; k <= j; ++k) add(f[i][j], mul(f[i - 1][j - k], Get(a[i], b[i], k)));
        }
    }
    cout << f[n][c];
}


Measured memory_bytes: 1920
#include <iostream>

using namespace std;

int main()
{
	int A, B, cnt=0;
	cin >> A; cin >> B;
	
	for (int i = A; i <= B; i++) {
		if (i == ((i % 10 * 10000) + (i / 10 % 10 * 1000) + (i / 100 % 10 * 100) + (i / 1000 % 10 * 10) + (i / 10000)))
			cnt++;
	}
	
	cout << cnt << endl;
	
	return 0;
}

Measured memory_bytes: 256
S=int(input())
L=[list(map(int,input().split())) for i in range(S)]
for i in range(S):
  if L[i][2]!=0:
    for cx in range(101):
      for cy in range(101):
        ans=0
        hpre=L[i][2]+abs(L[i][0]-cx)+abs(L[i][1]-cy)
        for j in range(S):
          if max(hpre-abs(cx-L[j][0])-abs(cy-L[j][1]),0)==L[j][2]:
            ans+=1
        if ans==S:
          print(cx,cy,hpre)
          exit()
        

Measured memory_bytes: 9184
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long [] in = new long [n];
        long [] ans = new long [n];
        long sum = 0;
        StringBuilder sb = new StringBuilder();
        for(int i=0;i<n;i++){
                             in[i] = sc.nextLong();
                             sum=sum^in[i];
        }
        for(int i=0;i<n;i++){ans[i]=sum^in[i];
                             sb.append(String.valueOf(ans[i]));
                             sb.append(" ");
                            }
       System.out.println(sb.toString());
		
	}
}

Measured memory_bytes: 63464
#!/usr/bin/env python

a,b,x=list( int(i) for i in input().split() )
count=0

if(a==b):
    if(a%x==0):
        print(1)
    else:
        print(0)
else:
    if(a%x==0):
        p=1
    else:
        p=0
    # print("a:", a, "b:", b, "x:", x, "p:", p)
    print(b//x-a//x+p)

Measured memory_bytes: 3060
E = ["S","H","C","D"]
n=int(input())
A=[[0 for j in range(14)] for i in range(4)]
for j in range(n):
	a,b=input().split()
	a=E.index(a)
	b=int(b)
	A[a][b]=1
	
for z in range(4):
	for c in range(1,14):
		if A[z][c]==0:
			print(f"{E[z]} {c}")


Measured memory_bytes: 5616
from numba import njit
@njit
def solve(n):
	fctrs=[0]*(n+1)
	ans=0
	for i in range(1,n+1):
		for j in range(i,n+1,i):
			fctrs[j]+=1
	for i in range(1,n+1):
		ans+=(i*fctrs[i])
	return ans
n=int(input())
print(solve(n))

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

#define ll long long
#define vvi vector< vector<int> >
#define vi vector<int>
#define All(X) X.begin(),X.end()
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define pi 3.14159265359
#define shosu(X) fixed << setprecision(X)
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
int dx[8] = {-1,-1,-1,0,0,1,1,1};
int dy[8] = {-1,0,1,1,-1,-1,0,1};
char data[100][100];
char ans[100][100];
int main(){
	int h,w;
	cin >> h >> w;
	REP(i,h){
		string s;
		cin >> s;
		REP(j,s.size()) {
			data[i][j] = s[j];
			ans[i][j] = s[j];
		}
	}
	REP(i,h){
		REP(j,w){
			if(data[i][j] != '.') continue;
			else ans[i][j] = '0';
			REP(k,8){
				int nx = i + dx[k];
				int ny = j + dy[k];
				if(nx < 0 || ny < 0 || nx >= h || ny >= w) continue;
				if(data[nx][ny] == '#') ans[i][j]++;
			}
		}
	}
	REP(i,h){
		REP(j,w){
			cout << ans[i][j];
		}
		cout << endl;
	}
}

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

int n;
long long d;
int ans=0;

int main(){
	cin >> n >> d;
	for (int i=0;i<n;i++){
		long long x, y;
		cin >> x >> y;
		if (x*x+y*y<=d*d) ans++;
	}
	cout << ans << "\n";
}

Measured memory_bytes: 3588
import java.util.*;

public class Main {

    Scanner sc = new Scanner(System.in);

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

    void run() {

        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] h = new int[n];
        for (int i=0; i<n; i++) h[i] = sc.nextInt();
        int[] dp = new int[n+1];
        for (int i=1; i<n+1; i++) dp[i] = Integer.MAX_VALUE;

        for (int i=0; i<n; i++) {
            for (int j=1; j<=k; j++) {
                if (i+j < n) dp[i+j] = Math.min(dp[i+j], (dp[i]+Math.abs(h[i+j]-h[i])));
            }
        }

        System.out.println(dp[n-1]);

    }
}




Measured memory_bytes: 52292
/* 
chirag11032000
Chirag Thakur
*/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;

template < typename T >
using ordered_set = tree < T, null_type, less < T >, rb_tree_tag, tree_order_statistics_node_update >;

typedef long long ll;
typedef double db;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;

#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template < typename Arg1 >
void __f(const char* name, Arg1&& arg1) {
	cerr << name << " : " << arg1 << std :: endl;
}
template < typename Arg1, typename... Args >
void __f(const char* names, Arg1&& arg1, Args&&... args) {
	const char* comma = strchr(names + 1, ',');
	cerr.write(names, comma - names) << " : " << arg1 << " | ";
	__f(comma + 1, args...);
}
#else
#define trace(...)
#endif

#define pb push_back
#define fast_io() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)

const db PI = acos(-1);
const ll MOD = 1e9 + 7, INF = LLONG_MAX;
const ll N = 1e5 + 10;

void test_case();

int main() {
	fast_io();
	test_case();
	cerr << "Time taken: " << int((clock() * 1000.) / CLOCKS_PER_SEC) << "ms\n";
	return 0;
}

void test_case() {
	ll x, y;
	cin >> x >> y;
	cout << x + y / 2 << "\n";
}

Measured memory_bytes: 256
import sys
import bisect

N = int(sys.stdin.readline())
A = list(map(int, sys.stdin.readline().split()))
B = list(map(int, sys.stdin.readline().split()))
C = list(map(int, sys.stdin.readline().split()))

A.sort()
B.sort()
C.sort()
# print(A)
# print(B)
# print(C)
ans = 0
for i in range(N):
    mid = B[i]
    top = bisect.bisect_left(A, mid)
    down = bisect.bisect_right(C, mid)
    # print(top, down)
    ans += top * (N - down)

print(ans)

Measured memory_bytes: 28928
{-# LANGUAGE BangPatterns, OverloadedStrings #-}

import Control.Monad
import Data.Array.Unboxed
import Data.Bits
import Data.Bool
import Data.Char
import Data.Coerce
import Data.Function
import Data.Int 
import Data.IORef
import Data.List
import Data.Maybe
import qualified Data.Map.Strict as M
import qualified Data.Vector.Unboxed as V
import qualified Data.Vector.Unboxed.Mutable as MV
import qualified Data.ByteString.Char8 as BS

main :: IO ()
main = do
  getLine
  ns <- map fromInteger <$> getIntegerList
  print $ solve ns

solve :: [N] -> N
solve ns = sum $ zipWith (*) ns $ tail $ scanr (+) 0 ns

-- Input

getInt :: IO Int
getInt = readLn
second :: (b -> c) -> (a, b) -> (a, c)
second f (a, b) = (a, f b)

readInt :: BS.ByteString -> Maybe (Int, BS.ByteString)
readInt = fmap (second BS.tail) . BS.readInt

getIntVec :: Int -> IO (V.Vector Int)
getIntVec n = V.unfoldrN n readInt <$> BS.getLine
 
getIntList :: IO [Int]
getIntList = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine

getIntegerList :: IO [Integer]
getIntegerList = map (fst . fromJust . BS.readInteger) . BS.words <$> BS.getLine

getIntPair :: IO (Int, Int)
getIntPair = do
  v <- getIntVec 2
  return (v V.! 0, v V.! 1)

-- Search

bisearch :: (Int -> Bool) -> (Int, Int) -> (Int, Int)
bisearch check = bis
  where
    bis (l, r)
      | l + 1 == r = (l, r)
      | check mid  = bis (mid, r)
      | otherwise  = bis (l, mid)
      where
        mid = l + (r - l) `div` 2

-- Modular Arithmetic
--
 
modulo :: Int64
modulo = 10^9+7
addMod, subMod, mulMod :: Int64 -> Int64 -> Int64
addMod !x !y | x + y >= modulo = x + y - modulo
             | otherwise = x + y
subMod !x !y | x >= y = x - y
             | otherwise = x - y + modulo
mulMod !x !y = (x * y) `rem` modulo

newtype N = N { unwrapN :: Int64 } deriving (Eq)
instance Show N where
  show (N x) = show x
instance Num N where
  (+) = coerce addMod
  (-) = coerce subMod
  (*) = coerce mulMod
  fromInteger n = N (fromInteger (n `mod` fromIntegral modulo))
  abs = undefined; signum = undefined
---
 
exEuclid :: (Eq a, Integral a) => a -> a -> (a, a, a)
exEuclid !f !g = loop 1 0 0 1 f g
  where loop !u0 !u1 !v0 !v1 !f 0 = (f, u0, v0)
        loop !u0 !u1 !v0 !v1 !f g =
          case divMod f g of
            (q,r) -> loop u1 (u0 - q * u1) v1 (v0 - q * v1) g r
 
recipM :: Int64 -> Int64
recipM !x = case exEuclid x modulo of
             (1,a,_) -> a `mod` modulo
             (-1,a,_) -> (-a) `mod` modulo
divM :: Int64 -> Int64 -> Int64
divM !x !y = x `mulMod` recipM y
 
instance Fractional N where
  (/) = coerce divM
  recip = coerce recipM
  fromRational = undefined

-- 組み合わせ
powerset :: [a] -> [[a]]  
powerset xs = filterM (\x -> [True, False]) xs


Measured memory_bytes: 60320
#[macro_use]
mod input {

use std;
use std::io;

const SPLIT_DELIMITER: char = ' ';

#[macro_export]
#[allow(unused_macros)]
macro_rules! input {
    ( $($x:expr ),*) => {
        {
            let temp_str = input_line_str();
            let mut split_result_iter = temp_str.split_whitespace();
                $(
                let buf_split_result = split_result_iter.next();
                let buf_split_result = buf_split_result.unwrap();
                    ($x) = buf_split_result.parse().unwrap();
                )*
        }
    };
}

#[allow(dead_code)]
pub fn input_line_str() -> String {
    let mut s = String::new();
    io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

}

use input::*;
use std::collections::BTreeMap;

fn main() {
    let mut map = BTreeMap::new();
    let mut s: usize;
    input!(s);

    let mut i = 1;
    loop {
        if map.contains_key(&s) {
            println!("{}", i);
            break;
        }
        map.insert(s, i);
        i += 1;
        if s % 2 == 0 {
            s /= 2;
        } else {
            s = s * 3 + 1;
        }
    }
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
  int N;
  cin >> N;
  map<string, ll> m;
  string s;
  for (int i = 0; i < N; i++) {
    cin >> s;
    sort(s.begin(), s.end());
    m[s]++;
  }
  ll v = 0;
  for (auto it = m.begin(); it != m.end(); it++) {
    ll t = it->second;
    v += t * (t - 1) / 2;
  }
  cout << v << "\n";
  return 0;
}

Measured memory_bytes: 11136
#include<stdio.h>
#include<algorithm>
using namespace std;
char str[52][52];
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};
char com[1100];
int vis[52][52][4][1100];
int to[1100];
int last[1100];
int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	for(int i=0;i<a;i++)scanf("%s",str[i]);
	scanf("%s",com);
	int depth=0;
	int len=0;
	for(int i=0;com[i];i++){
		len++;
		if(com[i]=='['||com[i]=='{'){
			last[depth++]=i;
		}
		if(com[i]==']'||com[i]=='}'){	
			depth--;
			to[i]=last[depth];
			to[last[depth]]=i;
		}
	}
	int row=0;
	int col=0;
	int dir=0;
	int cur=0;
	int gr,gc;
	for(int i=0;i<a;i++)for(int j=0;j<b;j++){
		if(str[i][j]=='s'){
			row=i;col=j;
		}
		if(str[i][j]=='g'){
			gr=i;gc=j;
		}
	}
	vis[row][col][dir][0]=1;
	int ret=0;
	while(cur<len){
		if(com[cur]=='['||com[cur]=='{'){
			bool nt=false;
			bool val=false;
			char p=com[cur+1];
			if(p=='~'){
				p=com[cur+2];
				nt=true;
			}
			if(p=='N'&&dir==0)val=true;
			if(p=='E'&&dir==1)val=true;
			if(p=='S'&&dir==2)val=true;
			if(p=='W'&&dir==3)val=true;
			if(p=='C'&&str[row+dx[dir]][col+dy[dir]]=='#')val=true;
			if(p=='T')val=true;
			if(nt)val=!val;
			if(val){
				if(nt)cur+=3;
				else cur+=2;
			}else{
				cur=to[cur]+1;
			}
		}else if(com[cur]==']')cur++;
		else if(com[cur]=='}')cur=to[cur];
		else{
			if(com[cur]=='^'){
				if(str[row+dx[dir]][col+dy[dir]]!='#'){
					row+=dx[dir];col+=dy[dir];
				}
			}
			if(com[cur]=='v'){
				if(str[row-dx[dir]][col-dy[dir]]!='#'){
					row-=dx[dir];col-=dy[dir];
				}
			}
			if(com[cur]=='>')dir=(dir+1)%4;
			if(com[cur]=='<')dir=(dir+3)%4;
			cur++;
			ret++;
		}
		if(gr==row&&gc==col){
			break;
		}
		if(vis[row][col][dir][cur]){
			ret=-1;break;
		}
		vis[row][col][dir][cur]=1;
	}
	if(gr!=row||gc!=col)ret=-1;
	printf("%d\n",ret);
}

Measured memory_bytes: 45020
function Main(input){
	var xs = input.trim().split(' ').map(v=>parseInt(v,10));
    if(xs[0]*xs[1]>xs[2]){
    console.log(xs[2]);
    }else if(xs[0]*xs[1]<xs[2]){
    console.log(xs[0]*xs[1]);
    }else if(xs[0]*xs[1]==xs[2]){
    console.log(xs[2]);
    }
}
Main(require("fs").readFileSync("/dev/stdin","utf8"));

Measured memory_bytes: 7372
import java.util.*;

public class Main {
	public static void main(String[] args){
		Scanner s = new Scanner(System.in);
		for(;;){
			int a = s.nextInt();
			String op = s.next();
			int b = s.nextInt();
		
			if(op.equals("?"))
				break;
			
			if(op.equals("+"))
				System.out.println(a + b);
			if(op.equals("-"))
				System.out.println(a - b);
			if(op.equals("*"))
				System.out.println(a * b);
			if(op.equals("/"))
				System.out.println(a / b);				
		}
	}
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll, int> plli;
typedef pair<int, pii> pipii;
typedef vector<vector<int> > mati;
typedef vector<vector<double> > matd;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef vector<pll> vpll;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back

inline void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

inline void OUT(void){
  cout << "\n";
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  string str;
  IN(str);

  bool flag = false;
  REP(i,str.size()-1){
    if(str[i] == str[i+1]) flag = true;
  }

  if(flag) OUT("Bad");
  else     OUT("Good");

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
typedef long long ll;
using namespace std;
int a[30],b[30];
int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string A,B;cin>>A>>B;
    for(int i=0;i<A.size();i++){
        a[A[i]-'a']++;b[B[i]-'a']++;
    }
    sort(a,a+27);sort(b,b+27);
    for(int i=0;i<30;i++){
        if(a[i]!=b[i]){
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    
    return 0;
}


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

// in-short-use macros

#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007

//container-use 

typedef vector< ll > vl;
typedef vector< vl > vvl;
typedef pair< ll,ll > pll;
typedef vector<pair<ll,ll > > vpl;
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define rep(i,a,b) for (int i = a; i <= b; i++)

//main function here
int a[25][25]={0};
int n,m;
int d[4][2]={{0,-1},{0,1},{1,0},{-1,0}};
int bfs(int i,int j)
{
    queue< pair<int,int > > q;
    int c=0;
    int vis[25][25]={0},dis[25][25]={0};
    q.push({i,j});
    vis[i][j]=1;
    while(!q.empty())
    {
        pair<int,int> el=q.front();
        int x=el.ff,y=el.ss;
        for(int f=0;f<4;f++)
        {
            int newdx=d[f][0]+x,newdy=d[f][1]+y;
            if(newdx<0 || newdx>=n || newdy<0 || newdy>=m)
                continue;
            if(!vis[newdx][newdy] && a[newdx][newdy]!=-1)
            {
                vis[newdx][newdy]=1;
                dis[newdx][newdy]=dis[x][y]+1;
                // cout<<newdx<<" "<<newdy<<" "<<dis[newdx][newdy]<<"\n";
                c=max(c,dis[newdx][newdy]);
                q.push({newdx,newdy});
            }
        }
        q.pop();
    }
    return c;
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
   
    cin>>n>>m;
    int q=0;
    for (int i=0;i<n;i++)
    {
        string c;
        cin>>c;
        for(int j=0;j<m;j++)
        {
            if(c[j]=='#')
                a[i][j]=-1;       
        }
    }
    // cout<<bfs(2,0);
    for(int i=0;i<n;i++)
    {
        for (int j=0;j<m;j++)
        {
            if(a[i][j]==-1)
                continue;
            // cout<<bfs(i,j)<<"\n";
            q=max(q,bfs(i,j));
        }
    }
    cout<<q<<"\n";
  return 0;
 }

Measured memory_bytes: 384
#include<cstdio>
#include<iostream>
#include<cstring>
#include<algorithm>
#include<map>
using namespace std;

typedef long long ll;

const int N=1e6+1e3+7;

map<ll,ll>s;

int n,a[N];

ll sum;

int main()
{
	scanf("%d",&n);
	s[0]++;
	ll ans=0;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		sum+=a[i];
		ans+=s[sum];
		s[sum]++;
	}
	printf("%lld",ans);
} 

Measured memory_bytes: 13568
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		OneDReversi game = new OneDReversi();
		game.run();
	}
}

class OneDReversi {
	
	char[] stones;
	
	OneDReversi() {
		Scanner cin = new Scanner(System.in);
		this.stones = cin.nextLine().toCharArray();
	}
	
	void run() {
		int count = 0;
		char previousStone = stones[0];
		for (int i = 1; i < stones.length; i++) {
			if (previousStone != stones[i]) {
				count++;
			}
			previousStone = stones[i];
		}
		System.out.println(count);
	}
}


Measured memory_bytes: 13696
#include <iostream>

using namespace std;
typedef long long ll;

const ll INF = 1000000000000000ll;

bool compare(ll ax, ll ay, ll az, ll bx, ll by, ll bz){
	if(ax + ay < bx + by){ return true; }
	if(ax + ay > bx + by){ return false; }
	return az < bz;
}

int main(){
	while(true){
		ll a, b, d;
		cin >> a >> b >> d;
		if(a == 0 && b == 0 && d == 0){ break; }
		ll ax = INF, ay = INF, az = INF;
		for(ll i = 0; i <= 1000000; ++i){
			if(i * a <= d && (d - (i * a)) % b == 0){
				ll x = i, y = (d - (i * a)) / b, z = a * x + b * y;
				if(compare(x, y, z, ax, ay, az)){
					ax = x; ay = y; az = z;
				}
			}
			if(i * a >= d && (i * a - d) % b == 0){
				ll x = i, y = (i * a - d) / b, z = a * x + b * y;
				if(compare(x, y, z, ax, ay, az)){
					ax = x; ay = y; az = z;
				}
			}
			if((i * a + d) % b == 0){
				ll x = i, y = (i * a + d) / b, z = a * x + b * y;
				if(compare(x, y, z, ax, ay, az)){
					ax = x; ay = y; az = z;
				}
			}
		}
		cout << ax << " " << ay << endl;
	}
	return 0;
}

Measured memory_bytes: 1156
#include <algorithm>
#include <bitset>
#include <complex>
#include <cstdio>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;

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

typedef long long ll;

const int Inf = 100100100;
const double EPS = 1e-9;

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

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

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;  cin >> n >> m;
    vector<int> city[100001];
    vector<int> p(m), y(m);
    rep(i, m) {
      cin >> p[i] >> y[i];
      city[p[i]].push_back(y[i]);
    }
    rep(i, n + 1) {
      sort(city[i].begin(), city[i].end());
    }
    rep(i, m) {
      int index;
      auto it = lower_bound(city[p[i]].begin(), city[p[i]].end(), y[i]);
      index = it - city[p[i]].begin() + 1;
      cout << setfill('0') << right << setw(6) << p[i];
      cout << setfill('0') << right << setw(6) << index << '\n';
    }

    return 0;
}


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

using namespace std;

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

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

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

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

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;  cin >> n;
    for (int i = 1; ; i++) {
      if (i * i > n) {
        cout << (i - 1) * (i - 1) << '\n';
        return 0;
      }
    }

    return 0;
}


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

int main(){
    int a[3];
    for(int i=0;i<3;i++){
        cin>>a[i];
    }
    sort(a,a+3);
    if(a[0]==5&&a[1]==5&&a[2]==7)cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
}


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

#define debug(a) cout << #a << " " << a << endl;
#define _debug(a, i) cout << #a << "[" << i << "]" \
						  << " = " << a[i] << endl;
#define fastio                        \
	ios_base::sync_with_stdio(false); \
	cin.tie(0);                       \
	cout.tie(0);
#define PI 3.141592654
#define all(v) v.begin(), v.end()

using namespace std;

using ll = long long;
const int MOD = 1e9 + 7;
const ll INF = 1e18 + 9;
using pi = pair<int, int>;

ll powmod(ll base, ll exp, const ll MOD) { ll ans = 1; while (exp) { if (exp & 1)	ans = (ans * base) % MOD; base = (base * base) % MOD; exp >>= 1; }return ans; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return (a * b) / gcd(a, b); }
ll modInverse(ll n, const ll p) { return powmod(n, p - 2, p); }

//ll f[500005];
//ll kCn(ll k, ll n) { return (f[n] * modInverse((f[n - k] * f[k]) % MOD, MOD)) % MOD; }


const int mxN = 1e6;


void test_case() {

}

int popcount(ll x) {
	int ans = 0;
	for (int i = 0; i < 64; ++i) {
		ans += (x >> i) & 1LL;
	}
	return ans;
}

int main() {
	fastio;
	int n;
	cin >> n;
	string x;
	cin >> x;
	ll pow[3] = { 1,1,1 };
	ll cnt = 0;
	ll a[3] = { 0 };

	for (auto ch : x)
		cnt += ch == '1';

	for (int i = n - 1; i >= 0; --i) {
		if (x[i] == '1') {
			if (cnt > 1) {
				a[0] = (a[0] + pow[0]) % (cnt - 1);
			}
			else
				a[0] = 0;
			a[2] = (a[2] + pow[2]) % (cnt + 1);
		}
		if (cnt > 1) {
			pow[0] *= 2;
			pow[0] %= cnt - 1;
		}
		else
			pow[0] = 0;
		pow[2] *= 2; pow[2] %= cnt + 1;
	}

	for (int i = 0; i < n; ++i) {
		int ans = 0;
		ll t = 0;
		if (x[i] == '1') {

			if (cnt - 1 == 0) {
				cout << 0 << "\n";
				continue;
			}

			ll old = a[0];
			if (cnt > 1)
				a[0] -= powmod(2, n - 1 - i, cnt - 1);
			else
				a[0] = 0;
			if (cnt > 1)
				a[0] %= cnt - 1;
			while (a[0] < 0 && cnt > 1)
				a[0] += cnt - 1;
			t = a[0];
			a[0] = old;
		}
		else {
			ll old = a[2];
			a[2] += powmod(2, n - 1 - i, cnt + 1);
			a[2] %= cnt + 1;
			t = a[2];
			a[2] = old;
			if (cnt + 1 == 1) {
				cout << 1 << "\n";
				continue;
			}
		}

		while (t != 0) {
			t = t % popcount(t);
			++ans;
		}
		cout << ans + 1 << "\n";
	}

	return 0;
}


Measured memory_bytes: 3748
#include <bits/stdc++.h>
using namespace std;
int main(){

  int N, i;
  string S;

  cin >> N;

  for(i=0;i<N;++i){
    cin >> S;
    if(S=="Y"){
      cout << "Four" << endl;
      break;
    }
  }
  if(i==N){
    cout << "Three" << endl;
  }
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

n = int(input())
a = list(map(int, input().split()))

two = []
four = []
others = []

for v in a:
    if v % 4 == 0:
        four.append(v)
    elif v % 2 == 0:
        two.append(v)
    else:
        others.append(1)

if len(two) % 2 != 0:
    others.append(two[0])
if len(four) + 1 >= len(others):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 84640
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<int>arr(n), brr(n);
    for(int i=0; i<n; i++)
    {
        cin >> arr[i];
    }
    for(int i=0; i<n; i++)
    {
        cin >> brr[i];
    }
    reverse(brr.begin(),brr.end());
    int number = -1;
    for(int i=0; i<n; i++)
    {
        if(arr[i] == brr[i])
        {
            number = arr[i];
            break;
        }
    }
    int leftPos = 0;
    for(int i=0; i<n; i++)
    {
        if(arr[i]==number && brr[i]==number)
        {
            leftPos = i;
            break;
        }
    }
    int rightPos = -1;
    for(int i=n-1; i>=0; i--)
    {
        if(arr[i]==number && brr[i]==number)
        {
            rightPos = i;
            break;
        }
    }
    for(int i=0; i<n && number!=-1; i++)
    {
        if(arr[i]!=number && brr[i]!=number && leftPos<=rightPos)
        {
            swap(brr[i],brr[leftPos]);
            leftPos++;
        }
    }
    if(leftPos<=rightPos)
    {
        cout << "No\n";
    } else
    {
        cout <<"Yes\n";
        for(int x : brr)cout << x << " ";
        cout << endl;
    }
}


Measured memory_bytes: 4832
N, M = map(int, input().split())
inputs = [[int(i) for i in input().split()] for _ in range(N)]

inputs.sort()
count = 0
ans = 0
for A, B in inputs:
    if M < B:
        print
        ans += A * M
        break
    else:
        ans += A * B
        M -= B

print(ans)


Measured memory_bytes: 21604
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list || .most_common(2)で最大の2個とりだせるお a[0][0]
from fractions import gcd
from itertools import combinations,permutations,accumulate # (string,3) 3回
#from collections import deque
from collections import deque,defaultdict,Counter
import decimal
import re
#import bisect
#
#    d = m - k[i] - k[j]
#    if kk[bisect.bisect_right(kk,d) - 1] == d:
#
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

import sys
sys.setrecursionlimit(10000000)
mod = 10**9 + 7
#mod = 9982443453
def readInts():
  return list(map(int,input().split()))
def I():
  return int(input())
import heapq
n = I()
A = sorted(readInts())
setA = set(A)
if (n - len(setA))%2 == 0:
    print(len(setA))
else:
    print(len(setA)-1)


Measured memory_bytes: 22400
#include <bits/stdc++.h>
typedef long long int LL;
typedef unsigned long long int ULL;
using namespace std;

// 插入此處

int in_degree[100005];

vector<int> edges[100005];

int parent[100005];

int main() {
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < n + m - 1; i++) {
        int a, b;
        cin >> a >> b;
        edges[a].push_back(b);
        in_degree[b]++;
    }
    int root;
    for (int i = 1; i <= n; i++) {
        if (in_degree[i] == 0) {
            root = i;
            break;
        }
    }
    queue<int> q;
    q.push(root);
    while (!q.empty()) {
        int cur = q.front(); q.pop();
        for (int nxt: edges[cur]) {
            in_degree[nxt]--;
            if (in_degree[nxt] == 0) {
                parent[nxt] = cur;
                q.push(nxt);
            }
        }
    }
    for (int i = 1; i <= n; i++) {
        cout << parent[i] << endl;
    }
}


Measured memory_bytes: 9788
#include <stdio.h>

int main(void) {
	
	int i,x;
	
	for(i=1; ;i++)
	{
		scanf("%d",&x);
		
		if(x==0)
		{
			break;
		}
		
		
		printf("Case %d: %d\n",i,x);
	}
	// your code goes here
	return 0;
}



Measured memory_bytes: 2056
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main 
{
	static Scanner scan = new Scanner(System.in);

	public static void main(String[] args) 
	{
		int n;
		int m;
		
		while(true)
		{
			n = scan.nextInt();
			m = scan.nextInt();
			
			if(m == 0 && n == 0)
			{
				return;
			}
			else
			{
				new DataSet(n, m);
			}
		}

	}
	
	static class DataSet
	{
		int money;
		int numOfGoods;
		List<Integer> prices = new ArrayList<Integer>();
		
		public DataSet(int n, int m)
		{
			numOfGoods = n;
			money = m;
			
			for(int i = 0; i < numOfGoods; i++)
			{
				prices.add(scan.nextInt());
			}
			
			int hiscore = 0;
			
			for(int a = 0; a < numOfGoods; a++)
			{
				for(int b = a+1; b < numOfGoods; b++)
				{
					int score = prices.get(a) + prices.get(b);
					
					if(hiscore < score && score <= money){hiscore = score;}
				}
			}
			
			if(hiscore > 0)
			{
				System.out.println(hiscore);
			}
			else
			{
				System.out.println("NONE");
			}
		}
	}

}



Measured memory_bytes: 49112
n = int(input())
s = input()
if s[0] == 'B':
  imos = [1]
else:
  imos = [0]
for i in range(1,2*n):
  if s[i] == s[i-1]:
    imos.append(0)
  else:
    imos.append(1)
#print(imos)
ans = 1
mod = 10 ** 9 + 7
l = 0
att = 0
for i in range(2*n):
  if imos[i] ^ att == 1:
    l += 1
    att = 0
  else:
    ans *= l
    l -= 1
    att = 1
  ans %= mod
  #print(ans,l)
for i in range(1,n+1):
  ans *= i
  ans %= mod
if l == 0:
  print(ans)
else:
  print(0)

Measured memory_bytes: 4916
N,M = map(int,input().split())
AB = [list(map(int,input().split())) for _ in [0]*(N+M-1)]

E = [set() for _ in [0]*N]
E2 = [set() for _ in [0]*N]
Eb = [set() for _ in [0]*N]
for a,b in AB:
    E[a-1].add(b-1)
    E2[a-1].add(b-1)
    Eb[b-1].add(a-1)

p = [0]*N
q = []
for i in range(N):
    if not E[i]:
        q.append(i)
while q:
    qq = set()
    for i in q:
        for j in Eb[i]:
            E[j].remove(i)
    for i in q:
        while Eb[i]:
            j = Eb[i].pop()
            if not E[j]:
                for k in E2[j]:
                    if p[k] == 0 : p[k] = j+1
                qq.add(j)
    q = qq

print(*p,sep="\n")

Measured memory_bytes: 119236
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"sort"
	"strconv"
)

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func maxInt64(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumInt64(a []int64) int64 {
	var ret int64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcdInt64(m, n int64) int64 {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcmInt64(m, n int64) int64 {
	return m / gcdInt64(m, n) * n
}

// sort ------------------------------------------------------------

type int64Array []int64

func (s int64Array) Len() int           { return len(s) }
func (s int64Array) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s int64Array) Less(i, j int) bool { return s[i] < s[j] }

type xxx struct {
	x int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

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

func main() {
	n := readInt()
	a := make([]int, n)
	mi := 0
	for i := range a {
		a[i] = readInt()
		if a[i] > a[mi] {
			mi = i
		}
	}

	sort.Ints(a)

	for i := range a {
		if i == mi {
			fmt.Println(a[n-2])
		} else {
			fmt.Println(a[n-1])
		}
	}
}


Measured memory_bytes: 6400
from sys import stdin, setrecursionlimit
from collections import Counter, deque, defaultdict
from math import floor, ceil
from bisect import bisect_left
from itertools import combinations, accumulate
setrecursionlimit(100000)

INF = int(1e10)
MOD = int(1e9 + 7)

def main():
    from builtins import int, map
    N = int(input())
    A = list(map(int, input().split()))
    cA = list(accumulate(A))
    ans = 0
    for i in range(N - 1):
        term = A[i] * (cA[-1] - cA[i]) % MOD
        ans = (ans + term) % MOD
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 104832
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>
using namespace std;
int n,a[101010],ans;
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		int x;
		cin>>x;
		a[x]++;
	}
	for(int i=1;i<=100000;i++)
	{
		ans=max(ans,a[i-1]+a[i]+a[i+1]);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 640
#include "iostream"
#include "cstring"
#include "cstdio"
#include "queue"
using namespace std;
const int N = 10010;
const int INF = 0x3fffffff;
int pre[N];
struct Edge
{
	int x, y, d, c;
	int next;
	Edge(){}
	Edge(int X, int Y, int D, int C):x(X), y(Y), d(D), c(C){}
}p, q, e[N * 4];
int dis[N], cost[N], vis[N]; 
queue<int> que;
void spfa(int n)
{
	for(int i = 1; i <= n; ++ i){
		dis[i] = INF;
		vis[i] = 0;
	}
	dis[1] = 0;
	cost[1] = 0;
	que.push(1);
	while(!que.empty()){
		int u = que.front();
		vis[u] = 0;
		que.pop();
		for(int i = pre[u]; i != -1; i = e[i].next){
			int v = e[i].y, d = e[i].d, c = e[i].c;
			if(dis[v] > dis[u] + d || (dis[v] == dis[u] + d && cost[v] > c)){
				dis[v] = dis[u] + d;
				cost[v] = c;
				if(!vis[v]){
					vis[v] = 1;
					que.push(v);
				}
			}
		}
	}
} 
int main(void)
{
	int n, m;
	while(scanf("%d %d", &n, &m) && (n || m)){
		memset(pre, -1, sizeof(pre));
		int x, y, d, c;
		int tot = 1;
		for(int i = 1; i <= m; ++ i){
			scanf("%d %d %d %d", &x, &y, &d, &c);
			e[tot] = Edge(x, y, d, c);
			e[tot].next = pre[x];
			pre[x] = tot++;
			e[tot] = Edge(y, x, d, c);
			e[tot].next = pre[y];
			pre[y] = tot++;
		}
		spfa(n);
		int ans = 0;
		for(int i = 1; i <= n; ++ i){
			ans += cost[i];
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 2192
#include<bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define pb push_back
#define ll long long
#define pii pair<int,int>


void test_case()
{
    int n;
    cin>>n;
    int sum=0,a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        sum+=a[i];
    }
    int avg=round((double)sum/n);
    ll ans=0;
    for(int i=0;i<n;i++) {
        ans+=1LL * (avg-a[i]) * (avg-a[i]);
    }
    cout<<ans;
}

int main()
{
    fastio
//    int t;
//    cin>>t;
//    while(t--)
    test_case();
}


Measured memory_bytes: 3632