akhauriyash/Code-Regression huggingface dataset:
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ScopedTypeVariables #-}
import qualified Data.ByteString.Char8 as BS
import qualified Data.Vector.Unboxed as U

-- n := V.length v + 1
-- v ! i = 表が i 枚、裏が n - i 枚出る確率
solve :: [Double] -> U.Vector Double
solve ps = go ps (U.singleton 1)
  where
    go [] !vec = vec
    go (!p:ps) !vec = go ps $ U.generate (U.length vec + 1) $ \i ->
      if i == 0
      then (1 - p) * vec U.! i
      else if i == U.length vec
           then p * vec U.! (i - 1)
           else p * vec U.! (i - 1) + (1 - p) * vec U.! i

main = do
  n :: Int <- readLn
  -- 1 <= n <= 2999, n is odd
  ps :: [Double] <- map (read . BS.unpack) . BS.words <$> BS.getLine
  let result = solve ps
  -- U.length result == n + 1
  print $ U.sum $ U.drop (n `quot` 2 + 1) result


Measured memory_bytes: 1788
my_range = int(input())
data_in = list(map(int,input().split()))
n_of_odd = 0
for ind in range(my_range):
  if (ind % 2) == 0:
    rem = data_in[ind] % 2
    n_of_odd = n_of_odd + rem
print(n_of_odd)

Measured memory_bytes: 61820
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define erep(i,a,n) for(int i = a;i<=n;i++)
typedef long long ll;
#define int long long
#define vint vector<int>
#define vvint vector<vector<int>>
#define vstring vector<string>
#define vdouble vector<double>
#define vll vector<ll>:
#define vbool vector<bool>
#define INF 1101010101010101010
#define MOD 1000000007
#define P pair<int,int>
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }

signed main(){
  int n,m;
  cin >> n >> m;
  vector<P> key;
  rep(i,0,m){
    int a,b;
    cin >> a >> b;
    int s = 0;
    rep(i,0,b){
      int c;
      cin >> c;
      c--;
      s |= 1<<c;
    }
    key.emplace_back(a,s);
  }
  vint dp(1<<n,INF);
  dp[0] = 0;
  rep(i,0,1<<n){
    rep(j,0,m){
      int s = key[j].second|i;
      int cost = dp[i] + key[j].first;
      dp[s] = min(dp[s],cost);
    }
  }
  int ans = dp.back();
  if(ans == INF) cout << -1 << endl;
  else cout << ans << endl;
}

Measured memory_bytes: 384
#include <iostream>  // cin,cout
#include <stdio.h>   // printf,scanf (standard input/output)
#include <cmath>     // abs(x),pow(x,2)
#include <string>
#include <string.h>  // strlen, strcmp
#include <algorithm> // min,max, sort(v.begin(),v.end())
#include <vector>
#include <time.h>
using namespace std;

struct Card{
    string suit;
    int value;
};

int Func(){
    int x = 0;
    return x;
}

int main(){
    int N;
    int A[15] = {};
    int P[] = {2,3,5,7,11,13,17,19,23,29,31,37,41,43,47};
    
    cin >> N;
    for (int i=2;i<=N;i++) {
        int temp = i;
        for (int j=0;j<15;j++) {
            //cout << temp << endl;
            while ((temp%P[j])==0) {
                A[j] += 1;
                temp /= P[j];
            }
        }
    }
    for (int j=0;j<15;j++) {
        //cout << A[j] << endl;
    }
    
    int count_4 = 0;
    int count_2 = 0;
    for (int j=0;j<15;j++) {
        if (A[j]>=4) count_4 += 1;
        else if (A[j]>=2) count_2 += 1;
    }
    
    int result = 0;
    //cout << count_4 << " " << count_2 << endl;
    int a = count_4;
    if (count_4>=3) {
        result += a*(a-1)*(a-2)/6*3;
    }
    if (count_4>=2) {
        result += a*(a-1)/2 * count_2;
    }
    
    int count_24 = 0;
    count_2 = 0;
    for (int j=0;j<15;j++) {
        if (A[j]>=24) count_24 += 1;
        else if (A[j]>=2) count_2 += 1;
    }
    if (count_24>=2) {
        result += count_24*(count_24-1);
    }
    result += count_24*count_2;
    
    int count_14 = 0;
    count_4 = 0;
    for (int j=0;j<15;j++) {
        if (A[j]>=14) count_14 += 1;
        else if (A[j]>=4) count_4 += 1;
    }
    if (count_14>=2) {
        result += count_14*(count_14-1);
    }
    result += count_14*count_4;
    
    int count_74 = 0;
    for (int j=0;j<15;j++) {
        if (A[j]>=74) count_74 += 1;
    }
    result += count_74;
    
    cout << result << endl;
    
    
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

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

        int n = sc.nextInt();
        int checkpoint=0;

        for(int i=1;i < 10;i++){
            double check = (double)n/i;
            if(check == (int)check && check < 10){
                checkpoint++;
            }
        }

        if(0 <checkpoint){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 23252
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

    	Main main=new Main();

    	main.run();

    }

    void run() {

    	Scanner sc=new Scanner(System.in);

    	String c=sc.next();

    	if(c.matches("[aiueo]")) {
    		System.out.println("vowel");
    	}else {
    		System.out.println("consonant");
    	}
    }
}


Measured memory_bytes: 21844
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int a=sc.nextInt(),b=sc.nextInt(),c=sc.nextInt();
		System.out.println(Math.max(Math.max(a, b),Math.max(a, c)) - Math.min(Math.min(a, b),Math.min(a, c)));
	}
}

Measured memory_bytes: 21716
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define ll long long
using namespace std;

int main()
{
    int n;
    string s;
    cin>>n>>s;

    int r=0,g=0,b=0;
    for(int i=0;i<n;i++)
    {
        if(s[i]=='R') r++;
        else if(s[i]=='G') g++;
        else b++;
    }

    ll ways=(ll)r*g*b;
    for(int i=0;i<n;i++)
    {
        for(int d=1;i+2*d<n;d++)
        {
            int j=i+d,k=i+2*d;
            if(s[i]!=s[j] && s[j]!=s[k] && s[k]!=s[i]) ways--;
        }
    }

    cout<<ways<<endl;


    return 0;
}


