akhauriyash/Code-Regression huggingface dataset:
def insertion_sort(a, n, g)
  cnt = 0

  g.upto(n - 1) do |i|
    v = a[i]
    j = i - g
    while j >= 0 && a[j] > v
      a[j + g] = a[j]
      j = j - g
      cnt += 1
      a[j + g] = v
    end
  end

  cnt
end

def shell_sort(a, n)
  g = [1]
  m = 1
  while (v = 3 * g[-1] + 1) <= n
    m += 1
    g << v
  end
  g.reverse!
  puts m
  puts g.map(&:to_s).join(' ')

  cnt = 0
  g.each do |gi|
    cnt += insertion_sort(a, n, gi)
  end
  puts cnt

  n.times do |i|
    puts a[i]
  end
end

n = gets.chomp.to_i
a = []
n.times do
  a << gets.chomp.to_i
end

shell_sort(a, n)


Measured memory_bytes: 14808
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)  //  repマクロ
#define leng(n) (int)(log10(n)+1)  //  桁数
using namespace std;

signed main() {
  int X;
  cin >> X;
  if (X!=3 && X!=5 && X!=7) cout << "NO" << endl;
  else cout << "YES" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;
typedef pair<ll,mp> mmp;

int main(){
    int y1,y2,m1,m2,d1,d2;
    cin>>y1>>m1>>d1>>y2>>m2>>d2;
    mmp a = mmp(y1,mp(m1,d1) );
    mmp b = mmp(y2,mp(m2,d2) );
    mmp m = min(a,b);
    mmp M = max(a,b);
    int dis = abs( y1-y2 );
    if( M.second.first > m.second.first || (M.second.first==m.second.first && M.second.second > m.second.second) ){
	cout<<dis + 1 <<endl;
    }else{
	cout<<dis<<endl;
    }

    return 0;
}



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

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


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

// 型名の省略
typedef unsigned int uint;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> P;
typedef pair<lint, lint> Plint;
 
const int MOD = 1e9+7;
const int INF = 1<<18;
const lint INFLINT = 1LL<<60;
const double PI=acos(-1.0);
 
// cinとcoutの高速化
#define endl "\n"
struct cinacc{cinacc(){cin.tie(0);ios::sync_with_stdio(false);}}cinaccc;
struct coutacc{coutacc(){cout.setf(ios::fixed);cout.precision(12);}}coutaccc;
 
// 繰り返し
#define rep(i,n) for(lint i=0;i<(lint)(n);i++)
#define reps(i,n) for(lint i=0;i<=(lint)(n);i++)
#define rrep(i,n) for(lint i=(lint)(n)-1;i>0;i--)
#define rreps(i,n) for(lint i=(lint)(n)-1;i>=0;i--)

#define pb push_back

#define ALL(s) (s.begin(), s.end())
#define SZ(s) (s.size())

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(b<a){a=b;return true;}return false;}

// Union-Find-Tree
class UnionFind {
	vector<int> par;
	UnionFind(int n):par(n){rep(i,n)par[i]=i;}
	int root(int x){if(par[x]==x)return x;return par[x]=root(par[x]);}
	void unite(int x,int y){int rx=root(x);int ry=root(y);if(rx==ry)return;par[rx]=ry;}
	bool same(int x,int y){return root(x)==root(y);}
};

// Final Weapon!
// #define int lint

int main() {
    int s, w;
    cin >> s >> w;
    if(s <= w) cout << "unsafe";
    else cout <<"safe";
    return 0;
}


Measured memory_bytes: 3640
import java.util.Scanner;

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

        int a = scan.nextInt();
        int b = scan.nextInt();
        
        
        if(a<b) {
            System.out.println("a < b");
        }
        if(a>b) {
            System.out.println("a > b");
        }    
        if(a==b) {
            System.out.println("a == b");
        }
        
    }
        
}       


Measured memory_bytes: 26276
n,k = map(int, input().split())
a = sorted(list(map(int, input().split())))
mod = 10 ** 9 + 7
fact = [1]*(n+1)
rfact = [1]*(n+1)
r = 1
for i in range(1, n+1):
  fact[i] = r = r * i % mod
rfact[n] = r = pow(fact[n], mod-2, mod)
for i in range(n, 0, -1):
  rfact[i-1] = r = r * i % mod

def comb(n, k):
  if n < k:
    return 0
  return fact[n] * rfact[k] * rfact[n-k] % mod
ans = 0
for i,v in enumerate(a):
  ans = (ans + (comb(i,k-1) - comb(n-i-1,k-1)) * v) % mod
print(ans)


