akhauriyash/Code-Regression huggingface dataset:
use std::io;
use std::str::FromStr;

fn input_tuple() -> (usize, usize) {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    let vec: Vec<usize> = line.split_whitespace().map(|s| s.parse().unwrap()).collect();
    (vec[0], vec[1])
}

fn input_vec() -> Vec<usize> {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.split_whitespace().map(|s| s.parse().unwrap()).collect()
}

fn main() {
    let (n, m) = input_tuple();
    let h_vec = input_vec();
    let mut h_max = vec![0usize; n];
    for _ in 0..m {
        let (a, b) = input_tuple();
        if h_vec[a - 1] > h_max[b - 1] {
            h_max[b - 1] = h_vec[a - 1];
        }
        if h_vec[b - 1] > h_max[a - 1] {
            h_max[a - 1] = h_vec[b - 1];
        }
    }
    let mut sum = 0;
    // println!("{:?}", h_max);
    for i in 0..n {
        if h_vec[i] > h_max[i] {
            sum += 1;
        }
    }
    println!("{}", sum);
}


Measured memory_bytes: 3964
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace keyence2020_a
{
  class Program
  {
    static void Main(string[] args)
    {
      var H = CIn.ReadInt();
      var W = CIn.ReadInt();
      var N = CIn.ReadInt();

      var ans = (int)Math.Ceiling((double)N / Math.Max(H, W));

      Console.WriteLine(ans);
    }
  }

  static class CIn
  {
    private static readonly Queue<string> fieldBuffer = new Queue<string>();

    public static string Read()
    {
      if (fieldBuffer.Count == 0)
      {
        foreach (var field in Console.ReadLine().Split())
        {
          fieldBuffer.Enqueue(field);
        }
      }
      return fieldBuffer.Dequeue();
    }

    public static int ReadInt() => int.Parse(Read());
    public static long ReadLong() => long.Parse(Read());
    public static double ReadDouble() => double.Parse(Read());

    public static string[] ReadStringArray(long n)
    {
      var array = new string[n];
      for (var i = 0L; i < n; i++)
      {
        array[i] = Read();
      }
      return array;
    }

    public static int[] ReadIntArray(long n)
    {
      var array = new int[n];
      for (var i = 0L; i < n; i++)
      {
        array[i] = ReadInt();
      }
      return array;
    }

    public static long[] ReadLongArray(long n)
    {
      var array = new long[n];
      for (var i = 0L; i < n; i++)
      {
        array[i] = ReadLong();
      }
      return array;
    }

    public static double[] ReadDoubleArray(long n)
    {
      var array = new double[n];
      for (var i = 0L; i < n; i++)
      {
        array[i] = ReadDouble();
      }
      return array;
    }

    public static char[,] ReadCharMatrix(long h, long w)
    {
      var array = new char[h, w];
      for (var i = 0L; i < h; i++)
      {
        var l = Console.ReadLine().ToCharArray();
        for (var j = 0L; j < w; j++)
        {
          array[i, j] = l[j];
        }
      }
      return array;
    }
  }
}


Measured memory_bytes: 11220
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
#include <limits>
using namespace std;
// 素因数分解
typedef pair<long long, long long> P;
vector<P> prime_factorize(long long n)
{
vector<P> res;
for (long long p = 2; p * p <= n; ++p)
{
if (n % p != 0)
continue;
int num = 0;
while (n % p == 0)
{
++num;
n /= p;
}
res.push_back(make_pair(p, num));
}
if (n != 1)
res.push_back(make_pair(n, 1));
return res;
}
// 因数分解
long long gcd(long long x, long long y)
{
  if (y == 0)
  {
    return x;
  }
  else
  {
    return gcd(y, x % y);
  }
}
const int MOD = 1000000007;
typedef long long int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, n) for (int i = 0; i < (n); i++)

void rec(int d,ll val,vector<ll> &all){
    all.push_back(val);

    if(d==10){
        return;
    }
    for (int j = -1; j <= 1;j++){
        int add = (val % 10) + j;
        if(0<=add&&add<=9){
            rec(d + 1, val * 10 + add, all);
        }
    }
}

int main()
{
    int k;
    cin >> k;
    vector<ll> all;
    for (int v = 1; v < 10;v++){
        rec(1, v, all);
    }
    sort(all.begin(), all.end());
    cout << all[k - 1] << endl;
    return 0;
}

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