Measured memory_bytes: 3576
#include<iostream>
#include<string>

using namespace std;

#define MAX 50

int main(){

	int n;
	int H,W;

	string pict[MAX];
	int zai['Z'-'A'+1][MAX][MAX];
	/*
	0..??????
	1..?????????
	2..??°
	3..??????
	*/
	bool zok['Z'-'A'+1];

	cin>>n;
	while(n--){
		cin>>H>>W;
		for(int i=0;i<H;i++){
			cin>>pict[i];
		}

		for(int i=0;i<H;i++){
			for(int j=0;j<W;j++){
				for(int k=0;k<='Z'-'A';k++){
					zai[k][i][j]=0;
				}
			}
		}

		for(int i=0;i<='Z'-'A';i++){
			zok[i]=false;
		}

		for(int i=0;i<H;i++){
			for(int j=0;j<W;j++){
				if(pict[i][j]!='.'){
					zai[pict[i][j]-'A'][i][j]=1;
				}
			}
		}

		while(1){
			bool ex=true;
			for(int i=0;i<='Z'-'A';i++){
				if(zok[i]) continue;
				bool fok=true;
				for(int j=0;j<H;j++){
					for(int k=0;k<W;k++){
						if(zai[i][j][k]==1) fok=false;
					}
				}
				if(fok) zok[i]=true;
			}
			for(int i=0;i<='Z'-'A';i++){
				if(zok[i]) continue;
				int mu=-1,mb=-1,mr=-1,ml=-1;
				for(int j=0;j<H&&mu==-1;j++){
					for(int k=0;k<W&&mu==-1;k++){
						if(zai[i][j][k]==1) mu=j;
					}
				}
				for(int j=H-1;j>=0&&mb==-1;j--){
					for(int k=0;k<W&&mb==-1;k++){
						if(zai[i][j][k]==1) mb=j;
					}
				}
				for(int j=0;j<W&&ml==-1;j++){
					for(int k=0;k<H&&ml==-1;k++){
						if(zai[i][k][j]==1) ml=j;
					}
				}
				for(int j=W-1;j>=0&&mr==-1;j--){
					for(int k=0;k<H&&mr==-1;k++){
						if(zai[i][k][j]==1) mr=j;
					}
				}
				bool sqf=true;
				for(int j=mu;j<=mb;j++){
					for(int k=ml;k<=mr;k++){
						if(zai[i][j][k]==0) sqf=false;
					}
				}
				if(sqf){
					ex=false;
					for(int j=mu;j<=mb;j++){
						for(int k=ml;k<=mr;k++){
							for(int l=0;l<='Z'-'A';l++){
								if(l!=i) zai[l][j][k]=2;
							}
							zai[i][j][k]=0;
						}
					}
				}
			}
			if(ex) break;
		}
		bool ansf=true;
		for(int i=0;i<='Z'-'A';i++){
			for(int j=0;j<H;j++){
				for(int k=0;k<W;k++){
				}
			}
			if(!zok[i]) ansf=false;
		}
		if(ansf) cout<<"SAFE"<<endl;
		else cout<<"SUSPICIOUS"<<endl;
	}
}

Measured memory_bytes: 1460
#include<bits/stdc++.h>
using namespace std;
signed main(){
int n;
int a[2000];
int count=0;
cin>>n;
for(int i=0;i<n;i++){
cin>>a[i];
}
sort(a,a+n);
for(int i=0;i<n-2;i++){
for(int j=i+1;j<n-1;j++){
for(int k=j+1;k<n;k++){
if(a[i]<a[j]+a[k]&&a[j]<a[i]+a[k]&&a[k]<a[j]+a[i]){
count++;
}else{
break;
}
}
}
}
cout<<count<<"\n";
return(0);
}

Measured memory_bytes: 256
n = input()
for i in xrange(n):
    x1, y1, x2, y2, x3, y3, x4, y4 = map(float, raw_input().split())
    Ax = x1 - x2
    Ay = y1 - y2
    Bx = x3 - x4
    By = y3 - y4
    if Ax == Bx == 0 or Ay == By == 0:
        print "YES"
    elif abs(Ay * Bx - By * Ax) < 1e-10:
        print "YES"
    else:
        print "NO"

Measured memory_bytes: 4236
#include<iostream>
#include<algorithm>
#include<functional>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<deque>
#include<sstream>
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<bitset>
#include<time.h>
#include<cstdlib>
#include<cassert>
#define ll long long
#define fi first
#define se second
using namespace std;

int n;
const ll inf=(ll)1e14;
ll dp[310][310];

bool aru[310][310];
                   
int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout<<fixed;
#ifdef LOCAL_DEFINE
    freopen("in", "r", stdin); 
    freopen("out","w",stdout);
#endif
  cin>>n;
  for(int i=0;i<310;i++){
    for(int j=0;j<310;j++){
      dp[i][j]=inf;
    }
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
    cin>>dp[i][j];
    }
  }
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      aru[i][j]=1;
    }
  }
  for(int k=0;k<n;k++){
    for(int i=0;i<n;i++){
      for(int j=0;j<n;j++){
        if(dp[i][j]>dp[i][k]+dp[k][j]){
          cout<<-1<<endl;
          return 0;
        }
      }
    }
  }
  ll ans=0;
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      bool flag=1;
      for(int k=0;k<n;k++){
        if(k==i || k==j)continue;
        if(dp[i][j]==dp[i][k]+dp[k][j])flag=0;
      }
      if(flag)ans+=dp[i][j];
    }
  }
  cout<<ans/2<<endl;
#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}

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

int n, m, q;
vector<int> a, b, c, d;
int ans;