Measured memory_bytes: 15056
#include<bits/stdc++.h>
using namespace std;
#define rep(i,j,n) for(int i=(int)(j);i<(int)(n);i++)
#define REP(i,j,n) for(int i=(int)(j);i<=(int)(n);i++)
#define MOD 1000000007
#define int long long
#define ALL(a) (a).begin(),(a).end()
#define vi vector<int>
#define vii vector<vi>
#define pii pair<int,int>
#define priq priority_queue<int>
#define disup(A,key) distance(A.begin(),upper_bound(ALL(A),(int)(key)))
#define dislow(A,key) distance(A.begin(),lower_bound(ALL(A),(int)(key)))
#define tii tuple<int,int,int>
#define Priq priority_queue<int,vi,greater<int>>
#define pb push_back
#define mp make_pair
#define INF (1ll<<60)
signed main(){
  int N,K; cin>>N>>K;
  vii dp(K+1,vi(K+1)),cp(K+1,vi(K+1));
  rep(i,0,N){
    int X,Y; cin>>X>>Y;
    char Z; cin>>Z;
    int sum=0;
    sum+=X/K;
    X%=K;
    sum+=Y/K;
    Y%=K;
    if((Z=='B'&&sum%2==0)||(Z=='W'&&sum%2==1)){
      dp[0][Y]++;
      dp[0][K]--;
      dp[X+1][Y]--;
      dp[X+1][K]++;
      dp[X+1][0]++;
      dp[X+1][Y]--;
      dp[K][0]--;
      dp[K][Y]++;
      cp[0][0]++;
      cp[0][Y]--;
      cp[X+1][0]--;
      cp[X+1][Y]++;
      cp[X+1][Y]++;
      cp[X+1][K]--;
      cp[K][Y]--;
      cp[K][K]++;
    }
    else{
      dp[0][0]++;
      dp[0][Y]--;
      dp[X+1][0]--;
      dp[X+1][Y]++;
      dp[X+1][Y]++;
      dp[X+1][K]--;
      dp[K][Y]--;
      dp[K][K]++;
      cp[0][Y]++;
      cp[0][K]--;
      cp[X+1][Y]--;
      cp[X+1][K]++;
      cp[X+1][0]++;
      cp[X+1][Y]--;
      cp[K][0]--;
      cp[K][Y]++;
    }
  }
  REP(i,0,K){
    REP(j,1,K) dp[i][j]+=dp[i][j-1];
  }
  REP(i,0,K){
    REP(j,1,K) dp[j][i]+=dp[j-1][i];
  }
  int ans=0;
  REP(i,0,K){
    REP(j,0,K) ans=max(ans,dp[i][j]);
  }
  REP(i,0,K){
    REP(j,1,K) cp[i][j]+=cp[i][j-1];
  }
  REP(i,0,K){
    REP(j,1,K) cp[j][i]+=cp[j-1][i];
  }
  REP(i,0,K){
    REP(j,0,K) ans=max(ans,cp[i][j]);
  }
  cout<<ans<<endl;
  }



Measured memory_bytes: 16000
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#define REP(i, N) for(int i = 0; i < N; ++i)
#define REEP(i, N) for(int i = N - 1; i >= 0; --i)
#define ALL(a) (a).begin(),(a).end()
#define FOR(i,m,n) for(int i = m; i < n; ++i)
#define RFOR(i,m,n) for(int i = n - 1; i >= m; --i)
#define CIN(a) cin >> a
#define CIN2(a, b) cin >> a >> b
#define CIN3(a, b, c) cin >> a >> b >> c
#define COUT(a) cout << a << endl
#define COUT2(a, b) cout << a << " " << b << endl
#define COUT3(a, b, c) cout << a << " " << b << " " << c << endl
#define pb push_back
#define PB push_back
#define VINT(v, n) vector<int> v(n); REP(i, n) { v[i] = 0 }
#define VINT2(v, n, m) vector<vector<int> > v(n, vector<int>(m)); REP(i, n) { REP(j, m) { v[i][j] = 0 } }
#define VCHAR(v, n) vector<char>v(n)
#define KIRIAGE(a, b) a += (b - a % b) % b
#define CEIL(c, a, b) if(a % b == 0) { c = a / b;} else { c = a / b + 1;}
#define sp(n) setprecision(n)
#define INF 1000000000
#define MOD 1000000007

using namespace std;
typedef pair<int, int> P;
typedef long long ll;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
	int N, K;
	CIN2(N, K);
	ll ans = K;
	REP(i, N - 1) {
		ans *= K - 1;
	}
	COUT(ans);
}


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <iostream>
#include <numeric>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>

#include <atcoder/mincostflow>

using namespace std;
using namespace atcoder;
#define rep(i,l,r) for(int i = l; i < r; ++i)

#define fir first
#define sec second

int main() {
    int n, m;
    int MAX = 5000;
    cin >> n >> m;

    vector<string> s(n, string());
    rep(i, 0, n) cin >> s[i];

    int t = n * m, u = t + 1;
    mcf_graph<int, int> mcf(u + 1);

    rep(i, 0, n) {
        rep(j, 0, m) {
            int x = i * m + j;
            if (s[i][j] == '#') continue;
            if (s[i][j] == 'o') mcf.add_edge(t, x, 1, MAX);
            mcf.add_edge(x, u, 1, MAX - i - j);

            if (i + 1 < n && s[i+1][j] != '#') mcf.add_edge(x, x + m, 100, 0);
            if (j + 1 < m && s[i][j+1] != '#') mcf.add_edge(x, x + 1, 100, 0);
        }
    }

    mcf.slope(t, u, 100).back();

    auto edge = mcf.edges();
    int ans = 0;
    for(auto e : edge) {
        if(e.from == t || e.to == u || e.flow == 0) continue;
        ans += e.flow;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4208
n, k = map(int, input().split())
s = list(map(int, list(input())))

i = 0
a = []
while i < n:
    l = 1
    while i+1 < n and s[i]==s[i+1]:
        l+=1
        i+=1
    a.append(l)
    i+=1

if s[0] == 0:
    a = [0] + a
if s[-1] == 0:
    a = a + [0]
n = len(a)

acum = [0]*(n+1)
for i in range(n):
    acum[i+1] = acum[i]+a[i]

ans = 0
for i in range(0, n, 2):
    end = min(i+2*k+1, n)
    ans = max(ans, acum[end] - acum[i])
print(ans)

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

int main() {
  
  int N; cin >> N; vector<tuple<string, int, int>> vec(N);
  
  for (int i = 0; i < N; i++) {

    string S; int P; cin >> S >> P; P *= -1;

    vec.at(i) = make_tuple(S, P, i + 1);

  }

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

  for (int i = 0; i < N; i++) {
    cout << get<2>(vec.at(i)) << endl;
  }
  
}

Measured memory_bytes: 256
#include <iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
int main(){
    int a,i,max=0;
    vector<int> count(100,0);
    while(cin>>a){
        count[a]++;
    }
    for(i=1;i<count.size();i++){
        if(max<count[i])max=count[i];
    }
    for(i=1;i<count.size();i++){
        if(max==count[i])cout<<i<<endl;
    }
          return 0;
}

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

namespace ABC170C
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split(' ');
            int X = int.Parse(input[0]);
            int N = int.Parse(input[1]);
            if (N == 0)
            {
                Console.WriteLine(X);
            }
            else
            {
                int[] p = new int[N];
                string[] pinput = Console.ReadLine().Split(' ');
                for(int i = 0; i < N; i++)
                {
                    p[i] = int.Parse(pinput[i]);
                }
                int[] hantei = new int[100];
                for(int i = 0; i < N; i++)
                {
                    hantei[p[i] - 1] = -1;
                }
                int sa = 200;
                int temp = 0;
                int ans = 0;

                temp = Math.Abs(X);
                if (temp < sa)
                {
                    sa = temp;
                    ans = 0;
                }
                for (int i = 1; i < 101; i++)
                {
                    if (hantei[i - 1] == 0)
                    {
                        temp = Math.Abs(X - i);
                        if (temp < sa)
                        {
                            sa = temp;
                            ans = i;
                        }
                    }
                }
                temp = Math.Abs(X -101);
                if (temp < sa)
                {
                    sa = temp;
                    ans = 101;
                }
                Console.WriteLine(ans);
            }
        }
    }
}