int main()
{
	int a, b, c, d, n;
	cin >> a >> b >> c >> d;
	cin >> n;
	long long ans = (long long)n*min(1ll*c, min(2ll*b, 4ll*a));
	ans = min(ans, (n&1)*min(1ll*c, min(2ll*b, 4ll*a))+1ll*(n/2)*d);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstdio>
using namespace std;
const int MAX = 100000;

int par[MAX],rank[MAX],n,m;

void init(int n){
  for(int i = 0 ; i < n ; i++){
    par[i] = i;
    rank[i] = 0;
  }
}

int find(int x){
  if(par[x] == x) return x;
    return par[x] = find(par[x]);
}

void unite(int x,int y){
  x = find(x); y = find(y);
  if(x == y) return;

  if(rank[x] < rank[y]){
    par[x] = y;
  } else {
    par[y] = x;
    if(rank[x] == rank[y]) rank[x]++;
  }
}

bool same(int x,int y){
  return find(x) == find(y);
}

int kruskal(pair<int,pair<int,int> > es[MAX]){
  sort(es,es + m);
  init(n);
  int res = 0;
  for(int i = 0 ; i < m ; i++){
    int a = es[i].second.first;
    int b = es[i].second.second;
    if(!same(a,b)){
      res += es[i].first;
      unite(a,b);
    }
  }
  return res;
}

int main(){
  while(cin >> n,n){
    cin >> m;
    pair<int,pair<int,int> > es[MAX];
    for(int i = 0 ; i < m ; i++){
      scanf("%d,%d,%d", &es[i].second.first, &es[i].second.second,&es[i].first);
    }
    for(int i = 0 ; i < m ; i++){
      es[i].first = es[i].first/100-1;
    }

    cout << kruskal(es) << endl;
  }

  return 0;
}

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

using namespace std;

int main() {
	int H, W;
	vector<vector<char>> map;

	cin >> H >> W;

	for (int i = 0; i < H; i++) {
		map.push_back(vector<char>());
		for (int j = 0; j < W; j++) {
			char tmp;
			cin >> tmp;
			map[i].push_back(tmp);
		}
	}

	int j;
	//行消去操作
	for (int i = 0; i < map.size(); i++) {
		for (j = 0; j < W; j++) {
			if (map[i][j] == '#')
				break;
		}
		if (j == W) {
			map.erase(map.begin() + i);
			i--;
		}
	}

	//列消去操作
	for (int i = 0; map.size() > 0 && i < map[0].size(); i++) {
		for (j = 0; j < map.size(); j++) {
			if (map[j][i] == '#')
				break;
		}
		if (j == map.size()) {
			for (int k = 0; k < map.size(); k++)
				map[k].erase(map[k].begin() + i);
			i--;
		}
	}

	for (int i = 0; i < map.size(); i++) {
		for (int j = 0; j < map[0].size(); j++) {
			cout << map[i][j];
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 256
import itertools,math,numpy as np
def I(): return int(input())
def LI(): return list(map(int,input().split()))
N = I()
xy = np.array([LI() for _ in range(N)])
sum_norm = 0
dict_norm = {}
for a in itertools.permutations(range(N)):
    for i in range(len(a)-1):
        vector = tuple(xy[a[i+1]]-xy[a[i]])
        if not vector in dict_norm:
            dict_norm[vector] = np.linalg.norm(vector)
            vector_inverse = tuple(xy[a[i]]-xy[a[i+1]])
            dict_norm[vector_inverse] = dict_norm[vector]
        sum_norm += dict_norm[vector]
print(sum_norm/math.factorial(N))


Measured memory_bytes: 12424
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

    FastScanner in;
    PrintWriter out;

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

    void solve() {
        int H = in.nextInt();
        int W = in.nextInt();
        int[][] c = new int[10][10];
        for (int i = 0; i < 10; i++) {
            for (int j = 0; j < 10; j++) {
                c[i][j] = in.nextInt();
            }
        }
        for (int k = 0; k < 10; k++) {
            for (int i = 0; i < 10; i++) {
                for (int j = 0; j < 10; j++) {
                    c[i][j] = Math.min(c[i][j], c[i][k] + c[k][j]);
                }
            }
        }
        int result = 0;
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                int temp = in.nextInt();
                if (temp >= 0) {
                    result += c[temp][1];
                }
            }
        }
        System.out.println(result);


    }


    void run() {
        in = new FastScanner();
        out = new PrintWriter(System.out);
        solve();
        out.close();
    }

    public class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        public FastScanner(String s) {
            try {
                br = new BufferedReader(new FileReader(s));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        public String nextToken() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(nextToken());
        }

        public long nextLong() {
            return Long.parseLong(nextToken());
        }

        public double nextDouble() {
            return Double.parseDouble(nextToken());
        }
    }

}

Measured memory_bytes: 26624
#include<cstring>
#include<iostream>
using namespace std;
long long f[305][305];
	int h[305];
int main()
{
	int n,k;
	long long ans=1e18;
	cin>>n>>k;
	for(int i=1;i<=n;i++)
	cin>>h[i];
	memset(f,63,sizeof(f));
	if(n==k){
	cout<<0<<endl;
	return 0;
}
	for(int i=n;i;i--){
	f[i][1]=h[i];
	for(int j=2;j<=n-k;j++)
	for(int p=i-1;p;p--)
	f[p][j]=min(f[p][j],f[i][j-1]+max(0,h[p]-h[i]));
}
	for(int i=1;i<=n;i++)
	ans=min(ans,f[i][n-k]);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4304
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> P;

template <typename T> T gcd(T x, T y) { return( y ? gcd(y, x % y) : x); }
template <typename T> T lcm(T x, T y) { return( x / gcd(x, y) * y); }
template <typename T> void printVec(vector<T> &vec) {
  cout << "";
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    cout << *it << " ";
  }
  cout << endl;
}

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

  x = n % 10;
  if (x == 2 || x == 4 || x == 5 || x == 7 || x == 9) {
    cout << "hon" << endl;
  } else if (x == 0 || x == 1 || x == 6 || x == 8) {
    cout << "pon" << endl;
  } else {
    cout << "bon" << endl;
  }
	return 0;
}

Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

int main(void) {
	ll n;
	cin >> n;
	
	for(ll i = 1; i <= n; ++i) {
		ll tmp = i * (i + 1LL) / 2LL;
		
		if( tmp >= n ) {
			for(ll j = i; j >= 1; --j) {
				if( j <= n ) {		
					cout << j << endl;
					n -= j;
				}
			}
			
			break;
		}		
	}
	
	return 0;
}


Measured memory_bytes: 3576
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>
#include <utility>
#include <numeric>