void dfs(vector<int> A){
    if(A.size() == n+1){
        int now = 0;
        rep(i,q){
            if(A[b[i]] - A[a[i]] == c[i]) now += d[i];
        }
        ans = max(ans, now);
        return;
    }

    A.push_back(A.back());
    while (A.back() <= m) {
        dfs(A);
        A.back()++;
    }
}

int main(){
    cin >> n >> m >> q;
    a = b = c = d = vector<int>(q);
    rep(i,q){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    dfs(vector<int>(1,1));
    cout << ans << endl;
    return 0;
}

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

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

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

  int r, g, b;
  cin >> r >> g >> b;

  if ((r * 100 + g * 10 + b) % 4 == 0) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned ui;
typedef unsigned long long ul;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef pair<bool, bool> pbb;
typedef vector<int> vi;
#define pb push_back
#define fi first
#define se second
#define mid ((l + r) >> 1)
#define ls (i << 1)
#define rs (i << 1 | 1)
#define enum(i, j, k) for(int i = j; i <= (k); i ++)
#define open(i, j, k) for(int i = j; i <  (k); i ++)
#define dec(i, j, k)  for(int i = j; i >= (k); i --)
#define ae(x) for(node *p = h[x]; p; p = p->nxt)
#define fill(x, k) memset(x, k, sizeof x)
#define copy(x, y) memcpy(x, y, sizeof x)
#define fio(x) freopen(x".in", "r", stdin); freopen(x".out", "w", stdout);
template <class T> bool chkmin(T &x, T y)
{ return y < x ? (x = y , true) : false; }
template <class T> bool chkmax(T &x, T y)
{ return y > x ? (x = y , true) : false; }
void __init()
{
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(16);
    srand(time(0) ^ ui(ul(new char)));
}
/* default code ends here */
int n, a, b;
int op[500100];
bool flag[20];
void work(int l, int r, int t)
{
	if(l + r & 1)
		exit(2);
	if(l == r)
	{
		op[l] = t;
		return ;
	}
	int k = __builtin_ctz(t);
	flag[k] = false;
	t ^= 1 << k;
	int g = 0;
	if(t == 0)
	{
		while(!flag[g])
			g ++;
	}
	else
		g = __builtin_ctz(t);
	work(l, mid - 1, 1 << g);
	work(mid + 1, r, t ^ 1 << g);
	op[mid] = 1 << k;
	flag[k] = true;
}
//unordered_set<int> st;
int main()
{
	__init();
	cin >> n >> a >> b;
	if(__builtin_popcount(a ^ b) % 2 == 0)
		return cout << "NO" << endl, 0;
	cout << "YES" << endl;
	memset(flag, true, sizeof flag);
	work(1, (1 << n) - 1, a ^ b);
	int x = a;
	cout << x << ' ';
	open(i, 1, 1 << n)
	{
//		assert(!st.count(x));
//		st.insert(x);
//		assert(__builtin_popcount(op[i]) == 1);
		x ^= op[i];
		cout << x << ' ';
	}
//	cerr << x << endl;
//	if(x != b)
//		exit(1);
//	assert(x == b);
//	assert(!st.count(x));
	return 0;
}

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

int main() {
 int k;
 string n;
  cin >> k >>n;
  if(n.size()<=k){
    cout <<n;
  }
  else{
    for(int a;a<k;a++){
      cout <<n.at(a);
    }
    cout <<"...";
  }
}

Measured memory_bytes: 3632
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(input())

# def LIST(): return list(map(str, input().split()))
# def LIST(): return list(input())

sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

N = INT()

i = 1
while(1):
    i += 1
    if i * i > N:
        ans = (i - 1) * (i - 1)
        print(ans)
        exit()

Measured memory_bytes: 5320
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void)
{
    int count['z'-'a'+1];
    memset(count, 0, sizeof(count));

    while(1){
        int code = getc(stdin);
        if(code == EOF) break;
        if(code >= 'A' && code <= 'Z'){
            count[code - 'A']++;
        }
        if(code >= 'a' && code <= 'z'){
            count[code - 'a']++;
        }
    }

    for(int i = 0; i < sizeof(count)/sizeof(count[0]); i++){
        printf("%c : %d\n", 'a' + i, count[i]);
    }

    return 0;
}

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

const int N = 55555;

vector<int> primes(int n) {
	bool is_prime[n+1];
	memset(is_prime, 0, sizeof is_prime);
	vector<int> ans = {2};
	is_prime[2] = 1; 
	for (int i = 3; i <= n; i+=2) 
		is_prime[i] = 1;

	for (int i = 3; i*i <= n; i+=2)
		if (is_prime[i])
			for (int j = i*i; j <= n; j+=i)
				is_prime[j] = 0;
	for (int i = 3; i <= n; i+=2)
		if (is_prime[i])
			ans.push_back(i);
	return ans;
}

int main () {
	vector<int> p = primes(N);
	int n; cin >> n;
	vector<int> ans;
	for (int x : p)
		if (x%5 == 1)
			ans.push_back(x);
	for (int i = 0; i < n; i++)
		cout << ans[i] << (i == n-1 ? '\n' : ' ');
	return 0;
}