Measured memory_bytes: 27480
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007
const ll INF=1e18;
template<class T>void show(vector<T>v){for (int i = 0; i < v.size(); i++){cerr<<v[i]<<" ";}cerr<<endl;}
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; }



int main(int argc, char const *argv[]) {
  int n;
  cin >> n;
  vector<ll> a(n);
  ll suml = 0, sumr = 0;
  rep(i, n) {
    cin >> a[i];
    sumr += a[i];
  }
  ll ans = INF;
  rep(i, n) { 
    suml += a[i];
    sumr -= a[i];
    chmin(ans, abs(sumr - suml));
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3632
#include <cstdint>
#include <iostream>
#include <vector>

using namespace std;

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

    vector<vector<int64_t>> ways(average * n + 1, vector<int64_t>(n + 1, 0));

    for (auto i = 0; i < n; i += 1) {
        int num;
        cin >> num;

        vector<vector<int64_t>> new_ways(average * n + 1, vector<int64_t>(n + 1, 0));
        if (num <= average * n) {
            new_ways[num][1] = 1;
        }

        for (auto s = 0; s < (int)ways.size(); s += 1) {
            for (auto k = 1; k < (int)ways[s].size(); k += 1) {
                new_ways[s][k] += ways[s][k];
                if (num <= s) {
                    new_ways[s][k] += ways[s - num][k - 1];
                }
            }
        }
        ways = new_ways;
    }

    int64_t res = 0;
    for (auto k = 1; k <= n; k += 1) {
        res += ways[k * average][k];
    }

    cout << res << "\n";
    return 0;
}


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

class Program
{
    static string InputPattern = "InputX";

    static List<string> GetInputList()
    {
        var WillReturn = new List<string>();

        if (InputPattern == "Input1") {
            WillReturn.Add("100");
            //18
        }
        else if (InputPattern == "Input2") {
            WillReturn.Add("9995");
            //35
        }
        else if (InputPattern == "Input3") {
            WillReturn.Add("3141592653589793");
            //137
        }
        else {
            string wkStr;
            while ((wkStr = Console.ReadLine()) != null) WillReturn.Add(wkStr);
        }
        return WillReturn;
    }

    static void Main()
    {
        List<string> InputList = GetInputList();
        string N = InputList[0];

        var NumList = new List<int>();
        for (int I = 1; I <= N.Length - 1; I++) {
            NumList.Add(N[I] - '0');
        }

        int LastNum = N[0] - '0';
        if (NumList.TrueForAll(X => X == 9)) {
            Console.WriteLine(9 * NumList.Count + LastNum);
        }
        else {
            Console.WriteLine(9 * NumList.Count + LastNum - 1);
        }
    }
}


Measured memory_bytes: 11092
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
using namespace std;
typedef long long ll;
ll MOD = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)
int main() {
    vector<vector<int>> a(3, vector<int>(3));
    rep(i, 3) rep(j, 3) cin >> a[i][j];
    int n;
    cin >> n;
    vector<vector<bool>> flg(3, vector<bool>(3));
    rep(i, n) {
        int tmp_b;
        cin >> tmp_b;
        rep(j, 3) rep(k, 3) {
            if ( a[j][k] == tmp_b ) {
                flg[j][k] = true;
            }
        }
    }
    rep(i, 3) if ( flg[i][0] && flg[i][1] && flg[i][2] ) {
        cout << "Yes" << endl;
        return 0;
    }
    rep(i, 3) if ( flg[0][i] && flg[1][i] && flg[2][i] ) {
        cout << "Yes" << endl;
        return 0;
    } 
    if ( flg[0][0] && flg[1][1] && flg[2][2] ) {
        cout << "Yes" << endl;
        return 0;
    }
    if ( flg[0][2] && flg[1][1] && flg[2][0] ) {
        cout << "Yes" << endl;
        return 0;
    } 
    cout << "No" << endl;
    return 0;
}


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

using namespace std;

typedef long long ll;

bool prime(int x) {
    if (x == 2) {
        return true;
    }
    if (x % 2 == 0) {
        return false;
    }
    for (int i = 3; i * i <= x; i += 2) {
        if (x % i == 0) {
            return false;
        }
    }
    return true;
}

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


Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    ( source = $ s : expr , $ ( $ r : tt ) * ) => { let mut iter = $ s . split_whitespace ( ) ; let mut next = || { iter . next ( ) . unwrap ( ) } ; input_inner ! { next , $ ( $ r ) * } };
    ( $ ( $ r : tt ) * ) => { let stdin = std :: io :: stdin ( ) ; let mut bytes = std :: io :: Read :: bytes ( std :: io :: BufReader :: new ( stdin . lock ( ) ) ) ; let mut next = move || -> String { bytes . by_ref ( ) . map ( | r | r . unwrap ( ) as char ) . skip_while ( | c | c . is_whitespace ( ) ) . take_while ( | c |! c . is_whitespace ( ) ) . collect ( ) } ; input_inner ! { next , $ ( $ r ) * } };
}
#[allow(unused_macros)]
macro_rules! input_inner {
    ( $ next : expr ) => { };
    ( $ next : expr , ) => { };
    ( $ next : expr , $ var : ident : $ t : tt $ ( $ r : tt ) * ) => { let $ var = read_value ! ( $ next , $ t ) ; input_inner ! { $ next $ ( $ r ) * } };
}
#[allow(unused_macros)]
macro_rules! read_value {
    ( $ next : expr , ( $ ( $ t : tt ) ,* ) ) => { ( $ ( read_value ! ( $ next , $ t ) ) ,* ) };
    ( $ next : expr , [ $ t : tt ; $ len : expr ] ) => { ( 0 ..$ len ) . map ( | _ | read_value ! ( $ next , $ t ) ) . collect ::< Vec < _ >> ( ) };
    ( $ next : expr , chars ) => { read_value ! ( $ next , String ) . chars ( ) . collect ::< Vec < char >> ( ) };
    ( $ next : expr , usize1 ) => { read_value ! ( $ next , usize ) - 1 };
    ( $ next : expr , $ t : ty ) => { $ next ( ) . parse ::<$ t > ( ) . expect ( "Parse error" ) };
}

