akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
ll p = 1000000007;
ll black[100005],white[100005];
bool visited[100005];
vector<ll> adj[100005];
void solve(ll v){
    black[v] = white[v] = 1;
    visited[v] = true;
    for(ll i = 0;i < adj[v].size();i++){
        if(!visited[adj[v][i]]){
            solve(adj[v][i]);
            black[v] = (black[v]*white[adj[v][i]])%p;
            white[v] = (white[v]*(black[adj[v][i]]+white[adj[v][i]])%p)%p;
        } 
    }
}
int main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin >> n;
    for(ll i = 0;i < n-1;i++){
        ll x,y;
        cin >> x >> y;
        adj[x-1].push_back(y-1);
        adj[y-1].push_back(x-1);
    }
    memset(visited,false,n*sizeof(bool));
    solve(0);
    cout << (white[0]+black[0])%p << endl;
}

Measured memory_bytes: 11520
#include <bits/stdc++.h>
#define INF 100000000000
#define ll long long
#define pll pair<ll, ll>
using namespace std;

int main()
{
  ll N;
  cin >> N;
  vector<ll> A(N);
  for (ll i = 0; i < N; ++i) {
    ll a;
    cin >> a;
    A.at(i) = a - i - 1;
  }
  sort(A.begin(), A.end());
  ll mid = A.at(N / 2);
  ll ans = 0;
  for (ll i = 0; i < N; ++i) {
    ans += abs(A.at(i) - mid);
  }
  cout << ans << endl;

}


Measured memory_bytes: 1792
#include<iostream>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<cctype>
#define szxb 22
using namespace std;
int n,m,a[szxb]={0,31,28,31,30,31,30,31,31,30,31,30,31};
signed main()
{
	scanf("%d%d",&n,&m);
	puts(((!(a[n]-a[m]))?("Yes"):("No")));
	return 0;
}

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

int main(){
  int n;
  cin>>n;
  vector<LL> v(n);
  int cnt=0, minN=1000000001, idx=0;
  for(int i=0;i<n;i++){
    scanf("%lld",&v[i]);
    if(v[i]<0) cnt++;
    if(minN>abs(v[i])){
      minN = abs(v[i]);
      idx=i;
    }
  }
  if(cnt%2!=0){
    for(int i=0;i<n-1;i++){
      if(v[i]<=0){
        v[i]*=-1;
        v[i+1]*=-1;
      }
    }
    if(v[idx]>0) v[idx]*=-1;
    if(n-1!=idx&&v[n-1]<0) v[n-1]*=-1;
  }else{
    for(int i=0;i<n;i++){
      if(v[i]<0){
        v[i]*=-1;
      }
    }
  }
  LL ans=accumulate(v.begin(),v.end(),0LL);
  cout<<ans<<endl;
}

Measured memory_bytes: 1024
n, m = map(int, input().split())
S = list(map(int, input().split()))
T = list(map(int, input().split()))
mod = 10**9 + 7

DP = [[0] * n for _ in range(m)]

t0 = T[0]
count = 0
for i in range(n):
    if S[i] == t0:
        count += 1
    DP[0][i] = count

s0 = S[0]
count = 0
for j in range(m):
    if T[j] == s0:
        count += 1
    DP[j][0] = count

for j in range(1, m):
    for i in range(1, n):
        total = DP[j-1][i] + DP[j][i-1] - DP[j-1][i-1]
        if T[j] == S[i]:
            total += DP[j-1][i-1] + 1
        total %= mod
        DP[j][i] = total

ans = DP[m-1][n-1] + 1
print(ans)


Measured memory_bytes: 72796
//ROADTOBLUE
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <stack>
#include <iomanip>
#include <queue>
#include <set>
#include <unordered_set>
#include <bitset>
#include <cstring>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace std;
using namespace __gnu_pbds;


#define ull unsigned ll
// #define endl '\n'
#define mp make_pair
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define speedhack() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define DO(x) for(int i = 1; i <= x; i++){ solve(i); }
#define form(i, n) for (size_t i = 0; i < size_t(n); ++i)
#define forn(i, n) for (size_t i = 1; i <= size_t(n); ++i)
#define M_PI 3.14159265358979323846
template<class T> using ordered_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
long long mod(long long a, long long b) { return (a%b+b)%b; }
long long gcd(long long x, long long y) { return __gcd(x, y); }
long long lcm(long long x, long long y) { return x * 1ll * y / gcd(x, y); }


const long long MAXN = 1e9;
const int SIZE = 2e5 + 5;  //are u sure ?
const int MOD = 1e9 + 7;


void solve(int CASE) {
	int x, y; cin >> x >> y;
	for(int i = 0; i <= x; i++) {
		int a = i;
		int b = x - a;
		int total = a * 2 + b * 4;
		if(total == y) {
			cout << "Yes";
			return;
		}
	}	cout << "No";
}


int main(){
	speedhack()
	// int IT; cin >> IT;
	int IT = 1;
	DO(IT);
	return 0;
}

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

typedef long long LL;

#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9+7;

int main() {
    int N;
    cin >> N;
    vector<LL> v(N);
    int M = 0;
    REP(i, N) {
        cin >> v[i];
        if(v[i] <= 0) {
            M++;
        }
    }
    sort(ALL(v));
    if(M%2 == 0) {
        REP(i, M) {
            v[i] *= -1;
        }
        cout << accumulate(ALL(v), 0L) << endl;
    }else{
        if(M == N) {
            REP(i, N - 1) {
                v[i] *= -1;
            }
            cout << accumulate(ALL(v), 0L) << endl;
        }else{
            REP(i, M - 1) {
                v[i] *= -1;
            }
            if(v[M - 1] < -v[M]) {
                v[M - 1] *= -1;
                v[M] *= -1;
            }
            cout << accumulate(ALL(v), 0L) << endl;
        }
    }
    return 0;
}



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