Measured memory_bytes: 384
#include<cstdio>
using namespace std;
#define Mod 1000000007
int now,n,m,a,b,fac[200001],inv[200001],ans,sum=0;
int C(int a,int b){
	return 1ll*fac[a]*inv[b]%Mod*inv[a-b]%Mod;
}
int main(void){
	register int i;
	scanf("%d%d%d%d",&n,&m,&a,&b),
	--n,--m;
	fac[0]=inv[0]=inv[1]=1;
	for(i=2;i<=200000;++i)
		inv[i]=1ll*(Mod-Mod/i)*inv[Mod%i]%Mod;
	for(i=1;i<=200000;++i)
		fac[i]=1ll*fac[i-1]*i%Mod,inv[i]=1ll*inv[i]*inv[i-1]%Mod;
	for(i=b;i<=m;++i){
		now=C(i+n-a,n-a),now=(now-sum+Mod)%Mod,sum=(sum+now)%Mod;
		ans=(ans+1ll*now*C(m-i+a,a)%Mod)%Mod;
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 1664
/*
 ABC149 B
 auther: takeheroaf
 created at 2020-1-2 15:9:37
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, j, n) for (int i = j; i < n; i++)
#define all(x) (x).begin(),(x).end()
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vc vector
#define a first
#define b second
#define pb push_back
#define INF (1000000000)
#define MOD (1000000007)
#define MAX (100000)

/////////////////////////////////////////////////////////

template<typename T1, typename T2>
void chmin(T1 &a, T2 b) {if(a > b) a = b;}
template<typename T1, typename T2>
void chmax(T1 &a, T2 b) {if(a < b) a = b;}

template<typename T1, typename T2>
ll mypow(T1 a, T2 n){
  if(n == 0) return 1;
  if(n == 1) return a;
  if(n % 2) return a * mypow(a, n - 1);
  ll tmp = mypow(a, n / 2);
  return tmp * tmp;
}

ll comb(ll n, ll r){
	ll res = 1;
  rep(i, 0, r){
    res *= n - i;
    res /= i + 1;
  }
  return res;
}

/////////////////////////////////////////////////////////

void Main(){
  ll A, B , K; cin >> A >> B >> K;
  ll tmp = min(A, K);
  A -= tmp;
  K -= tmp;
  B -= min(B, K);
  cout << A << " " << B << endl;
  return;
}

/////////////////////////////////////////////////////////

int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << std::fixed << std::setprecision(15);

  Main();

  return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;

namespace ProgramingStydying
{
    class Program
    {
        static void Main(string[] args)
        {
            var ab = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var a = ab[0];
            var b = ab[1];
            var ans = 0;

            for(int M = a; M <= b; M++)
            {
                var m = M;
                var n = 0;
                for(int i = 0; i < 5 ; i++)
                {
                    n += (m % 10) * (int)Math.Pow(10, 4 - i);
                    m /= 10;
                }

                if(n == M)
                {
                    ans++;
                }
            }
            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 28512
#include <bits/stdc++.h>
using namespace std;
#define  rep(i, n) for(int i = 0; i < n; i++) 
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  INF 1LL << 60
typedef long long int LL;
typedef long long int ll;
#define pll pair<ll, ll>
#define F first
#define S second
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }
//sort(all(x))とするとソートできるよ
// 10^x は pow(10,(x)) 
// 任意のlogは　対数の底の変換を使う    log(N) / log(任意の底)

int main(){
    int N;cin >> N;
    string S;cin >> S;
    vector<int> retu;
    if(N == 1){
        retu.push_back(1);
    }
    else{
        rep(i,N){
            if(i == N-1){
                retu.push_back(1);
                break;
            }
            if(S[i] != S[i+1])retu.push_back(1);
            else{
                retu.push_back(2);
                i++;
            }
        }
    }

    LL ans = 1;
    rep(i,retu.size()){
        if(i == 0){
            if(retu[i] == 1)ans *= 3;
            else ans *= 6;
        }
        else{
            if(retu[i-1] == 1 && retu[i] == 1)ans *= 2;
            else if(retu[i-1] == 1 && retu[i] == 2)ans *= 2;
            else if(retu[i-1] == 2 && retu[i] == 2)ans *= 3;
            else if(retu[i-1] == 2 && retu[i] == 1)ans *= 1;
            ans %= MOD;
        }
    }

    ans %= MOD;
    cout << ans << endl;
}


Measured memory_bytes: 256
h,w=map(int,input().split())
g=[input() for _ in range(h)]
def search(y,x):
	que=[(y,x)]
	vis=[[-1]*w for _ in range(h)]
	vis[y][x]=0
	while que:
		cy,cx=que.pop(0)
		for dy,dx in ((1,0),(-1,0),(0,1),(0,-1)):
			ny,nx=cy+dy,cx+dx
			if 0<=ny<h and 0<=nx<w and g[ny][nx]=="." and vis[ny][nx]==-1:
				vis[ny][nx]=vis[cy][cx]+1
				que.append((ny,nx))
	return max(max(l) for l in vis)
ans=0
for i in range(h):
	for j in range(w):
		if g[i][j]==".":
			ans=max(search(i,j),ans)
print(ans)


Measured memory_bytes: 3064
/*
digu_J - Digvijay Janartha
NIT Hamirpur - INDIA
*/

#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 >;
template < typename T > using MinPriorityQueue = priority_queue < T, vector < T >, greater < T > >;

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

typedef double db;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair < ll, ll > pll;
typedef pair < int, int > pii;
typedef vector < ll > vll;
typedef vector < int > vi;

#define eb emplace_back
#define pb push_back
#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define unique_sort(x) (sort(x.begin(), x.end()), x.resize(distance(x.begin(), unique(x.begin(), x.end()))))
#define fast_io() ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0)

const ll LINF = LLONG_MAX, base = 1e9, MOD = 1e9 + 7, N = 1e5 + 5, M = 1e3 + 5;
const int INF = INT_MAX;
const db PI = acos(-1);

void test();

int main() {
    fast_io();
    cout << fixed << setprecision(15);
    test();
    return 0;
}

void test() {
    ll n, x;
    cin >> n >> x;
    ll a, prev = 0, ans = 1;
    for (int i = 0; i < n; ++i) {
        cin >> a;
        prev = prev + a;
        ans += (prev <= x);
    }
    cout << ans << "\n";
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#ifndef ONLINE_JUDGE
#define dbg(x...) do { cout << "\033[32;1m " << #x << " -> "; err(x); } while (0)
void err() { cout << "\033[39;0m" << endl; }
template<template<typename...> class T, typename t, typename... A>
void err(T<t> a, A... x) { for (auto v: a) cout << v << ' '; err(x...); }
template<typename T, typename... A>
void err(T a, A... x) { cout << a << ' '; err(x...); }
#else
#define dbg(...)
#endif
typedef long long ll;
typedef pair<int,int> pi;
typedef vector<int> vi;
template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;
template<class T> void mkuni(vector<T>&v)
{
    sort(v.begin(),v.end());
    v.erase(unique(v.begin(),v.end()),v.end());
}
ll rand_int(ll l, ll r) //[l, r]
{
    static mt19937_64 gen(chrono::steady_clock::now().time_since_epoch().count());
    return uniform_int_distribution<ll>(l, r)(gen);
}
template<class T>
void print(T x,int suc=1)
{
    cout<<x;
    if(suc==1) cout<<'\n';
    else cout<<' ';
}
template<class T>
void print(const vector<T>&v,int suc=1)
{
    for(int i=0;i<v.size();i++)
    print(v[i],i==(int)(v.size())-1?suc:2);
}
int main()
{
    string s,t;
    cin>>s>>t;
    int a,b;
    cin>>a>>b;
    string u;
    cin>>u;
    if(u==s)a--;
    else b--;
    cout<<a<<" "<<b<<endl;
}

Measured memory_bytes: 256
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), ", ", cout) << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, string sep = " ", ostream &os = cout)
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

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

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), ", ", os) << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