fn main() {
    input!{
        n: usize, k: usize,
        a: [usize; n]
    }

    let mut dp = vec![false;k+1];
    for i in 0..k+1 {
        let mut win = false;
        for j in 0..n {
            if i >= a[j] {
                if !dp[i - a[j]] {
                    win = true;
                }
            }
        }
        dp[i] = win;
    }
    println!("{}", if dp[k] {"First"} else {"Second"});
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
#define D10 fixed<<setprecision(10)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/

int main()
{
	int n; cin >> n;
	while (n--)
	{
		vi v;
		int t;
		while (cin >> t, t) v.push_back(t);
		int m = 0;
		REP(i, v.size()) if (v[i] > 0) m++;
		vi dist(m), rem(m);
		vector<vi> ans(m);
		stack<int> st;
		st.push(0);
		int r = 0;
		dist[0] = 0;
		rem[0] = v[0];
		FOR(i, 1, v.size())
		{
			while (rem[st.top()] == 0) st.pop();
			int tmp = st.top();
			if (v[i] > 0)
			{
				r++;
				rem[tmp]--;
				rem[r] = v[i]-1;
				ans[tmp].push_back(r);
				ans[r].push_back(tmp);
				dist[r] = dist[tmp] + 1;
				st.push(r);
			}
			else
			{
				REP(j, m)
				{
					if (dist[j] - dist[tmp] == v[i] && rem[j] > 0)
					{
						rem[tmp]--;
						rem[j]--;
						ans[tmp].push_back(j);
						ans[j].push_back(tmp);
						break;
					}
				}
			}
		}
		REP(i, m)
		{
			cout << i + 1 << " ";
			sort(ALL(ans[i]));
			REP(j, ans[i].size())
			{
				cout << ans[i][j] + 1 << (j == ans[i].size() - 1 ? "\n" : " ");
			}
		}
	}
	return 0;
}

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

using namespace std;

typedef long long LL;

LL fact(int n) {
    LL res = 1;
    for (int i = 1; i <= n; i++) {
        res *= i;
        res %= 1000000000 + 7;
    }
    return res;
}

int main() {
    int n, m;
    cin >> n >> m;
    if (n < m) {
        swap(n, m);
    }

    if (n - m > 1) {
        cout << 0 << endl;
        return 0;
    }

    LL res;

    if (n - m == 0) {
        res = fact(n);
        res *= res * 2;
    } else {
        res = fact(n) * fact(m);
    }

    cout << res % (1000000000 + 7) << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int,int>;

int h, w, d, q;
vector<int> l;
vector<int> r;


int main() {
	// Input
	cin >> h >> w >> d;

	vector<vector<int> > a(h, vector<int>(w, 0));

	for (int i = 0; i < h; ++i)
	{
		for (int j = 0; j < w; ++j)
		{
			cin >> a.at(i).at(j);
		}
	}

	cin >> q;

	l.resize(q);
	r.resize(q);

	for (int i = 0; i < q; ++i) {
		cin >> l.at(i) >> r.at(i);
	}

	// Initialize s
	vector<pint> s(h*w+1);

	for (int i = 0; i < h; ++i)
	{
		for (int j = 0; j < w; ++j)
		{
			s.at(a.at(i).at(j)) = pair<int, int>(i, j);
		}
	}

	// Prepare
	vector<int> mp(h*w+1);
	for (int st = 1; st <= d; ++st)
	{
		mp.at(st) = 0;
		for (int i = st+d; i <= h*w; i = i+d)
		{
			mp.at(i) = mp.at(i-d) + abs(s.at(i).first-s.at(i-d).first) + abs(s.at(i).second-s.at(i-d).second);
		}
	}

	// Solve
	for (int i = 0; i < q; ++i)
	{
		cout << mp.at(r.at(i)) - mp.at(l.at(i)) << endl;
	}
}

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

using namespace std;
typedef long long ll;
//typedef unsigned long long ll;

#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
//#define sz(x) ll(x.size())
//typedef pair<ll, int> P;
//typedef pair<ll, ll> P;
//const double INF = 1e10;
//const ll INF = LONG_LONG_MAX / 10;
//const ll INF = 1e15;
const ll MINF = LONG_LONG_MIN;
const int INF = INT_MAX / 10;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
typedef pair<int, int> P;

bool contain(set<P> &s, P a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);


void print_line(vector<int> &line) {
    if (line.size() == 0ll) {
        cout << endl;
        return;
    }
    for (ll i = 0; i < line.size(); i++) {
        cout << line[i];
        if (i == line.size() - 1) cout << endl;
        else cout << ' ';
    }
}


typedef priority_queue<long long, vector<long long>, greater<long long>> PQ_ASK;
const int mod = 1000000007;

int main() {

    ll n;
    cin >> n;

    ll ans = 0;
    ans += n / 25;
    n %= 25;
    ans += n / 10;
    n %= 10;
    ans += n / 5;
    n %= 5;
    ans += n;

    cout << ans << endl;

}


Measured memory_bytes: 3116
#include <cstdio>
#include <queue>
#include <algorithm>

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

using namespace std;

const int inf = 2e7;

typedef pair<int, int> P;

struct E{
	E(int t, int c) :
		t(t), c(c)
	{}

	int t, c;
};

int c, n, m, s, t;
vector<E> g[1100];
int d[1100];

int index(int i, int j){
	return i * (c + 1) + j;
}

int main(){
	while(1){
		scanf("%d%d%d%d%d", &c, &n, &m, &s, &t);
		--s;
		--t;
		if(c == 0){
			break;
		}
		rep(i, m){
			int a, b, k;
			scanf("%d%d%d", &a, &b, &k);
			--a;
			--b;
			rep(j, c + 1){
				g[index(a, j)].push_back(E(index(b, j), k));
				g[index(b, j)].push_back(E(index(a, j), k));
			}
			rep(j, c){
				g[index(a, j + 1)].push_back(E(index(b, j), k / 2));
				g[index(b, j + 1)].push_back(E(index(a, j), k / 2));
			}
		}

		fill_n(d, n * (c + 1), inf);

		priority_queue<P, vector<P>, greater<P> > q;
		d[index(s, c)] = 0;
		q.push(P(0, index(s, c)));
		while(!q.empty()){
			P v = q.top();
			q.pop();
			if(v.first > d[v.second]){
				continue;
			}
			rep(i, g[v.second].size()){
				E e = g[v.second][i];
				if(d[e.t] > v.first + e.c){
					d[e.t] = v.first + e.c;
					q.push(P(d[e.t], e.t));
				}
			}
		}

		printf("%d\n", *min_element(d + index(t, 0), d + index(t + 1, 0)));

		rep(i, n * (c + 1)){
			g[i].clear();
		}
	}
	return 0;
}

Measured memory_bytes: 1324
import java.util.*;

public class Main {
  public static long MOD = (long)Math.pow(10, 9) + 7;
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long n = sc.nextLong();
    long k = sc.nextLong();
    long[] a = new long[(int)n];
    for(int i = 0; i < n; i++) {
      a[i] = sc.nextLong();
    }
    Arrays.sort(a);
    long ans = 0;
    long[] kai = new long[(int)n];
    kai[0] = 1;
    for(long i = 1; i < n; i++) {
      kai[(int)i] = (i * kai[(int)i - 1]) % MOD;
    }
    for(int i = 0; i < n; i++) {
      long ma = 0;
      long mi = 0;
      if(i >= (int)(k - 1)) {
        long t = kai[i];
        long t1 = func(kai[(int)(k - 1)], MOD - 2);
        long t2 = func(kai[(int)(i - k + 1)], MOD - 2);
        t = (t * t1) % MOD;
        t = (t * t2) % MOD;
        ma = t;
      }
      if(i <= (int)(n - k)) {
        long t = kai[(int)(n - 1 - i)];
        long t1 = func(kai[(int)(k - 1)], MOD - 2);
        long t2 = func(kai[(int)(n - i - k)], MOD - 2);
        t = (t * t1) % MOD;
        t = (t * t2) % MOD;
        mi = t;         
      }
      ans = (ans + ((ma * a[i]) % MOD)) % MOD;
      ans = (ans + MOD - ((mi * a[i]) % MOD)) % MOD;
    }
    System.out.println(ans);
  }

  public static long func(long a, long x) {
    if(x == 0) return 1;
    if((x % 2) == 0) {
      long t = func(a, x / 2);
      return (t * t) % MOD;
    } else {
      long t = func(a, x / 2);
      t = (t * t) % MOD;
      return (a * t) % MOD;
    }
  }
}

Measured memory_bytes: 60336
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define bFor(i,a,b) for(i=a;i>=(ll)b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

double distance(ddatas& x,ddatas& y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

ll modpow(ll a,ll n){
  ll res=1;
  while(n){
    if(n&1)res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

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

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}

void judgement(bool a){
  if(a){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
}
vec diviserlist(ll N){
  ll i;
  vec res;
  for(i=1;i*i<N;i++){
    if(N%i==0){
      res.pb(i);res.pb(N/i);
    }
  }
  if(i*i==N)res.pb(i);
  vsort(res);
  return res;
}
const double PI = acos(-1);
const double eps = 1e-9;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll i,N,K,ma=0,cnt=0,ng=0,mid;
  cin>>N>>K;
  vec v(N),b(N);
  rep(i,N){
    cin>>v[i];
    cnt+=v[i];
  }
  if(cnt<=K){
    cout<<0<<endl;
    return 0;
  }
  vsort(v);
  rep(i,N)cin>>b[i];
  vrsort(b);
  rep(i,N){
    chmax(ma,v[i]*b[i]);
  }
  if(K==0LL){
    cout<<ma<<endl;
    return 0;
  }
  while(ma-ng>1){
    mid=(ma+ng)/2;
    cnt=0;
    rep(i,N){
      cnt+=max(v[i]-mid/b[i],0LL);
    }
    if(cnt<=K){
      ma=mid;
    }else{
      ng=mid;
    }
  }
  cout<<ma<<endl;
  return 0;
}

Measured memory_bytes: 3328
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;

public class Prog
{
    private const int INF = 1000000007;
    private const long INFINITY = 9223372036854775807;
    private struct Pair { public int x, y; }
    public static void Main()
    {
        //input
        int H = NextInt();
        int W = NextInt();
        int D = NextInt();
        Pair[] pos = new Pair[H * W + 1];
        for (int i = 0; i < H; i++)
        {
            for (int j = 0; j < W; j++)
            {
                int n = NextInt();
                pos[n].x = j;
                pos[n].y = i;
            }
        }

        int M = H * W;
        int[] dp = new int[M + 1];
        dp[0] = 0;
        for (int i = D + 1; i <= M; i++)
        {
            dp[i] = dp[i - D] + Math.Abs(pos[i].x - pos[i - D].x) + Math.Abs(pos[i].y - pos[i - D].y);
        }

        int Q = NextInt();

        for (int i = 0; i < Q; i++)
        {
            int L = NextInt();
            int R = NextInt();
            Console.WriteLine(dp[R] - dp[L]);
        }
    }
}

public class Input
{
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static char NextChar() { Confirm(); return char.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}


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


int main(){
    string S; cin >> S;
    set<char> st;
    vector<char> v(26);
    rep(i,26){
        st.insert('a'+i);
        v[i] = 'a'+i;
    }
    rep(i,S.size()){
        st.erase(S[i]);
    }

    if(S == "zyxwvutsrqponmlkjihgfedcba"){
        cout << -1 << endl;
        return 0;
    }

    if(S.size() < 26){

        cout << S + *st.begin() << endl;
        return 0;

    }else{

        char cur = S[25], tar;
        int p;

        for(int i=1;i<26;i++){
            tar = S[25-i];

            if(cur > tar){
                p = 26-i;
                char ch = '{';
                for(int j=p;j<26;j++){
                    if(S[j] > S[p-1])ch = min(ch, S[j]);
                }
                S[p-1] = ch;
                rep(j,p){
                    cout << S[j];
                }
                cout << endl;
                return 0;
            }
            cur = tar;
        }
    }
}

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

typedef vector<int> vi;
typedef pair<int, int> pii;
#define endl "\n"
#define sd(val) scanf("%d", &val)
#define ss(val) scanf("%s", &val)
#define sl(val) scanf("%lld", &val)
#define debug(val) printf("check%d\n", val)
#define all(v) v.begin(), v.end()
#define PB push_back
#define MP make_pair
#define FF first
#define SS second
#define ll long long
#define MOD 1000000007
#define clr(val) memset(val, 0, sizeof(val))
#define what_is(x) cerr << #x << " is " << x << endl;
#define OJ                            \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout);
#define FIO                           \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
int n, m, k;
char ara[7][7];
char bara[7][7];

void copy()
{
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            bara[i][j] = ara[i][j];
        }
    }
}

void color(int x, int y)
{
    for (int i = 0; i < n; i++)
    {
        if (x & (1 << i))
        {
            for (int j = 0; j < m; j++)
            {
                bara[i][j] = '$';
            }
        }
    }

    for (int j = 0; j < m; j++)
    {
        if (y & (1 << j))
        {
            for (int i = 0; i < n; i++)
            {
                bara[i][j] = '$';
            }
        }
    }
}

bool check()
{
    int t = 0;

    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            if (bara[i][j] == '#')
                t++;
        }
    }

    if (t == k)
    {
        return true;
    }

    return false;
}

int main()
{

    cin >> n >> m >> k;
    int ans = 0;

    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < m; j++)
        {
            cin >> ara[i][j];
        }
    }

    for (int i = 0; i < (1 << n); i++)
    {
        for (int j = 0; j < (1 << m); j++)
        {
            copy();
            color(i, j);

            if (check())
                ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
long long a[200005];
int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    long long h,n;
    int k;
    cin>>n>>k;
    long long s=0;
    long long ans=0;

    for(int i=0 ; i<n ; i++){
        cin>>a[i];
    }
    sort(a,a+n);
    for(int i=0 ; i<n-k ; i++)
        ans+=a[i];
    cout<<ans;
    return 0;
}


Measured memory_bytes: 1792
import java.util.*;
import java.lang.*;
import java.io.*;
 
/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	public static void main (String[] args) 
	{
	    Scanner s=new Scanner(System.in);
	    int n=s.nextInt();
	    int[]arr=new int[n];
	    for(int i=0;i<n;i++){
	        arr[i]=s.nextInt();
	    }
	    int dp[]=new int[n+1];
	    dp[0]=0;
	    dp[1]=0;
	    dp[2]=Math.abs(arr[1]-arr[0]);
	    for(int i=2;i<n;i++){
	        int op1=Math.abs(arr[i]-arr[i-2]);
	        int op2=Math.abs(arr[i]-arr[i-1]);
	        dp[i+1]=Math.min(dp[i]+op2,dp[i-1]+op1);
	    }
	    System.out.println(dp[n]);
	    
	}
}