using namespace std;

int main() {
	long long N, K;
	cin >> N >> K;

	vector<long long> H;
	for (int i = 0; i < N; i++) {
		long long h;
		cin >> h;
		H.push_back(h);
	}

	sort(H.begin(), H.end());
	reverse(H.begin(), H.end());

	long long total_kougeki = 0;
	for (int i = 0; i < H.size(); i++) {
		if (K != 0) {
			K = K - 1;
		}
		else {
			total_kougeki = total_kougeki + H[i];
		}
	}

	cout << total_kougeki << endl;

}


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

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

typedef long long int ll;

const ll INF=(ll)1e18;

int N,M;
int ans;

vector<vector<int>> edge(8);
bool visited[8];

bool check(){
  int cnt = 0;
  REP(i,N){
    if(visited[i]==true)cnt++;
  }
  return cnt == N;
}

void dfs(int p, int n){
  if(visited[n])return;
//  fprintf(stderr, "%d %d %d\n",p,n,depth);
  visited[n] = true;
  if(check()){
    ans++;
    visited[n] = false;
    return;
  }
  REP(i,edge[n].size()){
    if(edge[n][i] == p)continue;
    dfs(n, edge[n][i]);
  }
  visited[n] = false;
}


int main(){
  cin >> N >> M;
  REP(i,M){
    int a,b;
    cin >> a >> b;
    a--;b--;
    edge[a].push_back(b);
    edge[b].push_back(a);
  }

  // REP(i,N){
  //   cout << i  << ": ";
  //   REP(j,edge[i].size()){
  //     cout << edge[i][j] << " ";
  //   }
  //   cout << endl;
  // }

  REP(i,N)visited[i]=false;
  visited[0]=true;
  ans = 0;
  REP(i,edge[0].size()){
    dfs(0, edge[0][i]);
  }
  cout << ans << endl;

}



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

// io
#define get(i) scanf("%d", &i)
#define flush fflush(stdin)

// manipulations
#define f(i, n) for (int i = 0; i < n; i++)
#define fr(i, n) for (int i = n - 1; i >= 0; i--)
#define ff(i, a, b) for (int i = a; i <= b; i++)
#define lowbit(x) (x & -x)
#define sz(x) int((x).size())

// built-in
#define bitcount __builtin_popcount
#define gcd __gcd

// short
#define pb push_back
#define fill(arr, a) memset(arr, a, sizeof(arr))

// useful bits
#define IN(i, l, r) (l <= i && i <= r)
#define relax(a, b) (a) = max((a), (b))
#define relaxi(a, b) (a) = min((a), (b))

typedef vector<int> VI;
typedef pair<int, int> PII;
typedef long long ll;
typedef long double ld;

ll modpow(ll a, ll b, ll mod = (ll) (1e9 + 7)) 
{if (!b) return 1; a %= mod; return modpow(a * a % mod, b / 2, mod) * (b & 1 ? a : 1) % mod;}

// for rand
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
// use uniform_int_distribution<int>(0, i)(rng)


int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int a, b;
	cin >> a >> b;
	int ans = max(a+b, max(a+(a-1), b+(b-1)));
	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std;
int main(){
  long long int n,ans; 
  int lala;  
  cin>>n;  
  for(int i=sqrt(n);i>=1;i--){
    if(n%i==0){
      ans=n/i;
      break;
    }
  }  
  while(ans>=1){ 
    lala++;
    ans/=10;
  }
  cout<<lala<<endl;
  return 0;
} 

Measured memory_bytes: 256
#include <stdio.h>

int main (){
 int i;
 int n;

  scanf("%d" , &n);
  int a[n];
  for ( i = 0; i < n; i++){
    scanf("%d",&a[i]);
  }
  
  for (i = 0; i < n ; i++){
    if(i) {
      printf(" ");
    }
    printf("%d", a[n-i-1]);
  }
  printf("\n");
  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define rep(I,n) for (int I = 0; I < (n); ++I)
#define FOR(I,k,n) for(int I=(k);I<(n);++I)
using namespace std;
typedef long long ll;
 
int main() {
    
    int r;
    cin >>r;
    
    cout << r*r<<endl;
    
  
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int n;
    cin>>n;
    long long int mi=100000000000000;
    for(int i=1;i<=sqrt(n);i++)
    {
        if(n%i==0)
        {
            long long int d;
            d=i+n/i-2;
            mi=min(mi,d);
        }

    }
    cout<<mi<<endl;
   return 0;
}

Measured memory_bytes: 3644
import itertools

n, k, s = map(int, input().split())
ans = [0] * n

if s == 1000000000:
    for i in range(n):
        if i < k:
            ans[i] = s
        else:
            ans[i] = 1
else:
    for i in range(n):
        if i < k:
            ans[i] = s
        else:
            ans[i] = s+1

for i in ans:
    print(i, end=" ")
print()



Measured memory_bytes: 8032
import java.util.Scanner;


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

		int pricetotal = 0, numtotal = 0, count = 0;
		String[] strings;

		while(sc.hasNext()){
			count++;
			strings = sc.next().split(",");

			pricetotal += Integer.parseInt(strings[0]) * Integer.parseInt(strings[1]);
			numtotal += Integer.parseInt(strings[1]);
		}

		System.out.println(pricetotal);
		System.out.printf("%.0f\n", (double)numtotal / (double)count);
	}
}

Measured memory_bytes: 12000
#abc072 c
n=int(input())
a=list(map(int,input().split()))
num=dict()

for i in a:
    x=i+1
    y=i-1
    if i not in num:
        num[i]=1
    else:
        num[i]+=1
    if x not in num:
        num[x]=1
    else:
        num[x]+=1
    if y not in num:
        num[y]=1
    else:
        num[y]+=1