int main()
{
    IN(ll, N);
    vi dp(N + 1);
    REP1(i, N)
    {
        for (ll j = i; j <= N; j += i)
        {
            ++dp[j];
        }
    }
    ll ans = 0;
    REP1(i, N)
    {
        ans += i * dp[i];
    }
    OUT(ans);
}

Measured memory_bytes: 81404
#include<bits/stdc++.h>
constexpr long long INFL = 1LL << 60;
constexpr int INF = 1 << 30;

using namespace std;

using ll = long long;
using P = tuple<int, int>;
using iarr = valarray<int>;
vector<vector<char>> v(22, vector<char>(22, '#'));

int bfs(int i, int j, vector<vector<char>>& m){
  queue<tuple<int, int, int>> q;
  q.push(make_tuple(i, j, 0));
  m[i][j] = '#';
  int max_cnt = -1;
  while(!q.empty()){
    int a = get<0>(q.front());
    int b = get<1>(q.front());
    int cnt = get<2>(q.front());
    if(max_cnt < cnt) max_cnt = cnt;
    q.pop();
    if(m[a+1][b] == '.'){
      q.push(make_tuple(a+1, b, cnt+1));
      m[a+1][b] = '#';
    }
    if(m[a-1][b] == '.'){
      q.push(make_tuple(a-1, b, cnt+1));
      m[a-1][b] = '#';
    }
    if(m[a][b+1] == '.'){
      q.push(make_tuple(a, b+1, cnt+1));
      m[a][b+1] = '#';
    }
    if(m[a][b-1] == '.'){
      q.push(make_tuple(a, b-1, cnt+1));
      m[a][b-1] = '#';
    }
  }
  return max_cnt;
}

int main()
{
  int h,w;
  cin >> h >> w;
  for(int i = 1; i <= h; ++i) for(int j = 1; j <= w; ++j) cin >> v[i][j];
  int max_cnt = -1;
  for(int i = 1; i <= h; ++i){
    for(int j = 1; j <= w; ++j){
      if(v[i][j] == '.'){
        vector<vector<char>> m(v);
        int cnt = bfs(i, j, m);
        if(max_cnt < cnt) max_cnt = cnt;
      }
    }
  }
  cout << max_cnt << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(int argc, char** argv) {
	int n;
	cin >> n;
	int d=0;
	for(int i=1;i<=100000;i++)
	{
		int cnt=0;
		for(int j=i/2;j<=100000;j++)
		{
			long long x=j,y=j-i;
			if(x*x*x*x*x-y*y*y*y*y>=n)
			{
				if(x*x*x*x*x-y*y*y*y*y==n)
				{
					cout << x << " " << y;
					return 0;
				}
				else break;
			}
			++cnt;
		}
		if(!cnt) break;
	}
	puts("dlstxdy!");
	return 0;
}

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

int main() {
  long N, A, B;
  cin >> N >> A >> B;
  if (A > B) return cout << 0 << "\n", 0;
  if (N == 1 && A != B) return cout << 0 << "\n", 0;
  long mx = A + B * (N - 1);
  long mi = A * (N - 1) + B;
  cout << mx - mi + 1 << "\n";
}

Measured memory_bytes: 3584
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	a := nextInt()
	b := nextInt()
	if (a+b)%2 == 1 {
		fmt.Println("IMPOSSIBLE")
	} else {
		fmt.Println((a + b) / 2)
	}
}


Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
const int ha=1e9+7;
int n;
int f[2000005];
int sum;
int main()
{
	scanf("%d",&n);
	f[n]=n;
	for(int i=n+1;i<=2*n;i++) f[i]=1;
	for(int i=n+2;i<=2*n;i++) sum+=f[i];
	for(int i=n-1;i>=1;i--)
	{
		f[i]=(f[i+1]+1ll*(n-1)*(n-1)%ha+sum)%ha;
		sum-=f[i+n+1];
		sum=(sum+f[i+2])%ha;
	}
	printf("%d\n",f[1]);
	return 0;
}
//f[i]=f[i+1]+(n-1)^2+f[i+3]+...+f[i+n+1](i<n)
//f[i]=f[i+1]+f[i+3]+...+f[i+n+1]=n(i==n)
//f[i]=1(i>n)
/*#include<iostream>//dfs(30points)
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
#define ha 1000000007
int n,ans;
int f[1000005];
int dfs(int p)
{
	if(p>n) return 1;
	int ans=0;
	if(f[p]) return f[p];
	else
	{
		ans=(ans+dfs(p+1))%ha;
		for(int i=2;i<=n;i++)
		{
			if(p<n) ans=(ans+n-1)%ha;
			ans=(ans+dfs(p+i+1))%ha;
		}
	}
	return f[p]=ans;
}
int main()
{
	scanf("%d",&n);
	ans=dfs(1);
	printf("%d\n",ans);
	return 0;
}*/

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