Measured memory_bytes: 59564
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <string>
#include <queue>
#include <numeric>
#include <ctype.h>
#include <limits>
#include <iomanip>

#define rep(i,n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()
using namespace std;

typedef long long ll;

int main()
{
	int n, m;
	cin >> n >> m;
	if (n == m)puts("Yes");
	else puts("No");

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){

  char input[9];

  while(scanf("%s",input)!=EOF){

    //6???????????§??????????????????????±??????????
    if((input[0]=='o' && input[1]=='o' && input[2]=='o') ||
       (input[3]=='o' && input[4]=='o' && input[5]=='o')){
        printf("o\n");
    }

    else if((input[0]=='x' && input[1]=='x' && input[2]=='x') ||
       (input[3]=='x' && input[4]=='x' && input[5]=='x')){
        printf("x\n");
    }

    //7???????????§??????????????????????±??????????
    //o?????????????????¨??????????????´???????????????
    else if((input[0]=='o' && input[3]=='o' && input[6]=='o') ||
       (input[2]=='o' && input[4]=='o' && input[6]=='o')){
        printf("o\n");
    }

    //x?????????????????¨??????????????´???????????????
    else if((input[0]=='x' && input[3]=='x' && input[6]=='x') ||
       (input[2]=='x' && input[4]=='x' && input[6]=='x')){
        printf("x\n");
    }

    //8???????????§??????????????????????±??????????
    //o???????????????????????´???????????????
    else if(input[1]=='o' && input[4]=='o' && input[7]=='o'){
      printf("o\n");
    }

    //x???????????????????????´???????????????
    else if(input[1]=='x' && input[4]=='x' && input[7]=='x'){
      printf("x\n");
    }

    //9???????????§??????????????????????±??????????
    else if((input[0]=='o' && input[4]=='o' && input[8]=='o') ||
       (input[6]=='o' && input[7]=='o' && input[8]=='o') ||
       (input[2]=='o' && input[5]=='o' && input[8]=='o')){
        printf("o\n");
    }

    else if((input[0]=='x' && input[4]=='x' && input[8]=='x') ||
       (input[6]=='x' && input[7]=='x' && input[8]=='x') ||
       (input[2]=='x' && input[5]=='x' && input[8]=='x')){
        printf("x\n");
    }

    else
      printf("d\n");

}

  return 0;

}