ans=0
for i in num.values():
    ans=max(ans,i)
print(ans)


Measured memory_bytes: 18800
#include <algorithm>
#include <stdio.h>
#include <math.h>
using namespace std;

const int NMAX = 100010;

int dp[NMAX];
int h[NMAX];

int main()
{
    int n;
    scanf("%d", &n);
    fill(dp, dp + n + 1, 2e9);

    for (int i = 1; i <= n; i++)
        scanf("%d", h + i);

    dp[1] = 0;

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

    printf("%d\n", dp[n]);

    return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <queue>
#include <stack>
#include <bitset>
#include <set>
#include <map>
#include <chrono>
#include <string>
#include <assert.h>

using namespace std;

#define endl '\n'

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

    int n; cin >> n;

    vector<int> a(n);
    map<int,int> freq;

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

    long long answer = 0;

    for (auto f : freq) {
        answer += 1LL * f.second * (f.second - 1) / 2;
    }

    for (int i = 0; i < n; ++i) {
        cout << answer - freq[a[i]] + 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 8320
name1, a1, b1 = map(str,input().split())
name2, a2, b2 = map(str,input().split())
name3, a3, b3 = map(str,input().split())
name4, a4, b4 = map(str,input().split())
name5, a5, b5 = map(str,input().split())
name6, a6, b6 = map(str,input().split())
name7, a7, b7 = map(str,input().split())
name8, a8, b8 = map(str,input().split())
name9, a9, b9 = map(str,input().split())
def f(x,y,z):
    a = int(y)
    b = int(z)
    print(x,int(a+b),int(a*200+(b*300)))
f(name1,a1,b1)
f(name2,a2,b2)
f(name3,a3,b3)
f(name4,a4,b4)
f(name5,a5,b5)
f(name6,a6,b6)
f(name7,a7,b7)
f(name8,a8,b8)
f(name9,a9,b9)


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

#define PI acos(-1)
#define pb push_back
#define lli long long int
#define mp make_pair
#define pi pair<int, int>
#define pii pair<pi, int>
#define fir first
#define sec second
#define MAXN 100001
#define MAXL 20
#define mod 1000000007

int n, m, k, ans;

void solve(int i, vector<vector<char>> grid)
{
  if (i == max(n, m))
  {
    int aa = 0;
    for (int x = 0; x < n; x++)
      for (int y = 0; y < m; y++)
        if (grid[x][y] == '#')
          aa++;
    if (aa == k)
      ans++;
    return;
  }
  solve(i + 1, grid);
  if (i < m)
  {
    char b[n];
    for (int x = 0; x < n; x++)
      b[x] = grid[x][i], grid[x][i] = '3';
    solve(i + 1, grid);
    for (int x = 0; x < n; x++)
      grid[x][i] = b[x];
  }
  if (i < n)
  {
    for (int x = 0; x < m; x++)
      grid[i][x] = '3';
    solve(i + 1, grid);
  }
  if (i < n && i < m)
  {
    for (int x = 0; x < m; x++)
      grid[i][x] = '3';
    for (int x = 0; x < n; x++)
      grid[x][i] = '3';
    solve(i + 1, grid);
  }
}
signed main()
{
  cin >> n >> m >> k;
  vector<vector<char>> grid(n);
  for (int i = 0; i < n; i++)
    grid[i].resize(m);
  for (int i = 0; i < n; i++)
    for (int j = 0; j < m; j++)
      cin >> grid[i][j];
  solve(0, grid);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <set>
#include <map>
#include <string.h>
#include <cmath>
#include <functional>

using namespace std;
typedef long long i64;
typedef long double ld;
typedef pair<i64,i64> P;

int n;

vector<vector<int>> dp;
vector<int> w;


int rec(int l,int r){
	if(dp[l][r] != -1) return dp[l][r];

	if(abs(l - r) <= 1) return 0;

	int res = 0;
	//l [able] r ?
	if(abs(w[l] - w[r - 1]) <= 1 && rec(l + 1,r - 1) == r - l - 2)
	{
		res = r - l;
	}

	//[l any] [any r]
	for(int mid = l + 1;mid <= r - 1;mid++)
	{
		res = max(res , rec(l,mid) + rec(mid,r));
	}
	return dp[l][r] = res;
};
int main()
{
	while(cin >> n , n)
	{
		w.assign(n,0);
		for(int i = 0;i < n;i++) cin >> w[i];

		dp.assign(n + 1,vector<int>(n + 1,-1));


		//[l,r)

		cout << rec(0,n) << endl;
	}
}
				


			




Measured memory_bytes: 3184
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string>
#include <numeric>
#include <cstring>
#include <cmath>
#include <set>
#include <queue>
#include <stack>

const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
using ll = long long int;
using P = pair<string, int>;
using edge = struct
{
    int to;
    int cost;
};

int wfs(string worm)
{
    queue<P> que;
    que.push(P(worm, 0));

    map<string, int> mp;

    while (!que.empty())
    {
        P p = que.front();
        que.pop();

        string tmp = p.first;

        if(mp[p.first]) continue;

        bool flag = true;

        for (int i = 0; i < tmp.size() - 1; i++)
        {
            if (tmp[i] != tmp[i + 1])
            {
                flag = false;
                break;
            }
        }

        if (flag) return p.second;

        mp[p.first] = p.second;

        for(int i = 0; i < tmp.size() - 1; i++)
        {
            if(tmp[i] == tmp[i + 1]) continue;

            string nworm = tmp;

            if(tmp[i] != 'g' && tmp[i + 1] != 'g')
            {
                nworm[i] = 'g';
                nworm[i + 1] = 'g';
            }
            else if(tmp[i] != 'b' && tmp[i + 1] != 'b')
            {
                nworm[i] = 'b';
                nworm[i + 1] = 'b';
            }
            else
            {
                nworm[i] = 'r';
                nworm[i + 1] = 'r';
            }

            que.push(P(nworm, p.second + 1));

        }        
    }
    return -1;
}

int main()
{
    string input;

    while(cin >> input && input != "0")
    {
        cout << (wfs(input) != - 1 ? to_string(wfs(input)) : "NA") << endl;
    }

    return 0;
}


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

using namespace std;

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  // freopen("input.txt", "r", stdin);
  // freopen("output.txt", "w", stdout);

  int n,k;cin>>n>>k;
  int arr[n];
  for(int i = 0; i<n; i++){
    cin>>arr[i];
  }
  // int dp[n];
  int INF = 1e9 + 5;
  // memset(dp, INF, sizeof(int)*n);
  vector<int> dp(n,INF);
  dp[0] = 0;
  for(int i=0; i<n; i++){
    for(int j=1; j<=k;j++){
      if(i+j<n)
        dp[i+j] = min(dp[i+j], dp[i] + abs(arr[i+j]-arr[i]));
    }
  }
  cout<<dp[n-1];
  return 0;
}


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

int main(){
	int a, b; cin >> a >> b;
	if(a <= 5)
		cout << 0 << endl;
	else if(6 <= a && a <= 12)
		cout << b / 2 << endl;
	else
		cout << b << endl;
}

Measured memory_bytes: 256
import numpy as np
from collections import Counter as cc
N = int(input())
A = list(map(int,input().split()))

ans = 0
A_p = cc(A+np.arange(N))
A_n = cc(np.arange(N) - A)
for k in range(1,N+1):
    ans += A_p[k]*A_n[k]
print(ans)

Measured memory_bytes: 79880
#include<bits/stdc++.h>
using namespace std;
using ll=long long int;
ll mod=1e9+7;
int main()
{
    ll n;
    cin>>n;
    vector<ll>  a(n);
    vector<ll> b(n);
    for(ll i=0;i<n;i++)
    {
        ll x,y;
        cin>>x>>y;
        a[i]=x+y;
        b[i]=x-y;
    }
    sort(begin(a),end(a));
    sort(begin(b),end(b));
    cout<<max(abs(a[n-1]-a[0]),abs(b[n-1]-b[0]))<<endl;
}

Measured memory_bytes: 6420
values = []
while True:
    value = input().split()
    if int(value[0]) == 0 and int(value[1]) == 0:
        break
    else:
        values.append(value)

for value in values:
    m = int(value[0])
    n = int(value[1])
    for i in range(m):
        row_output = ""
        for j in range(n):
            if i == 0 or i == m -1:
                row_output += "#"
            else:
                if j == 0 or j == n - 1:
                    row_output += "#"
                else:
                    row_output += "."
        print(row_output)
    print()



Measured memory_bytes: 5620
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
   int n;
   cin>>n;
   int count=0;
   for(int i=1;i<=9;i++)
   {
       for(int j=1;j<=9;j++)
       {
           int z=j*i;
           if(z==n)
            count++;
       }
   }
   if(count>0)
    cout<<"Yes"<<endl;
   else
    cout<<"No"<<endl;


    return 0;
}


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

long gcd(long a, long b) {
  long v0 = a, v1 = b, v2 = a % b;
  while (v2 != 0) {
    v0 = v1;
    v1 = v2;
    v2 = v0 % v1;
  };
  return v1;
}

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

int main() {
  int N;
  cin >> N;
  long a=1;
  for(int i=0;i<N;i++){
    long b;
    cin >> b;
    a=lcm(a,b);
  }
  cout << a;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int INF = 1 << 28;

int w, h;
vector<pair<int, int> > b[7];
vector<pair<int, int> > v[6];

int dist(pair<int, int> p1, pair<int, int> p2)
{
	return abs(p1.first - p2.first) + abs(p1.second - p2.second);
}

int dp[6][1000];

void solve()
{
	v[0] = b[0];
	v[5] = b[6];
	
	pair<int, int> res(INF, INF);
	
	for (int fi = 1; fi <= 5; fi++){
		for (int i = 1; i <= 4; i++){
			int x = (fi + i - 1) % 5 + 1;
			v[i] = b[x];
		}
		
		fill((int*)dp, (int*)dp + 6000, INF);
		dp[0][0] = 0;
		
		for (int i = 0; i < 6; i++){
			for (int j = 0; j < v[i].size(); j++){
				for (int k = 0; k < v[i + 1].size(); k++){
					dp[i + 1][k] = min(dp[i + 1][k], dp[i][j] + dist(v[i][j], v[i + 1][k]));
				}
			}
		}
		
		res = min(res, make_pair(dp[5][0], fi));
	}
	
	if (res.first == INF) puts("NA");
	else printf("%d %d\n", res.second, res.first);
}

int main()
{
	char c;
	while (scanf("%d %d", &w, &h), w){
		for (int i = 0; i < 7; i++){
			b[i].clear();
		}
		for (int i = 0; i < h; i++){
			for (int j = 0; j < w; j++){
				pair<int, int> p(i, j);
				scanf(" %c", &c);
				switch (c){
					case 'S':
					b[0].push_back(p);
					break;
					
					case 'G':
					b[6].push_back(p);
					break;
					
					case '.':
					break;
					
					default:
					b[c - '0'].push_back(p);
				}
			}
		}
		solve();
	}
}

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

int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if(a+b < c+d){
     cout << "Right" << endl;
  }
  else if(a+b > c+d){
     cout << "Left" << endl;
  }
  else{
   cout << "Balanced" << endl;
  }
 return 0; 
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define rep2(i, l, r) for (int i = (l); i < (r); i++)
#define rep2r(i, l, r) for (int i = (r) - 1; i >= (l); i--)
#define range(a) a.begin(), a.end()

using namespace std;
using ll = long long;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  const double pi = acos(-1);
  double a, b, x; cin >> a >> b >> x;
  double f = (a * a * b - x) * 2 / (a * a * a);
  double g = a * b * b / x / 2;
  double ans1 = atan(f);
  double ans2 = atan(g);
  if (b * cos(ans1) > a * sin(ans1)) {
    cout << ans1 / pi * 180 << endl;
  } else {
    cout << ans2 / pi * 180 << endl;
  }
}

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

int main() {
	int a;
  cin >> a;
  a = a % 10;
  if(a == 2 || a == 4 || a == 5 || a == 7 || a == 9){
    cout << "hon" << endl;
  }
  if(a == 0 || a == 1 || a == 6 || a == 8){
    cout << "pon" << endl;
  }
  if(a == 3){
    cout << "bon" << endl;
  }
	return 0;
}


Measured memory_bytes: 3528
N,K = gets.split.map(&:to_i)
l = gets.split.map(&:to_i)

def swap(a,i,j)
 tmp = a[i]
 a[i] = a[j]
 a[j] = tmp
 return a
end

def bubble(a,k)
 for i in 0..(k-2)
  if a[i] > a[i+1]
   swap(a,i,i+1)
  end
 end
 return a
end

def bubble_sort(a)
 k = a.length
 while k > 1
  bubble(a,k)
  k = k-1
 end
 return a
end

bubble_sort(l)

sum = 0
for i in (N-K)..(N-1)
    sum = sum + l[i]
end

puts(sum)

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

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

int main() {
    int n, k, x, y;
    cin >> n;
    cin >> k;
    cin >> x;
    cin >> y;
    int ans = 0;
    if (n > k) {
        ans = x * k + (n - k) * y;
    } else {
        ans = x * n;
    }
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

//typedef pair<int,int> P;



int main(){
	long long N,M;
	scanf("%lld %lld", &N, &M);

	long long ans = 0;

	if(N==1 || M==1){
		if(N==1&&M==1){
			ans = 1;
		}else{
			if(N==1) ans = M-2;
			else ans = N-2;
		}
	}else{
		ans = (N-2)*(M-2);
	}

	printf("%lld\n", ans);

	return 0;
}


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

int main(){
    int n;
	vector<long long> a;
  
    cin >> n;
  	for (int i = 0; i < n; i++){
      	long long buf;
     	cin >> buf;
      	a.push_back(buf);
    }
  	int before, after;
  	before = a.size();
    sort(a.begin(), a.end());
    a.erase(unique(a.begin(), a.end()), a.end());
    after = a.size();
    if (before == after) {
      	cout << "YES" << endl;
    } else {
      	cout << "NO" << endl;
    }

}





Measured memory_bytes: 2420
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string[] sS = System.Console.ReadLine().Trim().Split(' ');
            int iN = int.Parse(sS[0]);
            List<ClsPos> lstPos = new List<ClsPos>();
            for (int i = 0; i < iN; i++)
            {
                sS = System.Console.ReadLine().Trim().Split(' ');
                ClsPos oneUsr = new ClsPos();
                oneUsr.iX = decimal.Parse(sS[0]);
                oneUsr.iY = decimal.Parse(sS[1]);
                lstPos.Add(oneUsr);
            }

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            List<decimal> lstDef = new List<decimal>();
            for (int i = 0; i < lstPos.Count; i++)
            {
                for (int j = i + 1; j < lstPos.Count; j++)
                {
                    lstDef.Add((decimal)Math.Sqrt(Math.Pow((double)(lstPos[i].iX - lstPos[j].iX), 2) + Math.Pow((double)(lstPos[i].iY - lstPos[j].iY), 2)));
                }
            }
            decimal dAve = lstDef.Average();
            decimal dOut = dAve * (decimal)(iN - 1);

            // 出力
            System.Console.WriteLine("{0}", dOut.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

        // カウンター情報
        private class ClsPos
        {
            public decimal iX { get; set; } = 0M;
            public decimal iY { get; set; } = 0M;
        }

}


Measured memory_bytes: 13396
//#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"

using namespace std;

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//{akari : 1D, yukari : 2D, maki : 3D} vector
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
//{akane : ascending order, aoi : decending order} priority queue
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;

//------------------------------- Libraries ---------------------------------//

//------------------------------- Dubug Functions ---------------------------//

inline void print()
{
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest)
{
    cout << first << ' ';
    print(rest...);
}

//------------------------------- Solver ------------------------------------//

void solve()
{
    int k;
    cin >> k;

    auto calc = [](i64 x) -> int {
        seika s = to_string(x);
        yukari<int> dp(2, akari<int>(10));
        bool first = 1;
        for (char c : s)
        {
            int d = c - '0';
            yukari<int> new_dp(2, akari<int>(10));
            for (int f = 0; f < 2; f++)
                for (int i = 0; i <= (f ? 9 : d); i++)
                {
                    if (i == 0)
                    {
                        new_dp[f || (d != i)][0] += dp[f][0];
                        new_dp[f || (d != i)][0] += dp[f][1];
                    }
                    else if (i == 9)
                    {
                        new_dp[f || (d != i)][9] += dp[f][8];
                        new_dp[f || (d != i)][9] += dp[f][9];
                    }
                    else
                    {
                        for (int j = -1; j < 2; j++)
                        {
                            new_dp[f || (d != i)][i] += dp[f][i + j];
                        }
                    }
                }
            for (int i = 1; i <= (first ? d : 9); i++)
            {
                new_dp[!(first && i == d)][i]++;
            }
            swap(dp, new_dp);
            first = 0;
        }
        int res = 0;
        for (int f = 0; f < 2; f++)
            for (int i = 0; i < 10; i++)
            {
                res += dp[f][i];
            }
        return res;
    };
    i64 ok = 0, ng = 1e12;
    while (ok + 1 < ng)
    {
        i64 m = (ok + ng) / 2;
        (calc(m) < k ? ok : ng) = m;
    }
    cout << ok + 1 << endl;
}

int main()
{
    solve();
    return 0;
}


Measured memory_bytes: 256
A, B, C = map(int, input().split())
K = int(input())

ans = "No"

def ABC(int1, int2, int3):
    if int1 < int2 < int3:
        return True
    else:
        return False

if ABC(A, B, C):
    ans = "Yes"
else:
    for k in range(K):
        if B <= A:
            B = B * 2
        elif C <= B:
            C = C * 2
        
        if ABC(A, B, C):
            ans = "Yes"
            break

print(ans)

Measured memory_bytes: 9196
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.StringTokenizer;

public class Main {

    void solve() throws IOException {
        int n = ni();
        int c = ni();
        int k = ni();
        int[] t = nia(n);

        Arrays.sort(t);

        int prev = -1;
        int cnt = 0;
        int ans = 0;
        for (int i = 0; i < n; i++) {
            if (prev != -1 && t[i] - prev > k) {
                ans++;
                prev = -1;
                cnt = 0;
            }

            if (prev == -1) {
                prev = t[i];
            }
            cnt++;


            if (cnt == c) {
                ans++;
                prev = -1;
                cnt = 0;
            }
        }
        if (cnt > 0) ans++;

        out.println(ans);
    }

    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }

    int ni() throws IOException {
        return Integer.parseInt(ns());
    }

    long nl() throws IOException {
        return Long.parseLong(ns());
    }

    double nd() throws IOException {
        return Double.parseDouble(ns());
    }

    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }

    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }

    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