int main(void){
    int n;
    cin >> n;

    vector<bool> spade{0,0,0,0,0,0,0,0,0,0,0,0,0};
    vector<bool> heart{0,0,0,0,0,0,0,0,0,0,0,0,0};
    vector<bool> crover{0,0,0,0,0,0,0,0,0,0,0,0,0};
    vector<bool> diamond{0,0,0,0,0,0,0,0,0,0,0,0,0};
    for(int i=0;i<n;i++){
        int num_input;
        string mark_input;
        cin >> mark_input >> num_input;

        if(mark_input=="S")
            spade[num_input-1]   = true;
        if(mark_input=="H")
            heart[num_input-1]   = true;
        if(mark_input=="C")
            crover[num_input-1]  = true;
        if(mark_input=="D")
            diamond[num_input-1] = true;
    }


    for(int i=0;i<13;i++){
        if(spade[i] == false)
            cout << "S" << " " << i+1 << endl;
    }
    for(int i=0;i<13;i++){
        if(heart[i] == false)
            cout << "H" << " " << i+1 << endl;
    }
    for(int i=0;i<13;i++){
        if(crover[i] == false)
            cout << "C" << " " << i+1 << endl;
    }
    for(int i=0;i<13;i++){
        if(diamond[i] == false)
            cout << "D" << " " << i+1 << endl;
    }
}


Measured memory_bytes: 3160
import math
A,B,H,M = map(int, input().split())

A_ang = 30*H+30*M/60
B_ang = M*360/60

#print(A_ang, B_ang)
ang = A_ang - B_ang
out = A**2+B**2-2*A*B*math.cos(math.radians(ang))
print(math.sqrt(out))

Measured memory_bytes: 9500
#define fast ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#include <bits/stdc++.h>
using namespace std;
#define sqr 100
#define mp make_pair
#define mid (l+r)/2
#define le node * 2 
#define ri node * 2 + 1 
#define pb push_back
#define ppb pop_back
#define fi first
#define se second
#define lb lower_bound
#define ub upper_bound
#define ins insert
#define era erase
#define C continue
#define mem(dp,i) memset(dp,i,sizeof(dp))
#define mset multiset
#define all(x) x.begin(), x.end()
#define gc getchar_unlocked
typedef long long ll;
typedef short int si;
typedef double ld;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
typedef pair<double,ll>pdi;
const ll inf=2e18;
const ll mod=1e9+7;
const ld Pi=acos(-1) ;
ll n , q ;
vll in  [300009] , out [300009] ;
ll   l  [300009] , r   [300009] , val [300009] ; 
ll tree [1000009] , lzy [1000009] ;
void lzyUpd ( ll node , ll l , ll r ) {
	tree [node] += lzy [node] ;
	if ( l != r ) {
		lzy [le] += lzy [node] ;
		lzy [ri] += lzy [node] ;
	}
	lzy [node] = 0 ; 
}
void upd ( ll node , ll l , ll r , ll s , ll e , ll x ) {
	lzyUpd ( node , l , r ) ;
	if ( s > r || e < l ) return ;
	if ( s <= l && e >= r ) {
		lzy [node] += x ;
		lzyUpd ( node , l , r ) ;
		return ; 
	}
	upd ( le , l , mid , s , e , x ) ;
	upd ( ri , mid + 1 , r , s , e , x ) ;
	tree [node] = max ( tree [le] , tree [ri] ) ;
}
ll query ( ll node , ll l , ll r , ll s , ll e ) {
	lzyUpd ( node , l , r ) ;
	if ( s > r || e < l ) return -inf;
	if ( s <= l && e >= r ) return tree [node] ;
	return max ( query ( le , l , mid , s , e ) , query ( ri , mid + 1 , r , s , e ) ) ; 
}
int main () {
	cin >> n >> q ;
	for ( ll i = 1 ; i <= q ; i ++ ) {
		scanf ("%lld%lld%lld",&l [i] ,&r [i] ,&val [i] ) ;
		in  [l[i]] .pb ( i ) ;
		out [r[i]] .pb ( i ) ; 
	}
	ll ans = 0 , sum = 0 ;  
	for ( ll i = 1 ; i <= n ; i ++ ) {
		for ( auto u : in [i] ) {
			sum += val [u] ; 
		}
		ll dp = sum + query ( 1 , 0 , n , 0 , i - 1 ) ; 
		upd ( 1 , 0 , n , i , i , dp - sum ) ; 
		for ( auto u : out [i] ) {
			sum -= val [u] ;
			upd ( 1 , 0 , n , l [u] , r [u] , val [u] ) ; 	
		}
		ans = max ( ans , dp ) ; 
	}
	cout << ans << endl ; 
}


Measured memory_bytes: 43052
/*** 𝕒𝕜𝕤𝕙𝕒𝕪𝕜𝕦𝕞𝕒𝕣𝟡𝟡 ***/

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
template<typename T> using id_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update> ;
 
#define f(i,x,n) for(i=x;i<n;i++)
#define fr(i,x,n) for(i=x;i>=n;i--)
#define pu push_back           
#define pp pop_back
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define SP(x) fixed<<setprecision(x)
#define IOS() ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
const long long MOD=1e9+7;
const long double PI = acos(-1);
const long long INF=INT_MAX;
const long long LINF=LLONG_MAX;
const long long N=5e5+1;
 
typedef long long ll;
typedef long double ld;

ll blocksize = 2000, n, m, ans = 0;
ll a[N];
ll cont[N];

void remove(ll ind)
{
	if(cont[a[ind]] == 1)
		ans--;
    cont[a[ind]]--;
}
void add(ll ind)
{
    cont[a[ind]]++;
    if(cont[a[ind]] == 1)
		ans++;
}
ll getanswer()
{
    return ans;
}
struct Query
{
    ll l, r, ind;
    bool operator<(Query other) const
    {
        return make_pair(l/blocksize, r)<make_pair(other.l/blocksize, other.r);
    }
};