Measured memory_bytes: 524
#include <bits/stdc++.h>
using namespace std;
int a[10][10],m,n,flag;
char kk[10];
void dfs(int x,int y){
	if(x==m-1&&y==n-1){
		for(int i=0;i<m;++i)for(int j=0;j<n;++j)if(a[i][j])return;
		flag = 1;    
        return;
    }
	if(flag==1)return;
    if(a[x+1][y]){
        a[x+1][y]=0;
        dfs(x+1,y);
        a[x+1][y]=1;
    }
    if(a[x][y+1]){
        a[x][y+1]=0;
        dfs(x,y+1);
        a[x][y+1]=1;
    }
    if(!a[x][y+1]&&!a[x+1][y])return;
}
int main(){
    scanf("%d%d",&m,&n);
    for(int i=1;i<=m;++i){
        cin>>kk; 
        for(int j=0;j<n;++j)if(kk[j]=='#')a[i-1][j]=1;
    }
    if(a[0][0]){
        a[0][0] = 0;
        dfs(0,0);
    }
    if(flag)cout<<"Possible"<<endl;
    else cout<<"Impossible"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define REP(i,b) FOR(i,0,b)
#define INF 1e9

using ll = long long;
const ll mod = LLONG_MAX;

int main(){
  int ia=0,ib=0,ic=0;
  char a,b,c,x='a';
  string Sa,Sb,Sc;
  cin>>Sa>>Sb>>Sc;

while(1){

  if (x=='a'){
    x = Sa[ia];
    ia++;
    if (ia+1>=Sa.size()){
      cout<<'A'<<endl;
      return 0;
    }
  }

/*  if (ia+1>Sa.size()){
    cout<<'A'<<endl;
    return 0;
  }*/

  if (x=='b'){
    x = Sb[ib];
    ib++;
    if (ib+1>=Sb.size()){
        cout<<'B'<<endl;
        return 0;
      }
  }

/*  if (ib+1>Sb.size()){
    cout<<'B'<<endl;
    return 0;
  }*/

  if (x=='c'){
    x = Sc[ic];
    ic++;
    if (ic+1>=Sc.size()){
        cout<<'C'<<endl;
        return 0;
      }
  }

/*  if (ic+1>Sc.size()){
    cout<<'C'<<endl;
    return 0;
  }*/

  }
}


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

int main() {
  string n;
    cin >> n;
    if(n[0]==n[1]&&n[1]==n[2]) {
      cout << "Yes" <<endl;}
  else if(n[1]==n[2]&&n[2]==n[3]) {cout << "Yes" <<endl;}
  else {cout << "No" <<endl;}
}



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

int main(){
    int n,x;
    cin >> n >>x;
    int m[100];
    int count=0;
    for(int i=0;i<n;i++){
        cin >>m[i];
        count+=m[i];
    }
    sort(m,m+n);
    cout << n+(x-count)/m[0] << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<math.h>
#include<string>

using namespace std;

int main(){
  int a, b, c;

  cin >> a >> b >> c;

  if((a < c && c < b) || (a > c && c > b))cout << "Yes" << endl;
  else cout << "No" << endl;
}


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

count = 0

while True:
  exist_Odd = False
  for i in range(n):
      if a[i]%2 != 0:
        exist_Odd = True
      a[i] = a[i]/2
  
  if exist_Odd == True: 
    break      
    
  count += 1
  
print(count)


Measured memory_bytes: 2940
#include <iostream>
	#include <cstdio>
	#include <cstdlib>
	#include <time.h>
	#include <math.h>
	#include <vector>
	#include <queue>
	#include <map>
	#include <set>
	#include <algorithm>
	#include <iterator>
	#include <sstream>
	#include <string>
	#include <bitset>
	using namespace std;
	#define FOR(I,F,N) for(int I = F; I < (int)(N); I++)
	#define rep(i, n) FOR(i, 0, n)
	#define FIN(V) cout<<V<<endl
	#define pb push_back
	#define INF (1 << 30)
	typedef pair<int, int> P;
	typedef long long ll;
	typedef priority_queue<int> pq;
	int StrToInt(string);
	string IntToStr(int);
	int dx[4] = {1, -1, 0, 0};
	int dy[4] = {0, 0, 1, -1};
	
	int main(void){
		int month[] = {31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
		int n, m;
		while(cin >> n >> m, n || m){
			int day = 0;
			rep(i, n-1)day += month[i];
			day += m;
			int yo = day % 7;
			if(yo == 1){
				FIN("Thursday");
			}else if(yo == 2){
				FIN("Friday");
			}else if(yo == 3){
				FIN("Saturday");
			}else if(yo == 4){
				FIN("Sunday");
			}else if(yo == 5){
				FIN("Monday");
			}else if(yo == 6){
				FIN("Tuesday");
			}else if(yo == 0){
				FIN("Wednesday");
			}
		}


		return 0;
	}
	
	
	
	int StrToInt(string s){
		stringstream ss;
		ss << s;
		int val;
		ss >> val;
		return val;
	}
	string IntToStr(int i){
		stringstream ss;
		ss << i;
		return ss.str();
	}
		

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
#define N 100010
#define ll long long
int main()
{
	int a,b;
  	cin>>a>>b;
  	if(2*b > a){
    	printf("0");
    }
 	else{
    	printf("%d",a-2*b);
    }
    return 0;
}


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

using namespace std;

int main()
{
    int arr[3][3],n;
    for(int  i=0;i<3;i++)
    {
        for(int j=0;j<3;j++)
        {
            cin>>arr[i][j];
        }
    }
    cin>>n;
    for(int k=0;k<n;k++)
    {
        int temp;
        cin>>temp;
        int cnt=0;
        for(int  i=0;i<3;i++)
        {
            for(int j=0;j<3;j++)
            {
                if(arr[i][j]==temp)
                {
                    arr[i][j]=-1;
                }
            }
        }   
    }
    if(arr[0][0]==-1 && arr[0][0]==arr[0][1] && arr[0][1]==arr[0][2])
    {
        cout<<"Yes"<<endl;
    }
    else if(arr[1][0]==-1 && arr[1][0]==arr[1][1] && arr[1][1]==arr[1][2])
    {
        cout<<"Yes"<<endl;
    }
    else if(arr[2][0]==-1 && arr[2][0]==arr[2][1] && arr[2][1]==arr[2][2])
    {
        cout<<"Yes"<<endl;
    }
    else if(arr[0][0]==-1 && arr[0][0]==arr[1][0] && arr[1][0]==arr[2][0])
    {
        cout<<"Yes"<<endl;
    }
    else if(arr[0][1]==-1 && arr[0][1]==arr[1][1] && arr[1][1]==arr[2][1])
    {
        cout<<"Yes"<<endl;
    }
    else if(arr[0][2]==-1 && arr[0][2]==arr[1][2] && arr[1][2]==arr[2][2])
    {
        cout<<"Yes"<<endl;
    }
    else if(arr[0][0]==-1 && arr[1][1]==-1 && arr[2][2]==-1)
    {
        cout<<"Yes"<<endl;
    }
    else if(arr[0][2]==-1 && arr[1][1]==-1 && arr[2][0]==-1)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
n = int(input())
aaa = list(map(int, input().split()))

MOD = 10 ** 9 + 7
ans = 0
m = 1
ans = 0
for _ in range(60):
    one_count = sum(a & m for a in aaa)
    one_count //= m
    zero_count = n - one_count
    ans = (ans + one_count * zero_count * m) % MOD
    m *= 2
        
print(ans)


Measured memory_bytes: 42284
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define MAXN 100000+10
using namespace std;
int a[MAXN];
int main (void)
{
	int n;
	int m,k;
	cin>>n>>m>>k;
	double minn = 1e9;
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		double c = m-a[i]*0.006;
		minn=min(fabs(c-k),minn);
		//cout<<minn<<endl;
	}
	for(int i=1;i<=n;i++)
	{
		double c = m-a[i]*0.006;
		if(fabs(c-k)==minn)
		{
			cout<<i<<endl;
			return 0;
		}
	}
	return 0;
}


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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))
#define sz(v) ((int) v.size())

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << endl; exit(0); }
inline void no() { cout << "No" << endl; exit(0); }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { x = max(x, y); }
template <typename T> inline void amin(T &x, T y) { x = min(x, y); }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  int r;
  cin >> r;
  cout << ((f80) r * 2 * M_PI) << endl;
}