Measured memory_bytes: 34584
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<cstdlib>
#include<tuple>
#include<iomanip>
#include<stack>
#include<map>
#include<queue>
#include<set>
#define int long long
using namespace std;
const int INF = 1e10;
const int ZERO = 0;

signed main() {
	int N;
	cin >> N;
	vector<int> vec(N);
	for(int i = 0;i < N;i++) {
		cin >> vec.at(i);
	}
	int cnt = 0;
	int ret = 0;
	for(int i = 0;i < N - 1;i++) {
		if(vec.at(i) >= vec.at(i + 1)) {
			cnt++;
		}
		else {
			ret = max(ret,cnt);
			cnt = 0;
		}
	}
  	ret = max(ret,cnt);
	cout << ret << endl;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
#define ll long long
#define INF (1<<30)
using namespace std;
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1237
ll t;
string num;
ll ans;
vector<ll> ans_arr;

void dfs(ll n, ll sum,vector<ll> p) {
	if (n == num.length()) {
		p.push_back(sum);
		ll Sum = 0;
		for (int i = 0; i < p.size();i++) {
			//cout << p[i] << " ";
			Sum += p[i];
		}
		//cout << endl;
		if (Sum > t) return;

		//cout << Sum << endl;

		if (Sum > ans) {
			ans = Sum;
			ans_arr = p;
		}
		else if (Sum == ans) {
			ans_arr.clear();
			ans_arr.push_back(INF);
		}
		return;
	}

	int x = num[n] - '0';

	auto temp = p;
	if(n != 0)temp.push_back(sum);
	dfs(n + 1, x, temp);
	if(n != 0)dfs(n + 1, sum * 10 + x, p);
}

int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	while (cin >> t >> num) {
		if (t == 0 && num == "0")break;
		ans = -1;
		ans_arr.clear();
		vector<ll> p;
		dfs(0,0, p);

		if (ans == -1) {
			cout << "error" << endl;
			continue;
		}

		if (ans_arr[0] == INF) {
			cout << "rejected" << endl;
			continue;
		}

		cout << ans;
		for (int i = 0; i < ans_arr.size();i++) {
			cout << " " << ans_arr[i];
		}
		cout << endl;
	}
}

