akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define fs first
#define sc second
#define mp make_pair
#define pb emplace_back
#define sz(s) ((int) s.size ())
#define all(s) s.begin (), s.end ()

using namespace std;

typedef long long ll;
typedef pair<int, int> ii;
typedef unsigned long long ull;

const ll linf = (ll) 1e18;

const int pw = 997;
const int N = 49;
const int W = 409;
const int inf = (int) 1e9;
const int mod = (int) 1e9 + 7;

const double eps = 1e-10;
const double pi = 3.1415926535897932384626433832795;

int a[N];
int b[N];
int c[N];
int dp[N][W][W];

inline void prepare () {

}
inline void solve () {
        int n, ma, mb; cin >> n >> ma >> mb;
        for (int i = 1; i <= n; i++) {
                cin >> a[i] >> b[i] >> c[i];
        }
        for (int i = 0; i <= n; i++) {
                for (int a = 0; a <= 400; a++) {
                        for (int b = 0; b <= 400; b++) {
                                dp[i][a][b] = inf;
                        }
                }
        }
        dp[0][0][0] = 0;
        int ans = inf;
        for (int i = 1; i <= n; i++) {
                for (int a = 0; a <= 400; a++) {
                        for (int b = 0; b <= 400; b++) {
                                dp[i][a][b] = dp[i - 1][a][b];
                                if (a - ::a[i] >= 0 && b - ::b[i] >= 0) {
                                        dp[i][a][b] = min (dp[i][a][b], dp[i - 1][a - ::a[i]][b - ::b[i]] + c[i]);
                                }
                                if (a > 0 && b > 0 && a * mb == b * ma) {
                                        ans = min (ans, dp[i][a][b]);
                                }
                        }
                }
        }
        if (ans == inf) {
                ans = -1;
        }
        cout << ans;
}
int main () {
        #ifdef FSTREAM
                #define name ""
                freopen (name".in", "r", stdin);
                freopen (name".out", "w", stdout);
        #endif // FSTREAM
        int tests = 1;
        prepare ();
	while (tests--) {
                solve ();
        }
}