using namespace std;

int main(){

    int N, X;
    cin >> N >> X;
    int ans = 1;
    int L;
    int temp = 0;
    for(int i = 0; i < N; i++){
        cin >> L;
        
        temp += L;
        if(temp <= X){
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
a = int(input())
b = input()
chr_a = 0
ans = ''
for i in range(len(b)):
    if ord(b[i]) + a <= 90:
        chr_a = ord(b[i]) + a
    else:
        chr_a = ord(b[i]) + a -26
    ans += chr(chr_a)
print(ans)

Measured memory_bytes: 3060
#include <cstdio>
#include <algorithm>
#include <string>
#include <iostream>
using namespace std;

int n, a[110], ans = 987654321;

int main()
{
    scanf("%d", &n);
    for(int i = 0 ; i < n ; i++ )
        scanf("%d", a+i);
    for(int x = -100 ; x <= 100 ; x++ )
    {
        int temp = 0;
        for(int i = 0 ; i < n ; i++ )
        {
            temp += (x-a[i])*(x-a[i]);
        }
        ans = min( ans, temp );
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

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

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

func dist(r, l int) int {
	return min(diff(0, r)+diff(r, l), diff(0, l)+diff(l, r))
}

func main() {
	var N, K int
	fmt.Scan(&N, &K)
	xs := make([]int, N)
	for i := range xs {
		fmt.Scan(&xs[i])
	}

	min := dist(xs[0], xs[K-1])
	for i := 0; i+K-1 < len(xs); i++ {
		l := xs[i]
		r := xs[i+K-1]
		if v := dist(l, r); v < min {
			min = v
		}
	}
	fmt.Println(min)
}


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

template< typename T >
void divisor(T n, vector<T>& divisors) {
    T root_n = (T)sqrt(n);
    for (int i = 1; i <= root_n; ++i) {
        if (n % i == 0) {
            divisors.push_back(i);
            if (n / i != i) divisors.push_back(n / i);
        }
    }
}

template<class T>
void printIter(const T &a, string delimiter) {
    if (a.size() == 0) return;
    auto it = a.begin();
    cout << *it;
    it++;
    while (it != a.end()) {
        cout << delimiter << *it;
        it++;
    }
    cout << endl;
}

int main() {
    int n;
    cin >> n;
    int cnt = 0;
    for (int i = 1; i <= n; i += 2) {
        vector<int> div;
        divisor(i, div);
        if (div.size() == 8) {
            cnt++;
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 3732
#include<iostream>
#include<vector>
#include<queue>

using namespace std;

struct Edge{
    int to, id;
};

int main(){
    int n;
    cin >> n;
    vector<vector<Edge>> g(n);
    vector<int> ans(n-1);
    for (int i = 0; i < n-1; i++)
    {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        g[a].push_back((Edge){b, i});
        g[b].push_back((Edge){a, i});
    }
    queue<int> q;
    vector<bool> searched(n,false);
    vector<int> pc(n, 0);
    q.push(0);
    searched[0] = true;
    pc[0] = 0;
    ans[0] = 0;
    while (!q.empty())
    {
        int v = q.front();
        q.pop();
        int color = 1;
        for (auto edge : g[v]) //explore not searched edge that is being linked node v
        {
            int to = edge.to;
            int id = edge.id;
            if(searched[to])
                continue;
            if(color==pc[v])
            {
                color++;
            }
            pc[to] = color;
            ans[id] = color;
            color++;
            q.push(to);
            searched[to] = true;
        }
    }
    int mx = 0;
    for (int i : ans)
    {
        mx = (mx < i) ? i : mx;
    }
    cout << mx << endl;
    for (int id = 0; id < n - 1; id++)
    {
        cout << ans[id] << endl;
    }
    return 0;
}


Measured memory_bytes: 7424
#include <iostream>
#include <cmath>
using namespace std;
int main(void){
    // Your code here!
    int a,b;
    cin >> a >> b;
    if (abs(a+b)%2 == 0) {
        cout << (a+b)/2 << endl;
    }else{
        cout << "IMPOSSIBLE" << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,l,n) for(int i = l; i < (n); i++)
using namespace std;
using ll = long long;
int main() {
  int n;
  int a[10][10] = {};
  scanf("%d",&n);
  rep(i,1,n+1) {
    string tmp = to_string(i);
    a[tmp.at(0)-'0'][tmp.at(tmp.size()-1)-'0']++;
  }
  ll ans = 0;
  rep(i,1,10)rep(j,1,10) ans += a[i][j]*a[j][i];
  printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 384
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")

#include <iostream>
#include <stdlib.h>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <random>
#include <assert.h>
#include <memory.h>
#include <time.h>

#define uint unsigned int
#define ll long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)

using namespace std;

inline void setmin(int &x, int y) { if (y < x) x = y; }
inline void setmax(int &x, int y) { if (y > x) x = y; }
inline void setmin(ll &x, ll y) { if (y < x) x = y; }
inline void setmax(ll &x, ll y) { if (y > x) x = y; }

const int N = 100000;
const int inf = (int)1e9 + 1;
const ll big = (ll)1e18 + 1;
const int P = 239;
const int P1 = 31;
const int P2 = 57;
const int MOD = (int)1e9 + 7;
const int MOD1 = (int)1e9 + 9;
const int MOD2 = 998244353;
const double eps = 1e-9;
const double pi = atan2(0, -1);
const int ABC = 52;

int main()
{
    //freopen("a.in", "r", stdin);
    //freopen("a.out", "w", stdout);
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(20);
    cout << fixed;
    //ll TL = 0.95 * CLOCKS_PER_SEC;
    //clock_t time = clock();
    int cnt[4];
    fill(cnt, cnt + 4, 0);
    rep(i, 0, 3) {
        int x, y;
        cin >> x >> y;
        x--; y--;
        cnt[x]++; cnt[y]++;
    }
    sort(cnt, cnt + 4);
    if (cnt[0] == 1 && cnt[1] == 1 && cnt[2] == 2 && cnt[3] == 2) {
        cout << "YES\n";
    } else {
        cout << "NO\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REPR(i,n) for(int i=(n)-1;i>=0;i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase( unique(ALL(v)) , v.end());
#define PAU system("pause")

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vb> vvb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 28);
const double PI = acos(-1);

struct City {
	int Y, P, i;
	City(){}
	City(int _i, int _Y, int _P) {
		Y = _Y;
		P = _P;
		i = _i;
	}
	bool operator<(const City& c) const {
		return Y < c.Y;
	}
};

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N, M;
	cin >> N >> M;
	vi VP(M);
	vector<City> VC;
	REP(i, M) {
		int P, Y;
		cin >> P >> Y;
		VP[i] = P;
		VC.push_back(City(i, Y, P));
	}
	so(VC);
	vi Rank(M);
	vi VPR(N + 1, 0);
	REP(i, M) {
		Rank[VC[i].i] = VPR[VC[i].P] + 1;
		VPR[VC[i].P]++;
	}
	REP(i, M) {
		printf("%06d%06d\n", VP[i], Rank[i]);
	}
	PAU;
	return 0;
}


Measured memory_bytes: 4076
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=(a);i<(b);i++)
#define qi queue<int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second
#define prq priority_queue
#define foreach(it,c) for(__typeof((c).begin()) it=c.begin();it!=c.end();it++)
//#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
using namespace std;
inline ll read(){
	ll x=0;
	int f=1;
	char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-')f=-f;
	for(;isdigit(c);c=getchar())x=x*10+(c-'0');
	return x*f;
}
inline void out(int x){
	if(x>=10)out(x/10);
	putchar(x%10+'0');
}
int main(){
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	double n;
	cin>>n;
	for(double i=0.0;i<=n;i+=1.0) if(floor(i*1.08)==n){
		cout<<i<<endl;
		return 0;
	}
	cout<<":(\n";
	return 0;
}

Measured memory_bytes: 256
n, a, b, c, d = map(int, input().split())
s = input()
a -= 1; b -= 1; c -= 1; d -= 1; e = 1
for i in range(b, min(c, d)+1):
    if s[i-1] == "." and s[i] == "." and s[i+1] == ".": e = 0
if c < d: e = 0
for i in range(a, max(c, d)):
    if s[i] == "#" and s[i+1] == "#": e = 1
print("Yes") if e == 0 else print("No")

Measured memory_bytes: 9448
fact :: Int -> Int
fact 1 = 1
fact n = n * fact (n - 1) `mod` 1000000007

solve :: Int -> Int -> Int
solve n m
  | n == m = (fact n * fact m * 2) `mod` 1000000007
  | abs (n - m) == 1 = (fact n * fact m) `mod` 1000000007
  | otherwise = 0

main :: IO ()
main = do
  [n, m] <- map read . words <$> getLine
  print $ solve n m

Measured memory_bytes: 3068
#include <bits/stdc++.h>
// #include <iostream>
// #include <vector>
// #include <map>
// #include <algorithm>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())

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

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

// レベル n のバーガーの総レイヤー数
ll numlayer(ll n){
    return (ll)pow(2, n+2) - 3;
}

// レベル n に含まれるパティの数
ll nump(ll n){
    return (ll)pow(2, n+1) - 1;
}

ll countpaty(ll N, ll X){
    if (N == 0) {
        return (X <= 0) ? 0 : 1;
    }

    if (X <= 1 + numlayer(N-1)) {
        return countpaty(N-1, X-1);
    }else{
        return nump(N-1) + 1 + countpaty(N-1, X-2-numlayer(N-1));
    }

}


void solve(){
    ll N, X;
    cin >> N >> X;
    cout << countpaty(N, X) << endl;

    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


Measured memory_bytes: 256
import heapq

INF = 10 ** 7

def Z(): return int(input())
def ZZ(): return [int(_) for _ in input().split()]

def main():
    H, W = ZZ()
    C = [ZZ() for _ in range(10)]
    A = [ZZ() for _ in range(H)]

    def dijkstra(s):
        que = list()
        heapq.heapify(que)
        cost = [INF] * (10)
        cost[s] = 0
        heapq.heappush(que, [cost[s], s])

        while que:
            v = heapq.heappop(que)
            if cost[v[1]] < v[0]: continue
            for i in range(10):
                if cost[i] > cost[v[1]] + C[v[1]][i]:
                    cost[i] = cost[v[1]] + C[v[1]][i]
                    heapq.heappush(que, [cost[i], i])
        return cost[1]

    mc = [INF] * 10
    for i in range(10): mc[i] = dijkstra(i)
    output = 0
    for i in range(H):
         for j in range(W):
             if A[i][j] == -1: continue
             output += mc[A[i][j]]
    print(output)

    return

if __name__ == '__main__':
    main()


Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

signed main() {
    int n, m;
    cin >> n >> m;
    string s;
    cin >> s;
    int a, b;
    vector<int> G[n];
    int outdeg[2][n];
    fill(outdeg[0], outdeg[2], 0);
    rep(i, m) {
        cin >> a >> b;
        a--;
        b--;
        G[a].emplace_back(b);
        outdeg[s[a] - 'A'][b]++;
        if (a == b) continue;
        G[b].emplace_back(a);
        outdeg[s[b] - 'A'][a]++;
    }
    queue<int> que;
    bool deleted[n] = {};
    int sum = n;
    rep(i, n) {
        int mn = min(outdeg[0][i], outdeg[1][i]);
        if (mn == 0){
            que.emplace(i);
            deleted[i] = true;
            sum--;
        }
    }
    while(!que.empty()){
        int v = que.front();
        que.pop();
        for (int from : G[v]) {
            if (deleted[from]) continue;
            outdeg[s[v] - 'A'][from]--;
            if (outdeg[s[v] - 'A'][from] == 0) {
                que.emplace(from);
                deleted[from] = true;
                sum--;
            }
        }
    }
    cout << (sum > 0 ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 15408
N,K = map(int, input().split())
A = list(map(int,input().split()))
 
def souwa(num):
    if num % 2 == 0:
        return int((num+1) * (num/2))
    else:
        return int((num+1) * (num//2)) + ((num//2)+1)
 
ans = 0
for i in range(N):
    buf1 = sum(A[i] > A[j] for j in range(i+1, N))
    buf2 = sum(A[i] > a for a in A)
    ans += (buf1 * K) + (buf2 * (K*(K-1)//2))
 
print(ans % (10**9+7))

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const int MAX_BIT = (int)(5e3 + 5);

int n, m;

vector<ll> as;
vector<int> cs;

ll memo[MAX_BIT];

int main(void) {
  // Here your code !
  scanf("%d %d", &n, &m);

  for (int i = 0; i < m; ++i) {
    ll a;
    int b;
    scanf("%lld %d", &a, &b);
    as.push_back(a);

    int empty_bit = 0;
    cs.push_back(empty_bit);

    for (int j = 0; j < b; ++j) {
      int c;
      scanf("%d", &c);

      cs.back() |= (1 << (c - 1));
    }
  }

  for (int i = 0; i < MAX_BIT; ++i) {
    memo[i] = INF;
  }

  int empty_bit = 0;
  memo[empty_bit] = 0L;

  for (int b = 0; b < (1 << n); ++b) {
    if (memo[b] == INF) continue;

    for (int i = 0; i < cs.size(); ++i) {
      int new_bit = b;

      new_bit |= cs[i];

      memo[new_bit] = min(memo[new_bit], memo[b] + as[i]);
    }
  }

  int key = 0;
  for (int i = 0; i < n; ++i) {
    key |= (1 << i);
  }

  if (memo[key] == INF) {
    printf("%lld\n", -1L);
  } else {
    printf("%lld\n", memo[key]);
  }

  return 0;
}


Measured memory_bytes: 256
// Problem : C - Sqrt Inequality
// Contest : AtCoder - Panasonic Programming Contest 2020
// URL : https://atcoder.jp/contests/panasonic2020/tasks/panasonic2020_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#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;

//Macros

#define ll long long
#define db long double
#define pb push_back
#define eb emplace_back
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define mi map<int,int>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define inf 1e10
#define PI acos(-1.0)
#define int long long
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define N 100005

//Solution

void solve(){
    int a,b,c;
    cin>>a>>b>>c;
    if(c < a+b){
        cout<<"No\n";
        return;
    }
    if(a*a+b*b+c*c > 2*a*c+2*b*c+2*a*b) cout<<"Yes\n";
    else cout<<"No\n";
}

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    int tests;
    //cin>>tests;
    tests = 1;
    while(tests--){
        solve();
    }
    return 0;
}

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

/*
,,,,
　　　　　　　　　　　　　　　　　　　　　　　　　　,.斗*''“i:i:{
　　　　　　　　　　　　　,.　｡. . . * : : : ''' : : : :” :”“ ''ｰ - 弋,,_
　　　　　 　 　 ,.斗*''“ : : : : : : : : : : : : : ' ' ' ' ' ' : : : : : : : : : : :”: '':* ｡ ,
　　　 ,.斗*''“ ” ＼：　　 ”・・． ' ' ' '　　　　　　　　 ' ' ' ' : : : : : : : : : : : : ”ミ*｡,,,,,,　　　　　　 　 　 　 ＿
　　く.　 ◎　 ﾞ:.ﾞ:..　ﾟ:,　:　───────────　　　--　　,,,,,,__ ' ' ' :.:.:.:.:.”≧s｡.　　＿,,,｡s*i:i:i:i:<
　　ﾏ*s｡ :,　 }　ﾟ:,　 :}　　　　　　　　　　　　　　　　　　　　　　　　　　　　”　''　-　”””：：”：：`*｡i:i:i:i:i:i:i;:’
　　　` .｡`　 ,　,ノ ／｡ ,,,_　　　　　　　　　　　　　　　　　　　　　　　　　　　　　＿＿`　　} }　　ﾉi:i:i:i:i:ﾂ
　　　　　 `　*　｡　　`*｡i:i:i::*=-　　　　　　　　　　　＿＿　　　　　　,,,....｡s*'i,:’　　　”`*｡＿,*’i:i:i:i:r’
　　　　　　　　　　　”　─ --　　　　｡｡｡｡｡　　 -　－`''''''''ヽ ─ '''”　　　｀ｰ“　　　　　　　`*｡i:i:i:i:i:i:
　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　`*｡i:i:::
　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　　`*ﾟ:,
         fozubaoyou    no BUGs alive!
*/

typedef long long ll;

//{
#define mp make_pair
#define nsort(a) sort(a.begin(),a.end())
#define rsort(a) sort(a.rbegin(),a.rend())
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define dumo dump
#define hi debug("hi");
//}

#define debug_interval ','
#define dump_interval endl
#define debug_toggle 0

//{
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class...A> inline void dump(){cout<<endl;}
template<class...A> inline void dump_rest() {cout<<endl;}
template<class T, class...A> inline void dump_rest(const T& first, const A&... rest){cout<<dump_interval<<first;dump_rest(rest...);}
template<class T,class...A> inline void dump(const T&first,const A&...rest){cout<<first;dump_rest(rest...);}
template<class...A> inline void debug(){cout<<endl;}
template<class...A> inline void debug_rest() {cout<<endl;}
template<class T, class...A> inline void debug_rest(const T& first, const A&... rest){cout<<debug_interval<<first;debug_rest(rest...);}
template<class T,class...A> inline void debug(const T&first,const A&...rest){if(debug_toggle)cout<<first,debug_rest(rest...);}
//}

int n,c,ans,l;
string s;
char np;


int main(){
    cin>>n>>s;
    for(int i=1;i<n;i++){
        if(s[i]=='E')c++;
    }
    ans=c;
    np=s[0];
    for(int i=1;i<n;i++){
        if(s[i]=='E')c--;
        if(s[i-1]=='W') c++;
        ans=min(ans,c);
    }
    dump(ans);
}

Measured memory_bytes: 900
#include <bits/stdc++.h>
//#include <ext/numeric>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
#define oo 0x3f3f3f3f
#define OO 0x3f3f3f3f3f3f3f3f
#define popcount(n) __builtin_popcount(n)
#define popcountll(n) __builtin_popcountll(n)

using namespace std;
//using namespace __gnu_cxx;
using namespace __gnu_pbds;
template<typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const double PI = acos(-1.0), EPS = 1e-6;
const long long inf = 2e12 + 12;
const int MAXN = 100005, MAXM = 1003, Mod = 1000000007 , MAXLog = 20;



int main() {
#ifndef ONLINE_JUDGE
//    freopen("input.txt", "rt", stdin);
//    freopen("output.txt", "w", stdout);
#endif
    ios::sync_with_stdio(false), cin.tie(0), cout.tie(0), cout.precision(9), cout << fixed;

    int n;
    cin >> n;
    vector<pair<int, int>> arr(n);
    for (int i = 0; i < n; ++i) {
        cin >> arr[i].second >> arr[i].first;
    }

    sort(arr.begin(), arr.end());

    long long t = 0;
    for (int i = 0; i < n; ++i) {
//        cout << arr[i].first << ' ' << t << ' ' << arr[i].second.first << ' ' << arr[i].second.second << '\n';
        if (t + arr[i].second > arr[i].first) {
            cout << "No\n";
            return 0;
        } else {
            t += arr[i].second;
        }
    }

    cout << "Yes\n";

    return 0;
}

Measured memory_bytes: 1792
n = gets.to_i
member = Array.new(n){[false, false, false]}
3.times{|i|
    arr = gets.chomp.split.map(&:to_i)
    arr[1..-1].each{|x| member[x - 1][i] = true}
}
count = 0
member.each{|a, b, c| count += 1 if (!a || b) && c}
puts count


Measured memory_bytes: 6880
import itertools
if __name__ == "__main__":
    n = int(input())
    p = list(map(int, input().split()))
    q = list(map(int, input().split()))

    l = [i for i in range(1, n + 1)]
    two = []
    
    for i, v in enumerate(itertools.permutations(l)):
        tmp = 0
        for j in range(n):
            if v[j] == p[j]:
                tmp += 1
        
        if tmp == n:
            two.append(i)
        
        tmp = 0

        for j in range(n):
            if v[j] == q[j]:
                tmp += 1
        
        if tmp == n:
            two.append(i)

    print(abs(two[0] - two[1]))

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

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

memo = {}

ans = 0

for i in range(n):
    diff = i - a[i]
    if diff in memo:
         ans += memo[diff]
    sum = a[i] + i
    memo.setdefault(sum, 0)
    memo[sum] += 1

print(ans)

Measured memory_bytes: 40352
#include <iostream>
#include<stdio.h>
#include <vector>
#include <algorithm>
#include <queue>

#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define MAX_NUM 2e5
typedef long long int ll;
using namespace std;

int main(void) {
	ll n=0,k=0, ans=0;
	cin >> n >> k;
	vector<ll> enemy(MAX_NUM+1);

	//rep(i, n) 
	for (int i = 0; i < n; i++) {
		cin >> enemy[i];
	}
	sort(enemy.begin(), enemy.end());
	//rep(i, k)
	for (int i = 0; i < k; i++) {
		enemy.pop_back();
	}
	for (int i = 0; i < enemy.size(); i++) {
		ans += 1LL * enemy[i];
	}
	//rep(i, enemy.size()) 
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1792
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>


using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#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)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair
#define mt make_tuple

int main(void)
{
    cin.sync_with_stdio(false);
    int N;
    string S;
    cin >> N >> S;

    vector<int> west(N);
    int i = 0;
    REP(n, N){
        if (S[n] == 'W') ++i;
        west[n] = i;
    }

    vector<int> east(N);
    int j = 0;
    for(int n = N-1; n >= 0; --n) {
        if (S[n] == 'E') ++j;
        east[n] = j;
    }

    // REP(n,N) cout << west[n] << " ";
    // cout << endl;
    // REP(n,N) cout << east[n] << " ";
    // cout << endl;

    int ans = 1e9;
    REP(n, N) {
        int t = 0;
        if (n != 0) t += west[n-1];
        if (n != N-1) t += east[n+1];
        ans = min(ans, t);
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2964
#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;

#define ll long long
#define db long double
#define ii pair<int,int>
#define vi vector<int>
#define fi first
#define se second
#define sz(a) (int)(a).size()
#define all(a) (a).begin(),(a).end()
#define pb push_back
#define mp make_pair
#define FN(i, n) for (int i = 0; i < (int)(n); ++i)
#define FEN(i,n) for (int i = 1;i <= (int)(n); ++i)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repv(i,a,b) for(int i=b-1;i>=a;i--)
#define SET(A, val) memset(A, val, sizeof(A))
typedef tree<int ,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set ;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the kth largest element.(0-based)
#define TRACE
#ifdef TRACE
#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
const int N=105;
int a[N],b[N];
int main()
{
  std::ios::sync_with_stdio(false);
  cin.tie(NULL) ; cout.tie(NULL) ;
  int n,m,x,y;
  cin>>n>>m>>x>>y;
  rep(i,1,n+1) cin>>a[i]; a[++n]=x;
  rep(i,1,m+1) cin>>b[i]; b[++m]=y;
  sort(a+1,a+n+1); sort(b+1,b+m+1);
  if(b[1]>a[n]) cout<<"No War"<<endl;
  else cout<<"War"<<endl;
  return 0 ;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<deque>
#include<sstream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<bitset>
#include<cassert>
#define F first
#define S second
#define INF (1<<28)

using namespace std;
typedef pair<int,int> P;
typedef pair<string,int> SI;
int n,m,k,d;

class Pox
{
public:
  int p,cost,bit;
  int pre,pcost;
  Pox(){}
  Pox(int p,int cost,int bit):p(p),cost(cost),bit(bit){}
};

int toIndex(string s)
{
  if(s[0] == 'H')
    return 0;
  if(s[0] == 'D')
    return 1;
  if(s[0] == 'C')
    return 1+(s[1]-'0');//2,3,4,5,6,7
  if(s[0] == 'L')
    return 7+(atoi)(s.substr(1,s.length()-1).c_str());
  assert(false);
}

int main()
{
  
  while(cin >> m >> n >> k >> d,(n|m|k|d))
    {

      vector<int> calorie;
      calorie.resize(m);
      for(int i=0;i<m;i++)
	cin >> calorie[i];
      vector<vector<P> > G;
      G.resize(2+6+100+1);
      for(int i=0;i<d;i++)
	{
	  string from,to;
	  int cost;
	  cin >> from >> to >> cost;
	  int f,t;
	  f = toIndex(from);
	  t = toIndex(to);
 
	  G[f].push_back(P(t,cost));
	  G[t].push_back(P(f,cost));
	}
      
      int mincost[127][127][127];//mincost[bit][from][to]
     for(int i=0;i<127;i++)
       for(int j=0;j<127;j++)
	 for(int k=0;k<127;k++)
	   mincost[i][j][k] = INF;

     mincost[0][0][0] = 0;
     deque<Pox> deq;
     deq.push_back(Pox(0,0,0));

     deq.front().pre = 0,deq.front().pcost = 0;

     int ans = INF;
     //cout << "=== START ===" << endl;
     while(!deq.empty())
       {
	 Pox pox = deq.front(); deq.pop_front();
	 int bit = pox.bit;
	 int cost = pox.cost;
	 int p = pox.p;


	 //cout << "now = " << p << " pre = "  << pox.pre << " bit = " << bit << " cost = " << cost << " pcost = "<< pox.pcost << endl; 

	 if(p == 1)
	   ans = min(ans,cost);

	 //if(cost >= ans)
	 //continue;

	 for(int i=0;i<G[p].size();i++)
	   {      
	     P pes = G[p][i];
	     int to = pes.F;
	     int d = pes.S;	     

	     if(2 <= to && to <= 7)
	       {
		 to -= 2;
		 if((bit >> to) & 1)
		   continue;


		 //cout  << "Cake = " << mincost[bit|(1<<to)][p][to+2] <<  " >? " << cost+d*k-calorie[to] << endl;
		 if(mincost[bit|(1<<to)][p][to+2] > cost + d*k - calorie[to])
		   {
		     mincost[bit|(1<<to)][p][to+2] = cost + d*k - calorie[to];
		     deq.push_back(Pox(to+2,cost+d*k-calorie[to],bit|(1<<to)));
		  
		     deq.back().pre = p;
		     deq.back().pcost = cost;
		   }
		 continue;
	       }

	     if(mincost[bit][p][to] > cost + d*k)
	       {
		 mincost[bit][p][to] = cost + d*k;
		 deq.push_back(Pox(to,cost+d*k,bit));

		 deq.back().pre = p;
		 deq.back().pcost = cost;
	       }

	   }

       }

     cout << ans << endl;

    }
  return 0;
}

Measured memory_bytes: 10228
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>
#include <stdlib.h>
#include <stdio.h>
#include <functional>
#include <cfloat>
#include <math.h>
#include <numeric>
#include <string.h>
#include <sys/time.h>
#include <random>


#define fs first
#define sc second
#define endl "\n"

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef pair<ll, ll> P;


int main(){
    int n;  cin >> n;
    vector<ll> a(n);
    for(int i = 0; i < n; i++){
        cin >> a[i];
    }
    for(int i = 0; i < n; i++){
        if(a[i] == 0){
            cout << 0 << endl;
            return 0;
        }
    }
    ll res = a[0];
    ll ma = (ll)(1e18);
    for(int i = 1; i < n; i++){
        if(ma / res < a[i]){
            cout << -1 << endl;
            return 0;
        }
        res *= a[i];
    }
    cout << res << endl;

    return 0;
}


Measured memory_bytes: 3996
#include <iostream>
using namespace std;
int main(){
  int A,B,C,D;
  int x,y;
  cin>>A>>B>>C>>D;
  if(A<=B)x=A;
  else x=B;
  if(C<=D)y=C;
    else y=D;
  cout<<x+y;
}

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

using namespace std;

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

const int INF = 1000000000; //
const ll LINF = (ll) 4000000000000000000; //
const ll MOD = (ll) 1000000007; //
const double PI = 3.1415926535898; //
const int limit = 100010;

#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define rep2(i,n) REP(i,1,n+1)
#define rep3(i,n) REP(i,0,n+1)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define repll(i,n) REPLL(i,0,n)
#define repll2(i,n) REPLL(i,1,n+1)
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define NP(v) next_permutation(v.begin(),v.end())

//------------------------------------------------------
int n;

inline int mod(int a) {
    return (a + n) % n;
}

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

    rep(a, 2) {

        rep(b, 2) {
            bool sheep[n];
            sheep[0] = (a == 0);
            sheep[1] = (b == 0);

            REP(i, 1, n) {
                if ((s[mod(i)] == 'o') == sheep[mod(i)]) sheep[mod(i + 1)] = sheep[mod(i - 1)];
                else sheep[mod(i + 1)] = !sheep[mod(i - 1)];
            }

            bool can = true;

            rep(i, n) {
                if ((sheep[i] == (s[i] == 'o')) != (sheep[mod(i - 1)] == sheep[mod(i + 1)])) {
                    can = false;
                    break;
                }
            }

            if (can) {
                rep(i, n) cout << (sheep[i] ? 'S' : 'W');
                cout << endl;
                return 0;
            }

        }
    }

    cout << -1 << endl;

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = INT64_MAX;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;
using Vi = vector<long long int>;
typedef pair<int, int> P; typedef pair<ll, ll> PLL;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i=0;i<N;i++)
auto max(auto x,auto y){if(x>y){return x;}else{return y;}}
auto min(auto x,auto y){if(x>y){return y;}else{return x;}}
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
typedef vector<vector<ll> > matrix;
void princ(auto x){cout<<x<<" ";}; void print(auto x){cout<<x<<"\n";};
///////////////////////////////////////////////////////////////////////////////////

ll n;
vi v;
bool calc(int x){
    int tmp = 0;
    for(int i = 1;i*i <= x;i++){
        if(i*i==x)return false;
        if(x%i==0)tmp+=2;
    }
    if(tmp==8)return true;
    else return false;
}

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    cin>>n;
    rep(i,201){
        if(i%2==1 && calc(i))v.pb(i);
    }
    ll ans = 0;
    rep(i,v.size()){
        if(v[i]<=n){
            ans++;
        }else{
            break;
        }
    }
    print(ans);
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
	int A = 0;
	char B;
	for(int i = 0; i < 4; i++){
		scanf("%c", &B);
		if(B == '+'){
			A++;
		}else{
			A--;
		}
	}
	printf("%d\n", A);

	return 0;
}

Measured memory_bytes: 128
//https://atcoder.jp/contests/abc174/tasks/abc174_a
#include <stdio.h>
int main() {
    int a;
    
    printf("\n");
    scanf("%d", &a);
    
    if(a>30||a==30)
        printf("Yes");
    else
        printf("No");
    
    return 0;
}


Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define fi first
#define se second
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;

int a[1000][1000];
signed main(){
	int n, m, q;
	scanf("%lld%lld%lld", &n, &m, &q);
	rep(i,m){
		int l, r;
		scanf("%lld%lld", &l, &r);
		a[l][r]++;
	}
	rrep(i,n)rrep(j,n){
		a[i][j] += a[i][j-1];
	}
	drep(i,n,1)rrep(j,n){
		a[i][j] += a[i+1][j];
	}
	rep(i,q){
		int l, r;
		scanf("%lld%lld", &l, &r);
		printf("%lld\n", a[l][r]);
	}
	
	/*rrep(i,n){
		rrep(j,n)printf("%lld ", a[i][j]);
		printf("\n");
	}*/
	return 0;
}






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

int main(){
    int n, k;
    cin >> n >> k;
    ll ans;
    if(k%2==0){
        int memo = n / (k / 2);
        int memo1 = n / k;
        memo = memo - memo1;
        ans = pow(memo, 3) + pow(memo1, 3);
    }else{
        int memo = n / k;
        ans = pow(memo, 3);
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
    int n, k, d, a, ans = 0;
    cin >> n >> k;
    vector<bool>check(n);
    for (int i = 0; i < n; i++) {
        check.at(i) = true;
    }
    for (int i = 0; i < k; i++) {
        cin >> d;
        for (int j = 0; j < d; j++) {
            cin >> a;
            check.at(a-1) = false;
        }
    }
    for (int i = 0; i < n; i++) {
        if (check.at(i)) {
            ans++;
        }
    }
    cout << ans;
} 

Measured memory_bytes: 3632