Measured memory_bytes: 2972
#include <stdio.h>
#define MAXL 200000

int main(void){
    char s[MAXL+1];
    scanf("%s", s);

    int lefta = -1, rightz = -1;
    for(int i = 0; s[i] != '\0'; i++){
        if(!(s[i] == 'A' || s[i] == 'Z')) continue;
        if(lefta < 0){
            if(s[i] == 'A'){
                lefta = i;
            }
        }else{
            if(s[i] == 'Z'){
                rightz = i;
            }
        }
    }

    printf("%d\n", rightz - lefta + 1);
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  string YABAI, WAYO;
  int a, b;
  cin >> a >> WAYO;
  
  size_t d = WAYO.length();
  
  if(d > a){
    YABAI = WAYO.substr(0, a);
    cout << YABAI << "..." << endl;
  }
  else{
    cout << WAYO << endl;
  }
  
  //cout << d << endl;
  
}

Measured memory_bytes: 3628
// by adiforluls
#pragma GCC optimize ("-O2")
#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 FAST            ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ll              long long
#define ld              long double
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define all(a)          (a).begin(),(a).end()
#define clz(a)          __builtin_clz(a) // count leading zeroes
#define ctz(a)          __builtin_ctz(a) // count trailing zeroes
#define popc(a)         __builtin_popcount(a) // count set bits (for ints only diff for ll)
#define rep(i,a,b)      for(int i=a;i<b;i++)
#define rfor(i,a,b)     for(int i=a; i>=b; i--)
#define debug(x)        cerr << #x << " = " << x << endl;
#define F               first
#define S               second
#define endl            '\n'
#define SIZE            1000005
#define deci(n)         cout<<fixed<<setprecision(n)
#define ordered_set     tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key(k)
// find_by_order(k)
const ld PI = acos(-1.0);
const int INF = 0x3f3f3f3f;
const ll lul2 = 998244353;
const ll lul = 1000000007;