Measured memory_bytes: 28928
#include<iostream>
using namespace std;
int main(){
int a,e=0;
  cin>>a;
  for(int i=1;i<=9;i++){
  for(int j=1;j<=9;j++){
  if(a==i*j){
  cout<<"Yes"<<endl;
   e=1;
    break;
    
  }
    if(i==9&&j==9)cout<<"No"<<endl;
  }
    if(e==1)break;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    long N;
    cin >> N;
    vector<long> A(N);
    vector<long> B(N);
    vector<long> C(N-1);
    for(size_t i=0;i<N; i++)
    {
        cin >> A[i];
    }
    for(size_t i=0;i<N; i++)
    {
        cin >> B[i];
    }
    for(size_t i=0;i<N-1; i++)
    {
        cin >> C[i];
    }
    long total=0;
    for(size_t i=0;i<N; i++)
    {
        total+=B[A[i]-1];
        if(A[i]-1==A[i-1]) total+=C[A[i-1]-1];
    }
    cout << total << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

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

#define ll long long
#define INF_LL 1LL << 60
#define INF 99999999
#define MOD (ll)1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

void put_double(double obj){printf("%.12f\n",obj);};

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

struct UnionFind {
    // 親ノードの番号を持つメンバ変数
    // ただし自分が親の時は-x(xは自身を含めた子ノードの数)
    vector<int> par;
    
    //　コンストラクタでの初期化1(初期値-1を持つn次元配列)
    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }
    
    // 与えられたノードの親ノードの番号を返すメンバ関数
    int root(int x) {
        // もしも親ノードが0以下なら、それは初期値なので自身が親
        if (par[x] < 0) return x;
        // 親ノードを再帰的に一番上までたどって返す
        // 単にroot(par[x])ではなく代入してるのは、根に直接張り直すため
        else return par[x] = root(par[x]);
    }
    
    // もし根が同じかどうかの判定
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    
    // ２つの根をマージする処理
    bool unite(int x, int y) {
        // 根をたどって、同じなら何もしない
        x = root(x); y = root(y);
        if (x == y) return false;
 
        // xもyも今は親ノードなので、子の数を比べる
        if (par[x] > par[y]) swap(x, y); // merge technique
 
        // 小さい方を親ノードにする
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    // 親ノードに入っている番号*-1 = この木のノード数を返す。
    int size(int x) {
        return -par[root(x)];
    }
};


int main()
{
    int N,M;
    cin >> N >> M;

    UnionFind uf(N);

    vector<int> p(N);
    rep(i,N)
    {
        cin >> p[i];
        p[i]--;
    }

    rep(i,M)
    {
        int x,y;
        cin >> x >> y;
        x--;
        y--;
        uf.unite(x,y);
    }

    ll ans = 0;
    rep(i,N)
    {
        if( !uf.same(i, p[i]) )ans++;
    }

    cout << N-ans << endl;
}


Measured memory_bytes: 1024
#include <iostream>

using namespace std;

int main(void) {
    int n, x;
    cin>>n>>x;
    int min_m = x;
    int cnt = 0;
    for (int i=0; i<n; ++i) {
        int m;
        cin>>m;
        min_m = min(m, min_m);
        x -= m;
        cnt += 1;
    }
    cnt += x / min_m;
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 384
import sys
input=sys.stdin.readline
from collections import deque
from heapq import heappush,heappop
import re

def int_raw():
    return int(input())
 
def ss_raw():
    return input().split()
 
def ints_raw():
    return tuple(map(int, ss_raw()))

def main():
    N = int(input())
    ress= []
    for idx in range(N):
        a,x = ss_raw()
        ress.append([a,-int(x),idx])
    ress.sort()
    for res in ress:
        print (res[2]+1)

main()


Measured memory_bytes: 38384
#include <stdio.h>
int fib[45];
int fibonacci(int n){
  if(n==0 || n==1) return fib[n]=1;
  if(fib[n]!=-1) return fib[n];
  return fib[n]=fibonacci(n-1)+fibonacci(n-2);
}

int main()
{
  int n,i;
  for(i=0;i<45;i++) {fib[i]=-1;}
  scanf("%d",&n);
  printf("%d\n",fibonacci(n));
}


Measured memory_bytes: 2044
#include <bits/stdc++.h>
using namespace std;
int main(void)
{
  int n, r = 0, min = 0;
  bool rate[8] = {};
  cin >> n;
  for(int i = 0; i != n; i++){
    int a;
    cin >> a;
    if(a < 3200) rate[a / 400] = true;
    else r++;
  }
  for(int i = 0; i != 8; i++)
    min += (int)rate[i];
  if(min == 0)
    cout << 1 << " " << r << endl;
  else
    cout << min << " " << min + r << endl;
  return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
long long ans[55][55];
long long arr[55];
bool cmp(long long a, long long  b) {
    return a>b;
}
int main() {
    ans[0][0] = 1;
    for (int i = 1; i < 51; ++i) {
        for (int j = 0; j <= i; ++j) {
            ans[i][j] += ans[i-1][j];
            if (j > 0)
                ans[i][j] += ans[i-1][j-1];
        }
    }
    int N, A, B;
    scanf("%d%d%d",&N,&A,&B);
    for (int i = 0; i < N; ++i)
        scanf("%lld",&arr[i]);
    sort(arr, arr+N, cmp);
    long long sum = 0;
    for (int i = 0; i < A; i++)
        sum += arr[i];
    double ave = (double)(sum) / A;
    long long res = 0;
    int num = 0;
    for (int i = 0; i < N; i++){
        if (arr[i] == arr[A-1])
            num++;
    }
    if (arr[0] == arr[A-1]) {
        for (int j = A; j <= B; j++) {
            res += ans[num][j];
        }
    }
    else {
        int a = 0;
        for (int i = 0; i < A; ++i){
            if (arr[i] == arr[A-1])
                a++;
        }
        res = ans[num][a];
    }
    printf("%.6lf\n%lld",ave,res);
}


Measured memory_bytes: 128
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
using namespace std;
typedef long long LL;
LL L(int n){
	LL a, i, s = 1, t = 2;
	if(n == 0)
		return 2;
	for(i = 2;i <= n;++i){
		a = t;
		t = s;
		s = t + a;
	}
	return s;
}
int main(){
	LL n, i, x;
	scanf("%lld", &n);
	for(i = 0;i <= n;i++)
		x=L(i);
	printf("%lld\n", x);
	return 0;
}

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

int main(){
	vector <int> all;
	int x;
	for( int i=0 ; i<10 ; i++ ){
		cin >> x;
		all.push_back(x);
	}
	sort(all.begin() , all.end());
	int j = 0;
	for( int i=all.size()-1 ; i>=0 && j<3 ; i-- , j++ )
		cout << all[i] << endl;
	return 0;
}

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

int main() {
  int N, K, x, s = 0;
  cin >> N >> K;
  rep(i, N) {
    cin >> x;
    s += min(x, K - x);
  }
  cout << 2 * s << endl;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
  int n,m,x=0,q,w;
  cin>>n>>m;
  vector<int>a[n];
  r(i,m)cin>>q>>w,
    a[q-1].push_back(x),
    a[w-1].push_back(x++);
  set<int>s;int p=0,st,ans=0;
  r(i,n){
    if(a[i].size()){
      if(!p)p++,st=i;
      r(j,a[i].size())
        if(s.count(a[i][j]))s.erase(a[i][j]);
        else s.insert(a[i][j]);
    }
    ans++;
    if(s.size()==0&&p){
      p=0;
      ans+=(i-st)*2;
    }
  }
  cout<<ans+1<<endl;
}

Measured memory_bytes: 3208
#include <bits/stdc++.h>
#define MOD 1000000007
#define INF 1000000000
#define LINF 1000000000000000000
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define bit(n) (1LL<<(n))
using namespace std;

typedef pair<int, int> P;
typedef pair<long long, long long> LLP;

int main() {

    int K;
    int seq[32] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    cin >> K;

    cout << seq[K - 1] << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <algorithm>
#include <numeric>
#include <random>
#include <bitset>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

#define pb push_back
#define x  first
#define y  second
#define mp make_pair
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;

#ifndef ONLINE_JUDGE
	// #include "debug.h"
#else
// #define debug(...) 42
#endif

const int mxN=100;
const ld PI=acos(-1);
const int MD=1e9+7;

int main() {
	fast_cin();
	int t=1;
	// cin>>t;
	while(t--)
	{
		int n,cn=0,res=0;
		cin>>n;
		string s;
		cin>>s;
		for(int i=0;i<n;i++){
			if(s[i]=='R') cn++;
		}
		for(int i=0;i<n;i++){
			if(s[i]=='W'){
				if(cn>0){
					cn--;
					res++;
				}
			}
			else cn--;
		}
		cout<<res;
	}
	return 0;	
}

Measured memory_bytes: 3724
def int_array_input():
    return map(int, raw_input().split(' '))

while True:
    n = int(raw_input())
    if n == 0:
        break

    stars = [tuple(int_array_input()) for x in xrange(n)]

    m = int(raw_input())
    sky = set(tuple(int_array_input()) for x in xrange(m))

    for (nx, ny) in sky:
        dx = nx - stars[0][0]
        dy = ny - stars[0][1]

        f = True

        for (tx, ty) in stars[1:]:
            tx += dx
            ty += dy
            if not ((tx, ty) in sky):
                f = False
                break

        if f:
            print dx, dy
            break

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

using namespace std;

int main(int argc, const char *argv[]) {
  int l;
  cin >> l;

  vector<int> sum_pow2{0};
  int log2l = 0;
  for (int i = 1; i <= l; i *= 2) {
    sum_pow2.push_back(sum_pow2.back() + i);
    log2l++;
  }

  int n = log2l, m = (n - 1) * 2;
  int cur = l, lim = l, idx = 0;
  stringstream sout;
  while (cur != 1) {
    if (cur % 2 == 1) {
      m++;
      cur--;
      sout << idx + 1 << ' ' << n << ' ' << lim - 1 - sum_pow2[idx] << '\n';
      lim = lim - 1 - sum_pow2[idx];
    }

    cur /= 2;
    idx++;
  }

  for (int i = 0, pow2 = 1; i < n - 1; ++i, pow2 *= 2) {
    sout << i + 1 << ' ' << i + 2 << ' ' << 0 << '\n';
    sout << i + 1 << ' ' << i + 2 << ' ' << pow2 << '\n';
  }

  cout << n << ' ' << m << '\n';
  cout << sout.str();
}

Measured memory_bytes: 3604
#include <stdio.h>
int main (){
	int A,B;
	scanf("%d %d",&A,&B);
	
	if (B%A==0)
	{
		printf("%d",A+B);
	}
	else 
	{
		printf("%d\n",B-A);
	}
	
	
	
	return 0;
}

Measured memory_bytes: 1728
//#include"bits/stdc++.h"
#include<algorithm>
#include<cassert>
#include<cmath>
#include<climits>
#include<iostream>
#include<map>
#include<set>
#include<vector>
using namespace std;
#define ll long long
#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define rep(i, j) FOR(i, 0, j, 1)
#define MP make_pair
#define PB push_back
#define endl "\n"
#define MOD 1000000007
#define DEB(x) cout<<"##"<<x<<"##"<<endl
const int INF=(int)2e9+9;
const int SIZE=(int)2e6+5;
//Brute force answers(BINARY SEARCH) symmetry
//Change perspective
struct Query{
    int l;
    int r;
    int ind;
};
bool cmp(const Query &a,const Query &b){
    return a.r<b.r;
}
int A[SIZE];
int sum(int ind,int lv,int rv,int l,int r){
    if(r<l){
        return 0;
    }
    if(lv==l && rv==r){
        return A[ind];
    }
    int mid=(lv+rv)/2;
    return sum(2*ind,lv,mid,l,min(mid,r))+sum(2*ind+1,mid+1,rv,max(mid+1,l),r);
}
void update(int pos,int val,int ind,int lv,int rv){
    if(lv==rv){
        A[ind]=val;
    }
    else{
        int mid=(lv+rv)/2;
        if(pos>mid){
            update(pos,val,2*ind+1,mid+1,rv);
        }
        else{
            update(pos,val,2*ind,lv,mid);
        }
        A[ind]=A[2*ind]+A[2*ind+1];
    }
}
int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
    #endif
    int n,q;
    cin>>n>>q;
    int ar[n+1],ans[q],last[n+1];
    Query ob[q];
    rep(i,n){
        cin>>ar[i+1];
    }
    rep(i,q){
        cin>>ob[i].l>>ob[i].r;
        ob[i].ind=i;
    }
    sort(ob,ob+q,cmp);
    rep(i,n){
        last[i+1]=-1;
    }
    int j=0;
    for(int i=1;i<=n;i++){
        if(last[ar[i]]!=-1){
            update(last[ar[i]],0,1,1,n);
        }
        update(i,1,1,1,n);
        last[ar[i]]=i;
        while(j<q){
            if(ob[j].r==i){
                ans[ob[j].ind]=sum(1,1,n,ob[j].l,ob[j].r);
                j++;
            }
            else
                break;  
        }
    }
    rep(i,q){
        cout<<ans[i]<<endl;
    }
}


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

#define repss(name, start, stop, step) for (int name = start; name < stop; name += step)
#define reps(name, start, stop) repss(name, start, stop, 1)
#define rep(name, stop) reps(name, 0, stop)

using namespace std;

int main() {
  string T;
  cin >> T;

  int cnt = 0, ans = 0;
  for (auto it = T.begin(); it != T.end(); it++) {
    if (*it == 'A' || *it == 'C' || *it == 'G' || *it == 'T') {
      cnt++;
      ans = max(cnt, ans);
    } else cnt = 0;
  }

  printf("%d\n", ans);
}


Measured memory_bytes: 256
import sys
from sys import exit
from collections import deque
from bisect import bisect_left, bisect_right, insort_left, insort_right #func(リスト,値)
from heapq import heapify, heappop, heappush
from math import *

sys.setrecursionlimit(10**6)
INF = 10**20
eps = 1.0e-20
MOD = 10**9+7

def lcm(x,y):
    return x*y//gcd(x,y)
def mint():
    return map(int,input().split())
def lint():
    return list(map(int,input().split()))
def ilint():
    return int(input()), list(map(int,input().split()))
def judge(x, l=['Yes', 'No']):
    print(l[0] if x else l[1])
def lprint(l, sep='\n'):
    for x in l:
        print(x, end=sep)

K,A,B = mint()

if B-A<2:
    print(K+1)
elif K<=A-1:
    print(K+1)
else:
    K -= A-1
    print(A+(B-A)*(K//2)+(K%2))

Measured memory_bytes: 65320
#include<bits/stdc++.h>
#define rep(i,start,lim) for(lld i=start;i<lim;i++)
#define repd(i,start,lim) for(lld i=start;i>=lim;i--)
#define scan(x) scanf("%lld",&x)
#define print(x) printf("%lld ",x)
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define br printf("\n")
#define sz(a) lld((a).size())
#define YES printf("YES\n")
#define NO printf("NO\n")
#define all(c) (c).begin(),(c).end()
#define INF         1011111111
#define LLINF       1000111000111000111LL
#define EPS         (double)1e-10
#define MOD         1000000007
#define PI          3.14159265358979323
using namespace std;
typedef long double ldb;
typedef long long lld;
lld powm(lld base,lld exp,lld mod=MOD) {lld ans=1;while(exp){if(exp&1) ans=(ans*base)%mod;exp>>=1,base=(base*base)%mod;}return ans;}
lld ctl(char x,char an='a') {return (lld)(x-an);}
char ltc(lld x,char an='a') {return (char)(x+an);}
#define bit(x,j) ((x>>j)&1)
typedef vector<lld> vlld;
typedef pair<lld,lld> plld;
typedef map<lld,lld> mlld;
typedef set<lld> slld;
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define mxm(a,b) a = max(a,b)
#define mnm(a,b) a = min(a,b)
#define endl '\n'
#define fre freopen("1.in","r",stdin); freopen("1.out","w",stdout);
#define N 1000005
//Disjoint Set Union
struct DSU{
  lld sze[N],arr[N];
  void init() {
    rep(i,1,N) arr[i]=i,sze[i]=1;
  }
  void get_union(lld a,lld b) {
    lld root_a=root(a),root_b=root(b);
    if(sze[root_a]<sze[root_b]) arr[root_a]=arr[root_b],sze[root_b]+=sze[root_a];
    else arr[root_b]=arr[root_a],sze[root_a]+=sze[root_b];
  }
  lld root(lld x) {
    while(arr[x]!=x) arr[x]=arr[arr[x]],x=arr[x];
    return x;
  } 
} dsu;
lld a[N];
slld s[N];
int main()
{
    //sync;
    dsu.init();
    lld m,n,x,y;
    cin>>n>>m;
    rep(i,1,n+1) cin>>a[i];
    rep(i,1,m+1) {
        cin>>x>>y;
        dsu.get_union(x,y);
    }
    rep(i,1,n+1) s[dsu.root(i)].insert(a[i]);
    lld ans = 0;
    rep(i,1,n+1) ans += (s[dsu.root(i)].find(i) != s[dsu.root(i)].end());
    cout<<ans;
    return 0;
}

Measured memory_bytes: 71168
import itertools

N = int(input())
L = list(map(int, input().split()))

def has_duplicates(seq):
    return len(seq) != len(set(seq))

sides = list(itertools.combinations(L, 3))
count = 0
for side in sides:
    if has_duplicates(side):
        continue
    else:
        temp = sorted(side)
        if temp[1]-temp[0] < temp[2] < temp[0]+temp[1]:
            count += 1

print(count)

Measured memory_bytes: 20612
using System;
using System.Linq;
class Program
{
    static void Main(string[] args)
    {
        // 整数の入力

        //// スペース区切りの整数の入力
        int N = int.Parse(Console.ReadLine());
        int[] t = new int[N + 1];
        int[] x = new int[N + 1];
        int[] y = new int[N + 1];

        t[0] = 0;
        x[0] = 0;
        y[0] = 0;

        for (int i = 1; i < N + 1; i++)
        {
            string[] input = Console.ReadLine().Split(' ');
            t[i] = int.Parse(input[0]);
            x[i] = int.Parse(input[1]);
            y[i] = int.Parse(input[2]);
        }

        //出力
        Console.WriteLine(hantei(N, t, x, y));
    }

    private static string hantei(int N, int[] t, int[] x, int[] y)
    {
        for (int j = 1; j < N + 1; j++)
        {
            int distance = Math.Abs(x[j] - x[j - 1]) + Math.Abs(y[j] - y[j - 1]);
            int time = t[j] - t[j - 1];
            if (distance <= time
                && ((time - distance) % 2 == 0)
                )
            {
                continue;
            }
            else
            {
                return "No";
            }
        }
        return "Yes";
    }

}


Measured memory_bytes: 16200
#include<iostream>
#include<vector>
#include<algorithm>
#define INF 1000000000
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
signed main(){
  ll n,m;
  cin >> n >> m;
  ll a[m],b[m],d[300][300];
  fill(d[0],d[300],INF);
  for(int i=0;i<n;i++){
    d[i][i]=0;
  }
  for(int i=0;i<m;i++){
    cin >> a[i]>>b[i];
    a[i]--;
    b[i]--;
    d[a[i]][b[i]]=1;
  }
  for(ll k=0;k<n;k++){
    for(ll i=0;i<n;i++){
      for(ll j=0;j<n;j++){
        d[i][j] = min(d[i][j],d[i][k]+d[k][j]);
      }
    }
  }
  /*
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++) cout << d[i][j]<<" ";
    cout << endl;
  }
  */
  bool fi;
  for(int i=0;i<n;i++){
    fi=true;
    for(int j=0;j<n;j++){
      if(d[j][i]!=INF&&d[i][j]!=INF){
        if(!fi){
          cout <<" ";
        }else{
          fi=false;
        }
        cout << j+1;
      }
    }
    cout << endl;
  }
}



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

#define pb push_back
#define MAXN 100010

using namespace std;

vector<int> graph[MAXN];
vector<int> dp(MAXN, -1);

int dfs(int u) {

    if(dp[u] != -1)
        return dp[u];
    if(graph[u].empty())
        return (dp[u] = 0);
    for(int v: graph[u])
        dp[u] = max(dp[u], dfs(v) + 1);
    return dp[u];
}

int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);

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

    for(int i = 0; i < m; i++) {
        int u, v;
        cin >> u >> v;
        u--;
        v--;

        graph[u].pb(v);
    }

    int ans = 0;
    for(int i = 0; i < n; i++)
        ans = max(ans, dfs(i));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 11108
N, M = map(int, raw_input().split())
A = [None] * N
for i in xrange(N):
    A[i] = list(raw_input())
B = [None] * M
for i in xrange(M):
    B[i] = list(raw_input())


def find(x, y):
    for i in xrange(M):
        for j in xrange(M):
            if A[y + i][x + j] != B[i][j]:
                return False
    return True

found = False
for y in xrange(N - M + 1):
    for x in xrange(N - M + 1):
        if find(x, y):
            found = True
            break
    if found:
        break
print 'Yes' if found else 'No'

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

typedef long long  ll;

ll MOD = 1000000007;
ll INF = 100000000000000;
double PI = 3.1415926535;

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<pair<ll,ll>>>;


int main(){
  ll N,T;cin >> N >> T;
  vector<ll> A(N);
  for(int i = 0;i < N;i++){
    cin >> A[i];
  }
  vector<ll> B(N);
  ll m = 0;
  m = A[0];
  for(int i = 1;i < N;i++){
    B[i] = A[i] - m;
    m = min(m,A[i]);
  }
  sort(B.begin(),B.end());
  int ans = 1;
  for(int i = N-1;i > 0;i--){
    if(B[i] == B[i-1]){
      ans++;
    }else{
      break;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
#include <cassert>
using namespace std;
using VI = vector<long>;

long lefts[101010];
long leftback[101010];
long rights[101010];
long rightback[101010];

int main() {
    long n, c;
    cin >> n >> c;
    VI xs, vs;
    VI kankaku;
    for (int i = 0; i < n; i++) {
        long x, v;
        cin >> x >> v;
        if (i == 0) {
            kankaku.push_back(x);
        } else {
            kankaku.push_back(x - xs.back());
        }
        if (i == n - 1) {
            kankaku.push_back(c - x);
        }
        xs.push_back(x);
        vs.push_back(v);
        lefts[i + 1] = v - kankaku[i] + lefts[i];
        leftback[i + 1] = v - 2 * kankaku[i] + leftback[i];
    }
    for (int i = n - 1; i >= 0; i--) {
        int j = n - 1 - i;
        long v = vs[i];
        rights[j + 1] = v - kankaku[i + 1] + rights[j];
        rightback[j + 1] = v - 2 * kankaku[i + 1] + rightback[j];
    }
    
    long ans = 0;
    for (int i = 1; i <= n; i++) {
        ans = max(ans, lefts[i]);
        lefts[i] = max(lefts[i], lefts[i - 1]);
        ans = max(ans, rights[i]);
        rights[i] = max(rights[i], rights[i - 1]);
    }
    for (int i = 1; i < n; i++) {
        ans = max(ans, rightback[i] + lefts[n - i]);
        ans = max(ans, leftback[i] + rights[n - i]);
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 5984
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<(n);i++)
#define Rep(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define eb emplace_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

void init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(12);
}

signed main(){
    init();
    run();
    return 0;
}
    
void run(){
    int k,n;
    cin>>k>>n;
    vi a(n);
    rep(i,n)cin>>a[i];
    vi v(n);
    rep(i,n-1)v[i]=a[i+1]-a[i];
    v[n-1]=k+a[0]-a[n-1];
    int s=accumulate(all(v),0ll);
    int ans=inf;
    rep(i,n)ans=min(ans,s-v[i]);
    cout<<ans<<endl;
}

Measured memory_bytes: 3456
#include<bits/stdc++.h>
            using namespace std;
            #define rep(i,b) for(i=0;i<b;++i)
            #define repp(i,a,b) for(i=a;i<b;++i)
            #define endl "\n"
            //#define LLONG_MAX 99999999999999
            typedef long long int lli;
            int main(){
                ios_base::sync_with_stdio(false);
                cin.tie(NULL);
                lli t,n,i,j,b,a,q,m;
                cin>>n>>m;
                vector<lli> v(m);
                rep(i,m)cin>>v[i];
                lli ans=0;
                rep(i,m){
                    ans+=v[i];
                }
                if(ans>n){
                    cout<<-1<<endl;
                }
                else{
                    cout<<n-ans<<endl;
                }

            }



Measured memory_bytes: 3688
import java.util.*;
import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main{
    static long mod=1000000007;
//    static int dx[]={-1,0,1,0};
//    static int dy[]={0,-1,0,1};

    public static void main(String[] args)   throws Exception, IOException{        
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);

        int n = sc.nextInt();
        P p[]=new P[n];
        String ans="Yes";
        for (int i = 0; i < p.length; i++) {
			p[i]=new P(sc.nextInt(), sc.nextInt());
		}
        sort(p);
        
        long s=0;
        for (int i = 0; i < p.length; i++) {
        	s+=p[i].a;
        	if(s > p[i].b) {ans="No"; break;}
		}
        
		
        out.println(ans);
        out.flush();
    }
    static long gcd(long a, long b){
        if(min(a,b) == 0)return max(a,b);
        return gcd(max(a,b) % min(a,b),min(a,b));
    }

    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }

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


//class P {
//    int id, d;
//    P(int  id, int d) {
//        this.id=id;
//        this.d=d;
//    }
//}

class P implements Comparable<P>{
    int a,b;
    P(int a, int b) {
    	this.b=b;
    	this.a=a;
    }

    public int compareTo(P p){
        return b-p.b;
    }
}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public int[] nextIntArray(int size) throws IOException{
        int r[] = new int[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextInt(); 
        }
        return r;
    }
    public long[] nextLongArray(int size) throws IOException{
        long r[] = new long[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextLong(); 
        }
        return r;
    }
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}


Measured memory_bytes: 50924
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define rs(a, b) ((a) >> (b))
#define ls(a, b) ((a) << (b))
#define gcd __gcd
#define lcm(a, b) ((a * b) / gcd(a, b))
#define pq priority_queue
#define um unordered_map
#define us unordered_set
#define lb lower_bound
#define ub upper_bound
#define F first
#define B begin()
#define E end()
#define ln length()
#define sz size()
#define S second
#define em empty()
#define nani(x) cerr << #x << " is " << x << endl;
#define ch(x) (x - 'a' + 1)
#define mp make_pair
#define pb push_back
#define loop(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
#define scan(x, n) loop(i, 0, n) cin >> x[i];
#define adde(g, u, v) g[u].pb(v), g[v].pb(u);
#define addew(g, u, v, w) g[u].pb({ v, w }), g[v].pb({ u, w });
#define print(x, n) loop(i, 0, n) cout << x[i] << " ";
#define fast ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define inf 10000000000
#define mod 1000000007

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef pair<long, long> pll;
typedef vector<ii> vii;
typedef vector<pll> vll;
typedef um<int, int> umii;
typedef um<char, int> umci;
typedef map<char, int> mci;
typedef map<int, int> mii;

int main()
{
    fast;
    //freopen("input.txt", "r", stdin);
    int n, a, b;
    cin >> n >> a >> b;
    cout << min(n * a, b);
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

int main(){
	
	char contest[5];
	scanf("%s", &contest);
	
	if(strcmp(contest, "ABC") == 0){
		printf("ARC");
	}else if(strcmp(contest,"ARC") == 0){
		printf("ABC");
	}
	return 0;
}

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

int a[12][12];
int cost[12];

int main() {
  int n, m, x; scanf("%d %d %d", &n, &m, &x);
  for (int i = 0; i < n; ++i) {
    scanf("%d", &cost[i]);
    for (int j = 0; j < m; ++j) {
      scanf("%d", &a[i][j]);
    }
  }
  int ans = -1;
  for (int i = 1; i < (1<<n); ++i) {
    vector<int> c(m); int cur = 0;
    for (int j = 0; j < n; ++j) {
      if (((i>>j)&1) == 0) continue;
      cur += cost[j];
      for (int k = 0; k < m; ++k) {
	c[k] += a[j][k];
      }
    }
    if (all_of(c.begin(), c.end(), [x](int z){return z >= x;})) {
      if (ans == -1) ans = cur;
      else ans = min(cur, ans);
    }
  }
  printf("%d", ans);
  return 0;
}

Measured memory_bytes: 3784
use proconio::*;
use std::collections::BTreeMap;

fn run() {
    input! {
        n: usize,
        mut a: [i64; n],
    }
    let mut memo = vec![];
    for _ in 0..2 {
        // 塗った数、直前に塗った、スコア
        let mut map = BTreeMap::<(usize, bool), i64>::new();
        map.insert((0, false), 0);
        let mut ans = vec![];
        ans.push(map.clone());
        for (i, &a) in a.iter().enumerate() {
            let mut next = BTreeMap::new();
            for ((c, p), s) in map {
                if c + 1 < i / 2 {
                    continue;
                }
                if !p {
                    let po = next.entry((c + 1, true)).or_insert(std::i64::MIN);
                    *po = std::cmp::max(*po, s + a);
                }
                let po = next.entry((c, false)).or_insert(std::i64::MIN);
                *po = std::cmp::max(*po, s);
            }
            map = next;
            ans.push(map.clone());
        }
        a.reverse();
        memo.push(ans);
    }
    let right = memo.pop().unwrap();
    let left = memo.pop().unwrap();
    let mut ans = std::i64::MIN;
    for (&(c, _), &x) in left[n].iter() {
        if c == n / 2 {
            ans = std::cmp::max(ans, x);
        }
    }
    for i in 1..=n {
        for (&(c, _), &x) in left[i - 1].iter() {
            for (&(d, _), &y) in right[n - i].iter() {
                if c + d == n / 2 {
                    ans = std::cmp::max(ans, x + y);
                }
            }
        }
    }
    println!("{}", ans);
}

fn main() {
    run();
}


Measured memory_bytes: 127524
package main

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

var (
	read  = bufio.NewReader(os.Stdin)
	write = bufio.NewWriter(os.Stdout)
)

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

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

func yesno(result bool) {
	if result {
		fmt.Fprintln(write, "Yes")
	} else {
		fmt.Fprintln(write, "No")
	}
}

func printansStr(result bool, a, b string) {
	if result {
		fmt.Fprintln(write, a)
	} else {
		fmt.Fprintln(write, b)
	}
}

func printansInt(result bool, a, b int) {
	if result {
		fmt.Fprintln(write, a)
	} else {
		fmt.Fprintln(write, b)
	}
}

func main() {
	defer write.Flush()

	var s string
	fmt.Fscan(read, &s)

	var ans string
	if s == "Sunny" {
		ans = "Cloudy"
	} else if s == "Cloudy" {
		ans = "Rainy"
	} else {
		ans = "Sunny"
	}
	fmt.Fprintln(write, ans)

}


Measured memory_bytes: 640
while(<>){
	chomp;
	next if($. == 1);
	($cost{$.}, $lim{$.}) = split(/ /, $_);
}

$r = 0;
for (sort{$lim{$a} <=> $lim{$b}} keys %lim){
	$r += $cost{$_};
	if($r > $lim{$_}){
		print "No\n";
		exit;
	}
}

print "Yes\n";


Measured memory_bytes: 74340
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,x) for(int i=0;i<x;i++)
#define put(ans)    cout << ans << endl;
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())

//最大公約数
ll gcd(ll a, ll b) {
    return b ? gcd(b, a%b) : a;
}
//最小公倍数
ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}
bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

int strsum(const int n){
    string s = to_string(n);
    int b(0);
    rep(i,s.size()){
        b += s[i]-'0';
    }
    return b;
}

int main(){
    int m;
    cin >> m;
    m = 24-m;

    cout << m+24 << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<(n);i++)
#define MOD 1000000007
#define all(n) (n).begin(),(n).end()
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}

int main(){
	int n,a,b,c;
	string s;
	cin >> n;
	cout << n*n << endl;

}

Measured memory_bytes: 256
import java.util.*;
public class Main {
public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
  	int numA = sc.nextInt();
  	int numB = sc.nextInt();
  	int numC = sc.nextInt();
  	
  	int ans = numC - (numA - numB);
  	if(ans < 0) ans = 0;
  
  	System.out.println(ans);
  
	}
}

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

struct State{
    int Y,X,M,D;
};

int dx[4]={1,0,-1,0}, dy[4]={0,1,0,-1};
bool vis[20][20][16][4]={};

int main()
{
    int R,C;
    cin >>R >>C;
    vector<string> s(R);
    rep(i,R) cin >>s[i];

    queue<State> que;
    que.push({0,0,0,0});
    vis[0][0][0][0]=true;
    while(!que.empty())
    {
        State S = que.front(); que.pop();
        int y = S.Y, x = S.X, m = S.M, d = S.D;
        // printf("%d %d %d %d\n", y,x,m,d);

        vis[y][x][m][d] = true;

        char c = s[y][x];
        if(c=='@') break;

        if(c=='?')
        {
            rep(i,4)
            {
                // move
                int ny = (y+dy[i]+R)%R;
                int nx = (x+dx[i]+C)%C;
                if(!vis[ny][nx][m][i])
                {
                    vis[ny][nx][m][i] = true;
                    que.push({ny,nx,m,i});
                }
            }
        }
        else
        {
            if(c=='<' || c=='>' || c=='v' || c=='^')
            {
                if(c=='<') d = 2;
                if(c=='>') d = 0;
                if(c=='v') d = 1;
                if(c=='^') d = 3;
            }
            else if(c=='_')
            {
                if(m==0) d = 0;
                else d = 2;
            }
            else if(c=='|')
            {
                if(m==0) d = 1;
                else d = 3;
            }
            else if('0'<=c && c<='9') m = c-'0';
            else if(c=='+') m = (m+1)%16;
            else if(c=='-') m = (m+15)%16;

            // move
            int ny = (y+dy[d]+R)%R;
            int nx = (x+dx[d]+C)%C;
            if(!vis[ny][nx][m][d])
            {
                vis[ny][nx][m][d] = true;
                que.push({ny,nx,m,d});
            }
        }
    }

    string ans = "NO";
    rep(i,R)rep(j,C)if(s[i][j]=='@')
    {
        rep(k,16)rep(l,4)if(vis[i][j][k][l]) ans = "YES";
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pub push_back
#define pob pop_back
#define loops(i, s, n) for (ll i = s; i < n; i++)
#define loop(i, n) for (ll i = 0; i < n; i++)
#define loopr(i, s, e) for (ll i = s; i >= e; i--)
#define eps 1e-9
#define loopitr(mp) for (auto itr = mp.begin(); itr != mp.end(); itr++)
#define pii pair<ll, ll>
#define vi vector<ll>
#define vll vector<ll>
#define vpii vector<pair<ll, ll>>
#define even_set 0xAAAAAAAA ... 1010101010
#define odd_set 0x55555555 ... 01010101
#define fastio                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define vall(v) v.begin(), v.end()
#define mkp make_pair
#define ret return
#define cont continue
#define nl endl
#define ff first
#define ss second
#define cnt_bits __builtin_popcount
#define test  \
    ll T;    \
    cin >> T; \
    while (T)
#define arrinit \
    ll n;      \
    cin >> n;   \
    ll a[n];   \
    loop(i, n) { cin >> a[i]; }
#define init(arr, n, val)       \
    for (ll i = 0; i < n; i++) \
        arr[i] = val;
#define debug cout << "hello\n";
#define debugi(i) cout << "hello" << i << endl;
const ll mod = 1000000007;

int main()
{
    fastio;
    arrinit;

    ll tot = 0;
    ll mx = a[0];
    loops(i, 1, n){
        if(mx > a[i]){
            tot += mx-a[i];
        }
        else
          mx = max(mx, a[i]);
    }

    cout<<tot<<endl;   
}

Measured memory_bytes: 5152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 200005;
ll a[maxn];
bool b[maxn];
int main()
{
    string a, b;
    cin >> a >> b;
    int len1 = a.length();
    //printf("%s",a.substr(0,len1))
    if (b.substr(0, len1) == a)
        puts("Yes");
    else
        puts("No");
    return 0;
}

Measured memory_bytes: 3628
import sys
#立方体で数字が自由なさいころ
class Dice:
    def __init__(self,top,bottom,front,rear,right,left):
        self.top=top
        self.front=front
        self.right=right
        self.bottom=bottom
        self.rear=rear
        self.left=left

    def rotate_front(self):
        t,b,f,r=self.top,self.bottom,self.front,self.rear
        self.top=r
        self.bottom=f
        self.front=t
        self.rear=b

    def rotate_rear(self):
        t,b,f,r=self.top,self.bottom,self.front,self.rear
        self.top=f
        self.bottom=r
        self.front=b
        self.rear=t

    def rotate_right(self):
        t,b,r,l=self.top,self.bottom,self.right,self.left
        self.top=l
        self.bottom=r
        self.right=t
        self.left=b

    def rotate_left(self):
        t,b,r,l=self.top,self.bottom,self.right,self.left
        self.top=r
        self.bottom=l
        self.right=b
        self.left=t

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")

def main():
    top,front,right,left,rear,bottom=map(int, input().split())
    d=Dice(top,bottom,front,rear,right,left)
    s=input()
    for c in s:
        if c=="N":d.rotate_rear()
        if c=="S":d.rotate_front()
        if c=="E":d.rotate_right()
        if c=="W":d.rotate_left()
    print(d.top)

main()


Measured memory_bytes: 5616
from collections import Counter

h , w = map(int , input().split())
c = [[] for _ in range(10)]
a = [[] for _ in range(h)]
b = Counter()
for i in range(10):
    c[i] = list(map(int,input().split()))
    
for i in range(h):
    a[i] = list(map(int,input().split()))
    b += Counter(a[i])
    
for k in range(10):
    for i in range(10):
        for j in range(10):
            c[i][j] = min( c[i][j] , c[i][k] + c[k][j] )

ans = 0
for i in range(10):
    ans += (c[i][1] * b[i] )
    
print(ans)

Measured memory_bytes: 40428
#include<iostream>
#include<cstdio>
/*１つの整数 x を読み込んで、x の３乗を計算し結果を出力するプログラムを作成して下さい。 */
using namespace std;
 
int x;
int main()
{
  scanf("%d",&x);
  cout <<x*x*x<<endl;
  return 0;
}

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

int main() {
  int s;
  int ans1=0, ans10=0, ans100=0;
  cin >> s;
  
  ans1 = s%10;
  ans10 = ((s-ans1)/10)%10;
  ans100 = ((s-ans1-ans10*10)/100)%10;
  
  //cout << ans1 << endl;
  //cout << ans10 << endl;
  //cout << ans100 << endl;
  cout << ans1 + ans10 + ans100 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
#include <queue>
#include <map>
#include <set>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = (int)1e9 + 7;
const int MAX_N = (int)1e5 + 5;
#define debug(x) cout << #x << ": " << x << endl
template<typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2>& p) { os << p.first << " " << p.second; return os; }
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v) { for(int i = 0; i < (int) v.size(); i++) os << v[i] << (i + 1 != v.size() ? " " : ""); return os; }

void solve()
{
    string s, t; cin >> s >> t;
    t.pop_back();
    if(s == t) cout << "Yes" << endl;
    else cout << "No" << endl;
}

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    solve();
    return 0;
}

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

typedef long long ll;
 
using tpl = tuple<int, int, int>;
typedef pair<int,int> pii;

void fastStream(){cin.tie(0);std::ios_base::sync_with_stdio(0);}


int H, W, N;
int main(){

    cin >> N >> H >> W;
    cout << (N - H + 1) * (N - W + 1) << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int maxn=100005;
struct SHIT
{
    int one,two;
    bool operator<(const SHIT  &b)const {
        if(this->one!=b.one) return (this->one<b.one);
        return (this->two<b.two);
    }
}shit[maxn];
bool cmp(SHIT a,SHIT b)
{
    if(a.one+a.two!=b.one+b.two)
        return a.one+a.two<b.one+b.two;
    return a.one<b.one;
}
map<SHIT,bool>mp;
int main()
{
    int n;
    mp.clear();
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
    {
        scanf("%d%d",&shit[i].one,&shit[i].two);
        mp[shit[i]]=1;
    }
    if(!(shit[1].one==shit[2].two&&shit[1].two==shit[2].one&&shit[1].one==0&&shit[1].two!=0)){
        puts("-1");
        return 0;
    }
    int mn=shit[1].two;
    int ans=2*n-2;
    for(int i=3;i<=n;i++)
    {
        if(shit[i].one==0||shit[i].two==0||shit[i].one+shit[i].two<mn){
            puts("-1");
            return 0;
        }
    }
    sort(shit+1,shit+n+1,cmp);
    for(int i=1,j;i<=n;i=j)
    {
        j=i+1;
        while(j<=n&&shit[j].one+shit[j].two==shit[i].one+shit[i].two)
            j++;
        for(int k=i;k<j;k++)
            mp[shit[k]]=1;
        int last=0,left=0;
        for(int k=i,tk;k<j;k=tk)
        {
            tk=k+1;
            while(tk<j&&shit[tk].one==shit[k].one){
                tk++;
            }
            int now=tk-k;
            bool one=0,two=0;
            SHIT tmp1,tmp2;
            tmp1.one=shit[k].one-1;
            tmp1.two=shit[k].two-1;
            if(mp.count(tmp1)){
                one=1;two=1;
            }


            tmp1.one=shit[k].one-1;
            tmp1.two=shit[k].two+1;
            tmp2.one=shit[k].one+1;
            tmp2.two=shit[k].two-1;



            one=one|mp.count(tmp1);
            two=two|mp.count(tmp2);

            tmp1.two--;
            tmp2.one--;
            one=one|mp.count(tmp1);
            two=two|mp.count(tmp2);

            if(shit[k].one==0)one=1;
            if(shit[k].two==0) two=1;
            if(one==0||two==0){
                puts("-1");
                return 0;
            }
            int del=0;
            if(last+1==shit[k].one){
                del=min(now,left);
                ans-=del;
            }
            tmp1.two--;
            if(mp.count(tmp1)){
                ans-=now-del;
                now=del;
            }
            last=shit[k].one;
            left=now;
        }
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 7296
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define rep(i, from, to) for (ll i = from; i < (to); ++i)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define pb push_back
using ll = long long;
using vin=vector<int>;
using vll=vector<ll>;
using vst=vector<string>;
using P = pair<int, int>;
const int inf=1e9+7;
const ll INF=9e18;
template <typename T> bool chmin(T &a, const T& b){if(a > b){a = b;return true;}return false;}
template <typename T> bool chmax(T &a, const T& b){if(a < b){a = b;return true;}return false;}
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };

int main(){cout<<fixed<<setprecision(20);
		   ll n,m;
           cin>>n>>m;
           vll x(n),y(m);
           rep(i,0,n)cin>>x[i];
           rep(i,0,m)cin>>y[i];
           ll tate=0,ans=0;
           rep(i,0,m-1){
             tate=(tate+(y[i+1]-y[i])%inf*(i+1)%inf*(m-i-1)%inf)%inf;
           }
           rep(i,0,n-1){
             ans=(ans+tate*(x[i+1]-x[i])%inf*(i+1)%inf*(n-i-1)%inf)%inf;
           }
           cout<<ans<<endl;
}

Measured memory_bytes: 4788
n=int(input())
x=list(map(int,input().split()))
check=0
for y in x:
    if y%2==0:
        if y%3==0 or y%5==0:
            check=0
        else:
            check=1
            break

if check==1:
    print('DENIED')
else:
    print('APPROVED')

Measured memory_bytes: 3060