Measured memory_bytes: 3788
// AOJ 0563: Walking Santa
// 2017.10.25 bal4u@uu

#include <stdio.h>
#include <stdlib.h>

char buf[65], *p;
int getInt(void)
{
	int n;
	if (*p == ' ') p++;
	n = 0; while (*p >= '0') n = (n<<3) + (n<<1) + (*p++ & 0xf);
	return n;
}

int cmp(int *a, int *b) { return *a - *b; }

typedef struct { int x, y; } PP;
PP pp[100002];
int x[100002], y[100002];

long long calc(int x0, int y0, int n)
{
	int i;
	long long sum, ans, dx, dy, max;
	PP *p;

	sum = 0, max = 0, ans = 1LL << 60;
	for (p = pp, i = n; i--; p++) {
		dx = x0 - p->x, dy = y0 - p->y;
		if (dx < 0) dx = -dx;
		if (dy < 0) dy = -dy;
		dx += dy;
		sum += dx << 1;
		if (dx > max) max = dx;
	}
	if (sum - max < ans) ans = sum - max;
	return ans;
}

int main()
{
	int w, h, n, i, xpos, ypos, m;
	long long ans, a;

	fgets(p=buf, 64, stdin), w = getInt(), h = getInt();
	fgets(p=buf, 64, stdin), n = getInt();
	for (i = 0; i < n; i++) {
		fgets(p=buf, 64, stdin);
		pp[i].x = x[i] = getInt(), pp[i].y = y[i] = getInt();
	}
	qsort(x, n, sizeof(int), cmp), qsort(y, n, sizeof(int), cmp);

	m = (n-1)/2, xpos = x[m], ypos = y[m];
	ans = calc(xpos, ypos, n);
	if (!(n & 1)) {
		if (x[m] == x[m+1] && y[m] == y[m+1]);
		else if (x[m] == x[m+1]) {
			a = calc(xpos, y[m+1], n);
			if (a < ans) ans = a, ypos = y[m+1];
		} else if (y[m] == y[m+1]) {
			a = calc(x[m+1], ypos, n);
			if (a < ans) ans = a, xpos = x[m+1];
		} else {
			a = calc(x[m], y[m+1], n);
			if (a < ans) ans = a, xpos = x[m], ypos = y[m+1];
			a = calc(x[m+1], y[m], n);
			if (a < ans) ans = a, xpos = x[m+1], ypos = y[m];
			a = calc(x[m+1], y[m+1], n);
			if (a < ans) ans = a, xpos = x[m+1], ypos = y[m+1];
		}
	}
	printf("%lld\n%d %d\n", ans, xpos, ypos);
	return 0;
}

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

void rotate_array(string &S)
{
    char last_char = S[S.size() - 1];
    S.pop_back();
    S.insert(S.begin(), last_char);
}

int main(void)
{
    string S, T;
    cin >> S >> T;

    vector<string> S_copy(S.size());

    bool success = false;
    for (int i = 0; i < S.size(); i++)
    {
        rotate_array(S);
        // cout << S << endl;
        if (S == T)
        {
            success = true;
            break;
        }
    }

    if (success == true)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return (0);
}

Measured memory_bytes: 256