void mod(ll &x)
{
    if(x>=lul) x-=lul;
    if(x<0) x+=lul;
}

ll _gcd(ll a, ll b)
{
    if(b == 0) return a;
    return _gcd(b,a%b);
}

ll expo(ll n, ll p)
{
    if(p == 0) return 1;
    ll x = expo((n*n)%lul, p/2)%lul;
    if(p&1) return (x*n)%lul;
    return x;
}
//---------------------------------------------------------------------
vector<ll> bits(64,0);
ll ans = 0;
void solve()
{
    ll n,k; cin>>n>>k;
    rep(i,0,n)
    {
        ll val; cin>>val;
        while(val)
        {
            int lb = log2(val&(-val));
            bits[lb]++;
            val-=(val&(-val));
        }
    }
    rfor(i,63,0)
    {
        ll add = 1LL<<i;
        ll fact = bits[i];
        if(k-add<0)
        {
            ans+=fact*add;
            continue;
        }
        if(n-bits[i]>bits[i]) k-=add, fact = n-bits[i];
        ans+=fact*add;
    }
    cout<<ans;
}
int main()
{   
    FAST;
   //  #ifndef ONLINE_JUDGE
     // freopen("input.txt", "r", stdin);
     // freopen("output.txt", "w", stdout);
   //  #endif
    int t; t=1;
    rep(i,1,t+1){
        solve();
    }
    return 0;
}