vector<ll> mosalgo(vector<Query> queries)
{
    vector<ll> answer(queries.size());
    sort(all(queries));
    ll curl=0, curr=-1;
    for(Query q : queries)
    {
        while(curl>q.l)
        {
            curl--;
            add(curl);
        }
        while(curr<q.r)
        {
            curr++;
            add(curr);
        }
        while(curl<q.l)
        {
            remove(curl);
            curl++;
        }
        while(curr>q.r)
        {
            remove(curr);
            curr--;
        }
        answer[q.ind]=getanswer();
    }
    return answer;
}

void test_case()
{
    cin >> n >> m;
    for(int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    vector<Query> v;
    for(int i = 0; i < m; i++)
    {
        ll x,y;
        cin >> x >> y;
        x--;y--;
        v.pu({x,y,i});
    }
    vector<ll> res = mosalgo(v);
    for(int i = 0; i < m; i++)
        cout<<res[i]<<'\n';

}

int main()
{
    IOS();
   
    int tc=1;
    // cin>>tc;
    while(tc--)
        test_case();
    return 0;
}

Measured memory_bytes: 38492
#include <stdio.h>
#include <algorithm>
using namespace std;
int n, x, a[30]; bool dp[1000001], prime[1000001];
int main() {
	prime[0] = true;
	for(int i = 2; i <= 1000000; i++) prime[i] = true;
	for(int i = 2; i <= 1000; i++) {
		if(!prime[i]) continue;
		for(int j = i * i; j <= 1000000; j += i) prime[j] = false;
	}
	while(scanf("%d%d", &n, &x), n) {
		for(int i = 0; i < n; i++) scanf("%d", &a[i]); sort(a, a + n);
		for(int i = 0; i < x; i++) dp[i + 1] = false; dp[0] = true;
		for(int i = 1; i <= x; i++) {
			for(int j = 0; j < n && i >= a[j]; j++) {
				if(dp[i - a[j]]) {
					dp[i] = true; break;
				}
			}
		}
		for(int i = x; i >= 0; i--) {
			if(dp[i] && prime[i]) {
				printf(i ? "%d\n" : "NA\n", i); break;
			}
		}
	}
}

Measured memory_bytes: 4620
#include<iostream>
#include<cstdio>
using namespace std;
int n,a,b;
long long ans=0;
int num(int x)
{
	int sum=0;
	while(x) 
	{
		sum+=x%10;
		x/=10;
	}
	return sum;
}
int main()
{
	scanf("%d%d%d",&n,&a,&b);
	for(int i=1;i<=n;i++)
		if(num(i)>=a&&num(i)<=b) ans+=i;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;
import java.util.Arrays;

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

        int n = sc.nextInt();
        int[] a = new int[n];
        String ans = "YES";
        int cnt = 0;

        for (int i = 0; i < n; i++ ) {
            a[i] = sc.nextInt();
        }
        int[] b = Arrays.copyOf(a, n);
        Arrays.sort(b);

        for(int i = 0; i < n; i++ ){
            if (a[i] != b[i]) cnt++;
            if (cnt > 2) {
                ans = "NO";
                break;
            }
        }

        System.out.println(ans);
        
        sc.close();
    }
}