Measured memory_bytes: 256
//-------------
//include
//-------------
#include <map>
#include <list>
#include <cmath>
#include <vector>
#include <string>
#include <cctype>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
//-------------
//typedef
//-------------
typedef  long long LL;
typedef  vector<int> VI;
typedef  vector<double> VD;
typedef  string STR;
typedef  pair<int, int> PII;
typedef  vector<int, int> VII;
typedef  map<string, int> MSI;
//-------------
//utillty
//-------------
#define ALL(a)  (a).begin(),(a).end()
#define MK make_pair
#define PB push_back
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define COUT(a) cout<<a<<endl
#define POW2(a) pow(a, 2.0)
//-------------
//repetition
//-------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//-------------
//debug
//-------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumpl(c) REP(i,SZ(c))cerr<<#c<<i<<"="<<(c[i])<<endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const int MOD = 1000000007;
int main()
{
	string a,b;
	cin >> a>>b;
	if ((a.at(0) == b.at(2)) && (a.at(2) == b.at(0)) && (a.at(1) == b.at(1)))
	{
		COUT("YES");
	}
	else
	{
		COUT("NO");
	}
#ifdef _DEBUG
	while(1);
#endif // _DEBUG

	return 0;
}

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

using namespace std;

#define fastio cin.tie(NULL);cout.tie(NULL);ios_base::sync_with_stdio(0);
#define debug(x) cout << x << endl;
#define endl '\n'
#define sz(x) (int)x.size()
#define popcount __builtin_popcount
#define MAXN 305
#define LOG 20
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define pb push_back
#define int long long

typedef long long ll;
typedef pair <ll, ll> pii;
typedef vector <int> vi;
typedef vector <pii> vii;
typedef vector <vi> matriz;

int n, m, l;
int dist[MAXN][MAXN];
int res[MAXN][MAXN];

int32_t main(){
    fastio
    cin >> n >> m >> l;
    int a, b, p;
    memset(dist, INF, sizeof(dist));
    memset(dist, INF, sizeof(dist));
    for(int i = 1; i <= m; i++){
        cin >> a >> b >> p;
        dist[a][b] = p;
        dist[b][a] = p;
    } 
    for(int k = 1; k <= n; k++){
        for(int i = 1; i <= n; i++){
            for(int j = 1; j <= n; j++){
                dist[i][j] = min(dist[i][j], dist[i][k] + dist[k][j]);
            }
        }
    }

    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            if(dist[i][j] <= l) res[i][j] = 1;
            else res[i][j] = INF;
        }
        res[i][i] = 0;
    }

    for(int k = 1; k <= n; k++){
        for(int i = 1; i <= n; i++){
            for(int j = 1; j <= n; j++){
                res[i][j] = min(res[i][j], res[i][k] + res[k][j]);
            }
        }
    }

    cin >> p;
    while(p--){
        cin >> a >> b;
        cout << (res[a][b] == INF ? -1 : res[a][b] - 1) << endl;
    }

    return 0;
}

Measured memory_bytes: 5128
#include <bits/stdc++.h>
#define repp(i,l,r)for(long long i=(l);i<(r);i++)
#define rep(i,n) for (long long i = 0; i < (n); ++i)
#define per(i,n) for (long long i = (n); i >= 0; --i)
const int INF = 2147483647;//int max
const long long int MOD = 1000000007;
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
//ミョ(-ω- ?)
int main() {
    ll n;
    cin >> n;
    ll ans = 0;
    ans += 1000*(n/500);
    n%=500;
    ans += 5*(n/5);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import static java.util.Arrays.*;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

	static void tr(Object... os) {
		System.err.println(deepToString(os));
	}

	void solve() {
		int n = sc.nextInt();
		int s = sc.nextInt();
		if (n == 0 && s == 0) return;
		int m = s;

		long[][][] dp = new long[n + 1][m + 1][102];
		dp[0][0][101] = 1;
		for (int i = 0; i < n; i++) {
			for (int j = 0; j <= m; j++) {
				for (int last = 0; last <= 101; last++) {
					if (dp[i][j][last] == 0) continue;
					for (int add = last - 1; add >= 0; add--) {
						if (j + add <= m)
							dp[i+1][j+add][add] += dp[i][j][last];
					}
				}
			}
		}
		long ans = 0;
		for (int last = 0; last <= 101; last++) ans += dp[n][m][last];
		out.println(ans);
	}

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

	MyScanner sc = null;
	PrintWriter out = null;
	public void run() throws Exception {
		sc = new MyScanner(System.in);
		out = new PrintWriter(System.out);
		for (;sc.hasNext();) {
			solve();
			out.flush();
		}
		out.close();
	}

	class MyScanner {
		String line;
		BufferedReader reader;
		StringTokenizer tokenizer;

		public MyScanner(InputStream stream) {
			reader = new BufferedReader(new InputStreamReader(stream));
			tokenizer = null;
		}
		public void eat() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					line = reader.readLine();
					if (line == null) {
						tokenizer = null;
						return;
					}
					tokenizer = new StringTokenizer(line);
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
		}
		public String next() {
			eat();
			return tokenizer.nextToken();
		}
		public String nextLine() {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		public boolean hasNext() {
			eat();
			return (tokenizer != null && tokenizer.hasMoreElements());
		}
		public int nextInt() {
			return Integer.parseInt(next());
		}
		public long nextLong() {
			return Long.parseLong(next());
		}
		public double nextDouble() {
			return Double.parseDouble(next());
		}
		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++) a[i] = nextInt();
			return a;
		}
	}
}