Measured memory_bytes: 23892
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TupleSections #-}
{-# LANGUAGE RankNTypes #-}
import qualified Data.ByteString.Lazy.Char8 as B
import Data.Maybe
import Data.List
-- import qualified Data.Vector.Unboxed as VU
-- import qualified Data.Vector.Unboxed.Mutable as VUM
-- import Control.Monad
-- import Control.Monad.ST
-- import Debug.Trace
-- trace _ = id

solve :: Int -> [(Int,Int)] -> Int
solve n lst_ab = xtak - xaok
  where
    lst = sortOn (\(x,t) -> -x) (map f lst_ab)
      where 
        f :: (Int,Int) -> (Int, (Int,Int))
        f (a,b) = (a+b, (a,b))
    (tak, aok) = partition (\(p,q) -> even p) (zip [0..] lst)
    xtak = sum (map (fst.snd.snd) tak)
    xaok = sum (map (snd.snd.snd) aok)

readBInt :: B.ByteString -> Int
readBInt = fst . fromJust . B.readInt

tmain :: B.ByteString -> Int
tmain cont =
  let remLines0 = map B.words (B.lines cont)
      [bs_n]:remLines1 = remLines0
      n = readBInt bs_n
      abs = map (\[x1,x2] -> (readBInt x1,readBInt x2)) remLines1
  in solve n abs

outAnswer :: Int -> IO ()
outAnswer = putStrLn . show

main :: IO ()
main = outAnswer . tmain =<< B.getContents


-------------------------------------------------------------------------------

inp1 = "3\n10 10\n20 20\n30 30\n"
inp2 = "3\n20 10\n20 20\n20 30\n"
inp3 = "6\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n1 1000000000\n"
tv1 = tmain $ B.pack inp1
tv2 = tmain $ B.pack inp2
tv3 = tmain $ B.pack inp3
test1 = tv1 == 20
test2 = tv2 == 20
test3 = tv3 == -2999999997
alltest = test1 && test2 && test3



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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

struct UnionFind
{
    int i;
    vector<int> par;
    vector<int> size;
    UnionFind(int n): par(n),size(n,1){
        for(i = 0;i < n;++i){
            par.at(i) = i;
        }
    }
    
    int root(int x){
        if(par.at(x) == x){
            return x;
        }else{
            return par.at(x) = root(par.at(x));
        }
    }
    
    void unite(int x, int y){
        int rx = root(x);
        int ry = root(y);
        if(rx == ry){
            return;
        }else{
            if(size.at(rx) < size.at(ry)){
                swap(rx,ry);
            }
            par.at(ry) = rx;
            size.at(rx) += size.at(ry);
            return;
        }
    }
    
    bool same(int x, int y){
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
    
    int get_size(int x){
        return size.at(root(x));
    }
};

int main()
{
    ll i,j;
    ll n;
    cin >> n;
    vector<pair<ll,ll>> xy(n);
    for(i = 0;i < n;++i){
        cin >> xy.at(i).first >> xy.at(i).second;
    }
    ll ans = n;
    for(i = 0;i < n-1;++i){
        for(j = i+1;j < n;++j){
            ll tx = xy.at(j).first - xy.at(i).first;
            ll ty = xy.at(j).second - xy.at(i).second;
            ll k, l;
            UnionFind uf(n);
            for(k = 0;k < n-1;++k){
                for(l = k+1;l < n;++l){
                    ll sx = xy.at(l).first - xy.at(k).first;
                    ll sy = xy.at(l).second - xy.at(k).second;
                    if((sx == tx && sy == ty) || (sx == -tx && sy == -ty)) uf.unite(k, l);
                }
            }
            ll tmp = 0;
            for(k = 0;k < n;++k){
                if(uf.root(k) == k) ++tmp;
            }
            ans = min(ans, tmp);
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3560
#include<iostream>
#include<vector>
#include<algorithm>
#include <queue>
#include<string>
#include<utility>

#define lli long long
#define all(i) i.begin(),i.end()
#define rall(i) i.rbegin(),i.rend()
#define rep0(i,j) for(lli i=0;i<j;i++)
#define rep1(i,j) for(lli i=1;i<=j;i++)
#define rep0d(i,j) for(lli i=j-1;i>=0;i--)
#define MAX 1000000007
typedef struct tree Tree;

using namespace std;


bool cmpf(pair<lli, lli> left, pair<lli, lli> right) {
	return left.first < right.first;
}

struct tree {
	queue<lli> leaf;
	lli num;
};

Tree t[200001];

void dfs(lli n, lli num) {
	t[n].num += num;
	while (!t[n].leaf.empty()) {
		dfs(t[n].leaf.front(), t[n].num);
		t[n].leaf.pop();
	}

}
int main() {
	lli n, q;
	cin >> n >> q;
	lli a, b;
	rep0(i, n-1)cin >> a >> b, t[a].leaf.push(b),t[i].num=0;
	lli p, x;
	rep0(i, q)cin >> p >> x, t[p].num += x;
	dfs(1, 0);

	rep1(i, n)cout << t[i].num << ' ';
}


Measured memory_bytes: 144640
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h> 
#include <climits> 
#include <assert.h>
#include <random>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod2 = 1'000'000'007;
constexpr ll mod = 998244353;
const double PI = 3.14159265358;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// ---------------------------------------------------------------------------

struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};



int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  ll A,B,K;
  cin >> A >> B >> K;
  mint ans = 0;
  combination c(N);
  for(int i=0; i<=N; i++){
    if(A*i > K) break;
    if((K-A*i)%B == 0){
      ans += c(N,i) * c(N,(K-A*i)/B);
    }    
  }
  cout << ans.x << "\n";
  return 0;
}

Measured memory_bytes: 7960
#include <bits/stdc++.h>
using namespace std;
int main(){
    unsigned long long N,M;
    cin >> N >> M;
    if(N==1 && M==1) cout << 1 << endl;
    else if(N==1 || M==1) cout << max(N,M)-2 << endl;
    else cout << (N-2)*(M-2) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

int xx,yy,zz;
int pr(char c)
{
    if(c=='+') return xx;
    if(c=='-') return yy;
    if(c=='*') return zz;
    assert(false);
}

ll E(string s)
{
    int S=s.size();
    int idx = 0;

    vector<ll> val;
    vector<char> op;

    while(idx<S)
    {
        if(s[idx]=='+' || s[idx]=='-' || s[idx]=='*') op.pb(s[idx++]);
        else
        {
            if(s[idx]=='(')
            {
                int b = 1;
                ++idx;
                int st = idx;
                while(b>0)
                {
                    if(s[idx]=='(') ++b;
                    else if(s[idx]==')') --b;
                    ++idx;
                }

                val.pb(E(s.substr(st,idx-1-st)));
            }
            else
            {
                int st = idx;
                while('0'<=s[idx] && s[idx]<='9') ++idx;
                val.pb(atoll(s.substr(st,idx-st).c_str()));
            }
        }
    }

    rep(i,3)
    {
        vector<ll> tv;
        vector<char> to;

        tv.pb(val[0]);
        rep(j,op.size())
        {
            char c = op[j];
            if(pr(c)==i)
            {
                int TV = tv.size();
                if(c=='+') tv[TV-1] = tv[TV-1]+val[j+1];
                if(c=='-') tv[TV-1] = tv[TV-1]-val[j+1];
                if(c=='*') tv[TV-1] = tv[TV-1]*val[j+1];
            }
            else
            {
                to.pb(c);
                tv.pb(val[j+1]);
            }
        }

        val = tv;
        op = to;
    }

    return val[0];
}

int main()
{
    string s;
    cin >>s;
    ll ans = -LLONG_MAX;
    for(xx=0; xx<3; ++xx)for(yy=0; yy<3; ++yy)for(zz=0; zz<3; ++zz) ans = max(ans,E(s));
    cout << ans << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;

ll rec( int N, ll X){
  if( N == 0){ return 1;}
  
  ll length = ( 1LL << ( N + 1) ) - 3;
  ll number = ( 1LL << ( N ) ) - 1;
  
  if( X == 1){ return 0;}
  else if( X <= length + 1){ return rec( N - 1, X - 1);}
  else if( X == length + 2){ return number + 1;}
  else if( X <= 2 * length + 2){
    return number + 1 +  rec( N - 1, X - length - 2);}
  else if( X == 2*length + 3){ return 2 * number + 1; }
  
}

int main(){
  int N; ll X; cin >> N >> X;
  cout << rec(N,X) << endl;
  return 0;}

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


#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()


bool my_cp(pair<int, int> a, pair<int, int> b){
  return (double)b.first / (double)(b.second+1) < (double)a.first / (double)(a.second+1);
}



// substr(start, len)

int main(){
  int N, R, rate;

  cin >> N >> R;

  if(N >= 10){
    rate = R;
  }else{
    rate = R + 100*(10-N);
  }

  cout << rate << endl;
  

// CHECK if it's possible to overflow!!
}

Measured memory_bytes: 256