Measured memory_bytes: 60960
class dice:

    def __init__(self, numlist):
        self._men = {"T": numlist[0],
                     "B": numlist[5],
                     "N": numlist[4],
                     "S": numlist[1],
                     "W": numlist[3],
                     "E": numlist[2]}

    def roll(self, direction):
        t = dict(self._men)

        if direction == "N":
            self._men["T"] = t["S"]
            self._men["B"] = t["N"]
            self._men["N"] = t["T"]
            self._men["S"] = t["B"]
        elif direction == "S":
            self._men["T"] = t["N"]
            self._men["B"] = t["S"]
            self._men["S"] = t["T"]
            self._men["N"] = t["B"]
        elif direction == "W":
            self._men["T"] = t["E"]
            self._men["B"] = t["W"]
            self._men["W"] = t["T"]
            self._men["E"] = t["B"]
        elif direction == "E":
            self._men["T"] = t["W"]
            self._men["B"] = t["E"]
            self._men["W"] = t["B"]
            self._men["E"] = t["T"]


    def gettop(self):
        return self._men["T"]

def decode():
    numlist = [int(x) for x in input().split()]
    dlist = input()
    return numlist, dlist

if __name__ == '__main__':

    numlist, dlist = decode()
    d1 = dice(numlist)
    for c in dlist:
        d1.roll(c)
    print(d1.gettop())


Measured memory_bytes: 5612
P = int(input())
A = [int(_) for _ in input().split()]


class Factorial:
    def __init__(self, max_fact, mod):
        #mod should be prime number
        #using homogeneous_product(n,r), max_fact ≧ max(n+r-1)
        f = [1] * (max_fact + 1)
        for idx in range(2, max_fact + 1):
            f[idx] = f[idx - 1] * idx
            f[idx] %= mod
        fi = [pow(f[-1], mod - 2, mod)]
        for idx in range(max_fact, 0, -1):
            fi += [fi[-1] * idx % mod]
        fi = fi[::-1]
        self.mod = mod
        self.f = f
        self.fi = fi

    def factorial(self, n):
        return self.f[n]

    def factorial_inverse(self, n):
        return self.fi[n]

    def combination(self, n, r):
        f = self.f
        fi = self.fi
        return f[n] * fi[r] * fi[n - r] % self.mod

    def permutation(self, n, r):
        return self.f[n] * self.fi[n - r] % self.mod

    def homogeneous_product(self, n, r):
        f = self.f
        fi = self.fi
        return f[n + r - 1] * fi[r] * fi[n - 1] % self.mod


max_fact = P - 1
mod = P
fact_instance = Factorial(max_fact, mod)
comb = fact_instance.combination
perm = fact_instance.permutation
combrep = fact_instance.homogeneous_product

ans = [0] * P
for i, a in enumerate(A):
    if a:
        #1-(x-i)^(P-1)
        ans[0] += 1
        for r in range(P):
            ans[r] -= comb(P - 1, r) * pow(-i, P - 1 - r, P)
            ans[r] %= mod
print(*ans)


Measured memory_bytes: 73500
import java.io.*;
import java.util.*;


class Main {
    static final long MOD=1000000007;
    static final long solve(long[]x){
        int n=x.length;
        long ans=0;
        for(int i=0;i<n;++i)
            ans=(ans+(2*i-n+1+MOD)*((x[i]+MOD)%MOD))%MOD;
        return ans;
    }
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));
        int n=sc.nextInt();
        int m=sc.nextInt();
        long[]x=new long[n],y=new long[m];
        for(int i=0;i<n;++i)x[i]=sc.nextInt();
        for(int i=0;i<m;++i)y[i]=sc.nextInt();
        out.println(solve(x)*solve(y)%MOD);
        out.close();
    }
    // http://codeforces.com/blog/entry/7018
    //-----------PrintWriter for faster output---------------------------------
    public static PrintWriter out;
    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;
        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        String nextLine(){
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}


Measured memory_bytes: 43356
// https://atcoder.jp/contests/dp/tasks/dp_h

#include <bits/stdc++.h>

using namespace std;

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

    int n,m;
    cin >> n >> m;

    int mod = 1e9 + 7;

    char ar[n][m];

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

    int dp[n][m];

    for(int i = 0; i < n; i++)
    {
        for(int j = 0; j < m; j++)
        {
            if(!i && !j) {dp[i][j] = 1; continue;}
            if(ar[i][j] == '.')
            {
                dp[i][j] = 0;
                if(i > 0)
                {
                    dp[i][j] = (dp[i][j] + dp[i-1][j])%mod;
                }
                if(j > 0)
                {
                    dp[i][j] = (dp[i][j]+dp[i][j-1])%mod;
                }
            }
            else
            {
                dp[i][j] = 0;
            }
        }
    }

    cout << dp[n-1][m-1];
}


Measured memory_bytes: 5120