akhauriyash/Code-Regression huggingface dataset:
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")

#include <bits/stdc++.h>

using namespace std;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "


// CHECK THE LIMITS
typedef long long ll;

const int MOD = 1000000007;
const ll INFLL = 1e18;
const int INF = 1e9;
const int NMAX = 1000001;
const int MAX = 1e6+5;
ll gcd(ll a, ll b) {
  return b ? gcd(b, a%b) : a;
} 

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

ll mul(ll x, ll y)
{
	return (ll) (x * y) % MOD;
}

ll power(ll x, ll y)
{
	ll sol = 1;
	while(y)
	{
		if(y&1)
		{
			sol = mul(sol,x);
		}
		x = mul(x,x);
		y >>=1;
	}
	return sol;
}

ll inv_mod(ll x)
{
	return power(x, MOD-2);
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
	int n;
	cin >> n;
	ll lcm = 1;
	vector<int> v(n);
	vector<int> ans(MAX);
	for(int i =0; i< n; ++i)
	{
		ll x;
		cin >> x;
		v[i] = x;
		map<int,int> cnt;
		for(int i = 2; i*i <= x; ++i)
		{
			while(x % i == 0)
			{
				++cnt[i];
				x/=i;
			}
		}
		if(x!=1)
		{
			++cnt[x];
		}

		for(auto &p : cnt)
		{
			ans[p.first] = max(ans[p.first], p.second);
		}
	}
	for(int j = 0; j < MAX; ++j)
	{
		ll k = ans[j];
		for(int i = 0; i < k; ++i)
		{
			lcm = mul(lcm,j);
		}
	}
	
	ll sum = 0;
	for(ll x : v)
	{
		sum = (sum + mul(lcm, inv_mod(x))) % MOD;
	}

	cout << sum;

    return 0;
}

Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
string parse_letter(string &S, int &p);
string parse_string(string &S, int &p);
string parse_cipher(string &S, int &p);
string parse_letter(string &S, int &p){
  if (S[p] == '+'){
    p++;
    string ans = parse_letter(S, p);
    if (ans == "?"){
      return "?";
    } else if (ans == "Z"){
      return "A";
    } else {
      ans[0]++;
      return ans;
    }
  } else if (S[p] == '-'){
    p++;
    string ans = parse_letter(S, p);
    if (ans == "?"){
      return ans;
    } else if (ans == "A"){
      return "Z";
    } else {
      ans[0]--;
      return ans;
    }
  } else {
    string ans = "";
    ans += S[p];
    p++;
    return ans;
  }
}
string parse_string(string &S, int &p){
  if (S[p] == '['){
    p++;
    string ans = parse_cipher(S, p);
    p++;
    reverse(ans.begin(), ans.end());
    return ans;
  } else {
    string ans = parse_letter(S, p);
    return ans;
  }
}
string parse_cipher(string &S, int &p){
  string ans;
  while (S[p] != ']'){
    ans += parse_string(S, p);
    if (p == S.size()){
      break;
    }
  }
  return ans;
}
int main(){
  while (1){
    string S;
    cin >> S;
    if (S == "."){
      break;
    }
    int p = 0;
    string T = parse_cipher(S, p);
    int N = T.size();
    for (int i = 0; i < N; i++){
      if (T[i] == '?'){
        cout << 'A';
      } else {
        cout << T[i];
      }
    }
    cout << endl;
  }
}


Measured memory_bytes: 3088
//by shubham_bitsg

#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;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector <string> vs;

//#define oset tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define forl(i,a,b) for (int i = a; i < b; i++)
#define rfor(i,b,a) for (int i = b; i >= a; i--)
#define f first
#define s second
#define pb push_back
#define mp make_pair
#define srt(x) sort(x.begin(), x.end())
#define sumup(x) accumulate(x.begin(), x.end(), 0)
#define PI 3.141592653589793238

struct room {
    int flag = -1;
    vi connections;
};
queue <int> q;
int n, m;
void solve(vector <room> &rm, room &r, map <int,bool> &isvisited);
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n>>m;
    vector <room> rm(n); //rm[0] is room1 and so on..
    forl(i,0,m) {
        int a, b;
        cin>>a>>b;
        rm[a-1].connections.push_back(b);
        rm[b-1].connections.push_back(a);
    }
    map <int,bool> isvisited;
    forl(i,1,n+1) {
        isvisited[i] = false;
    }
    isvisited[1] = true;
    q.push(1);
    solve(rm, rm[q.front()-1], isvisited); // passing room1
}
void solve(vector <room> &rm, room &r, map <int,bool> &isvisited) {
    for(auto &con: r.connections) {
        if(!isvisited[con]) {
            isvisited[con] = true;
            rm[con-1].flag = q.front();
            q.push(con);
        }
    }
    q.pop();
    if(q.empty()) {
        forl(i,1,n+1) { // scanning isvisited
            if(!isvisited[i]) {
                cout<<"No\n";
                return;
            }
        }
        cout<<"Yes\n";
        forl(i,1,n) {
            cout<<rm[i].flag<<"\n";
        }
        return;
    }
    solve(rm, rm[q.front()-1], isvisited);
}

Measured memory_bytes: 26212
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <iomanip>
using namespace std;
#define INF 1e9
#define PI acos(-1)
typedef long long ll;
typedef pair<int, int> p_ii;


int main() {
	ll ans = 1e10;
	ll h, w; cin >> h >> w;

	for (int i = 0; i <= h; i++) {
		ll a = i * w;
		ll mid = (h - i) / 2;
		ll b = mid * w, c = (h - i - mid)*w;
		ll d = (h - i)*(w / 2), e = (h - i)*(w - w / 2);

		ll mxarea1 = max(a, max(b, c));
		ll mnarea1 = min(a, min(b, c));
		ans = min(ans, mxarea1 - mnarea1);

		ll mxarea2 = max(a, max(d, e));
		ll mnarea2 = min(a, min(d, e));
		ans = min(ans, mxarea2 - mnarea2);
	}

	swap(h, w);

	for (int i = 0; i <= h; i++) {
		ll a = i * w;
		ll mid = (h - i) / 2;
		ll b = mid * w, c = (h - i - mid)*w;
		ll d = (h - i)*(w / 2), e = (h - i)*(w - w / 2);

		ll mxarea1 = max(a, max(b, c));
		ll mnarea1 = min(a, min(b, c));
		ans = min(ans, mxarea1 - mnarea1);

		ll mxarea2 = max(a, max(d, e));
		ll mnarea2 = min(a, min(d, e));
		ans = min(ans, mxarea2 - mnarea2);
	}

	cout << ans << endl;

	return 0;
}

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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = 1LL << 60;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(16);

	//cout << setprecision(10) << scientific << ans << endl;
}

signed main() {
	ll n, i;

	cin >> n >> i;
	
	cout << n - i + 1 << endl;
}

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

#define rep2(x,fr,to) for(int x=(fr);x<(to);x++)
#define rep(x,to) for(int x=0;x<(to);x++)
#define repr(x,fr,to) for(int x=(fr);x>=(to);x--)
#define all(c) c.begin(),c.end()
#define sz(v) (int)v.size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<ll,int> pii;
typedef vector<ll> VL; const int MD = (int)1e9 + 7;
void dbg(){ cerr << "\n"; } template <typename T,typename ...T2> void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T, class T2> void amax(T& a,T2 b){ if(a < b) a = b;}

ll gcd(ll x, ll y){ return y? gcd(y, x%y): x; }

int main()
{
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n; ll z;
	cin >>n >>z;
	VL b(n);
	
	rep(i, n){
		ll q; cin >>q;
		b[i] = abs(q - z);
	}
	ll ans =0;
	rep(i, n) ans = gcd(ans, b[i]);
	cout <<ans <<"\n";
	return 0;
}


Measured memory_bytes: 1024
import java.math.BigInteger;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		for(Scanner s = new Scanner(System.in);s.hasNext();){
			try{
				System.out.println(parse(s.nextLine()));
			}catch(Exception e){
				System.out.println("overflow");
			} 
		}
	}
	
	static Cplx parse(String str)throws Exception{
		if(str.matches("-?\\d+")){
			if(new BigInteger(str).compareTo(BigInteger.valueOf(10000))>0) throw new Exception();
			return new Cplx(new Integer(str),0);
		}
		Deque<Cplx> n = new ArrayDeque<Cplx>();
		Deque<String> q = new ArrayDeque<String>();
		for(int i = 0, j = 0; i < str.length(); i += j){
			String c = str.substring(i,i+1);
			if(c.equals("i")){
				n.push(new Cplx(0,j=1));
			}else if(c.matches("\\d")){
				n.push(parse(str.substring(i,i+(j=t(str.substring(i))))));
			}else if(c.matches("\\(")){
				n.push(parse(str.substring(i+1,i-1+(j=t(str.substring(i))))));
			}else if(c.equals("*")){
				n.push(n.pop().mul(parse(str.substring(i+1,i+(j=t(str.substring(i+1))+1)))));
			}else{
				j = 1;
				q.push(c);
			}
		}
		for(;q.size()>0;){
			String op = q.removeLast();
			if(op.equals("+")){
				n.add(n.removeLast().add(n.removeLast()));
			}else{
				n.add(n.removeLast().sub(n.removeLast()));
			}
		}
		return n.pop();
	}
	
	static int t(String str){
		int c = 0, i = 0;
		if(str.matches("[i\\d]+.*")){
			for(;i<str.length() && str.substring(i,i+1).matches("[i\\d]");++i){
			}
			return i;
		}
		for(;i<str.length();++i){
			if(str.charAt(i)=='('){
				++c;
			}else if(str.charAt(i)==')'){
				--c;
				if(c<1){
					return i+1;
				}
			}
		}
		return -1;
	}
	
	static class Cplx{
		int a,b;
		Cplx(int aa, int bb) throws OE{
			if(aa<-10000||10000<aa||bb<-10000||10000<bb){
				throw new OE();
			}
			a=aa;b=bb;
		}
		Cplx add(Cplx c) throws OE{
			return new Cplx(a+c.a,b+c.b);
		}
		Cplx sub(Cplx c) throws OE{
			return new Cplx(a-c.a,b-c.b);
		}
		Cplx mul(Cplx c) throws OE{
			return new Cplx(a*c.a-b*c.b,b*c.a+a*c.b);
		}
		public String toString(){
			String r ="";
			if(a!=0) r+=a;
			if(b!=0){if(b>0&&a!=0)r+="+";r+=b+"i";}
			return r==""?"0":r; 
		}
	}
	
	static class OE extends Exception{}
}

Measured memory_bytes: 13000
#include <bits/stdc++.h>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>
#define fill(a,val) memset(a,val,sizeof(a))
#define REP(i,a,b) for (auto i = a; i != b; i++)
#define ll long long int
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define mod 1000000007
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define pb push_back
#define SQ(a) (a)*(a)

const int N = 200005;

using namespace std;

int main()
{
    std::ios::sync_with_stdio(false);
    //ll p = 1000000007; 
    
    int T = 1;
    //cin>>T;
    // cin.ignore(); must be there when using getline(cin, s)
    while(T--)
    {
          int a;
          cin>>a;

          cout<<a + a*a + a*a*a;
    }
    return 0;
}

 

Measured memory_bytes: 3648
#include<bits/stdc++.h> 
//#define <- プログラムの文字列を置換する
//typedef <- 新しい型に名前を付けるためのキーワード

using namespace std;

#define MAX_N 1

const double pi = 3.141592653589793;
const long long MOD = 1e9 + 7;
const long long INF = 1e15;

int main(){
    string s;
    cin >> s;
    if(s =="ABC") cout << "ARC" << endl;
    else cout << "ABC" << endl;
    return 0;
}


Measured memory_bytes: 3592
import java.util.*;

public class Main {
    public static void main(String[] args)  {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        
        for(int i = 1; i <= n; i++){
            if(i % 3 == 0 || String.valueOf(i).contains("3")){
                System.out.print(" " +i);
            }
        }
        System.out.println();
    }
}



Measured memory_bytes: 29200
#include<stdio.h>

int gcm(int p, int q){
	int r;
	if(p < q){
		int tmp, r;
		tmp = p;
		p = q;
		q = tmp;
	}
	do{
		r = p%q;
		p = q;
		q = r;
	} while(r != 0);
	return p;
}

int main(){
	int A, B, C, Q, b;
	char line[16];

	fgets(line, 16, stdin);
	sscanf(line, "%d %d %d", &A, &B, &C);

	Q = A%B;
	if( Q == 0 ? C == 0 : C%gcm(B, A%B) == 0 ){
		printf("YES\n");
	} else{
		printf("NO\n");
	}

	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main(){
  string S,T;
  cin>>S>>T;
  int count=0;
  for(int i=0;i<S.size();i++){
    if(S.at(i)==T.at(i)){
      count=count+1;
    }
  }
  cout<<count<<endl;
}

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

int main() {
  int N, A;
  A = 0;
  cin >> N;
  for ( int i = 0; i < N; i++ ) {
    string S;
    cin >> S;
    if ( S == "Y")
      A++;
  }
  if ( A == 0 )
    cout << "Three" << endl;
  else
    cout << "Four" << endl;
}



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

int main()
{
	string S;

	cin >> S;

	int s = S.size()-2,ans = 0;

	for (int a = 0, b = s/2; a < s/2; a++,b++) {
		if (S[a] != S[b]) {
			s -= 2;
			a = -1;
			b = s/2-1;
		}
		else if (a == s / 2 - 1 && ans < s) {
			ans = s;
			break;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,*b;
  cin>>a;
  b = (int *)malloc(sizeof(int)*(a+1));
 
  for(int i=1;i<=a;i++)
    cin>>b[i];
  
  for(int i=1;i<=a;i++){
    cout<<"node "<<i<<": key = "<<b[i]<<", ";
    if(i!=1) cout<<"parent key = "<<b[i/2]<<", ";
    if(i*2<=a) cout<<"left key = "<<b[i*2]<<", ";
    if((i*2+1)<=a) cout<<"right key = "<<b[i*2+1]<<", ";
    cout<<endl;
  }
  
  return 0;
}



Measured memory_bytes: 3084
#include<bits/stdc++.h>
using namespace std;
int main()
{

        string s;
        cin>>s;
        int m=s.length(),c=0;
        for(int i=0,j=m-1;i<m/2;i++,j--)
        {
            if(s[i]!=s[j])
                c++;
        }
        cout<<c<<endl;
}


Measured memory_bytes: 3632
#include <stdio.h>

int main(void) {
	char a[3],b[3];
	scanf("%s",a);
	scanf("%s",b);
	if(a[0]==b[2]&&a[1]==b[1]&&a[2]==b[0])
		printf("YES\n");
	else
		printf("NO\n");
	return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <numeric>

using namespace std;

#define mod 1000000007

double getpow(double x, int n)
{
	if(n == 0) return 1.0;
	double tmp = getpow(x, n / 2);
	if(n % 2 == 0) return tmp * tmp;
	else return tmp * tmp * x;
}

int main()
{
	double n, m, d;
	cin >> n >> m >> d;
	double ans;
	if(d == 0){
		ans = 1.0 / n * (m - 1.0);
	} else {
		double tmp = 2.0 * (n - d) / (n * n);
		ans =tmp * (m - 1.0);
	}
	printf("%.10f\n", ans);
}


Measured memory_bytes: 256
eval"N,M,K="+`tr ' ' ,`
f=t=1,*(1..N).map{t=t*_1%Z=998244353}
p M*(0..K).sum{(M-1).pow(j=N+~_1,Z)*t*(N*f[j]*f[_1]).pow(Z-2,Z)}%Z

Measured memory_bytes: 34576
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long int lli;

int main(){
	lli x;
	cin >> x;
	for(lli i=-5000; i<5000; i++){
		for(lli j=-5000; j<5000; j++){
			if(i*i*i*i*i -j*j*j*j*j == x){
				cout << i << " " << j << endl;
				return 0;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define DEBUG(x)           cout << '>' << #x << ':' << x << endl;
#define forn(i,n)          for(int i=0;i<(int)n;++i)
#define for1(i,n)          for(int i=1;i<=(int)n;++i)
#define forr(i,n)          for(int i=(int)n-1;i>=0;--i)
#define forre(i,a,b)       for(int i=(int)b;i>=(int)a;--i)
#define fore(i,a,b)        for(int i=(int)a;i<=(int)b;++i)
#define input(arr,n)       for(int i=0;i<n;i++)cin>>arr[i]
#define output(arr,n)      for(int i=0;i<n;i++)cout<<arr[i]<<" "
#define for_each(arr)      for(auto& it:arr)cout<<it<<" "
#define ff                 first
#define ss                 second
#define PI                 acos(-1.0)
#define all(a)             a.begin(),a.end()
#define rall(a)            a.rbegin(),a.rend()
#define Unique(a)          sort(all(a)),a.erase(unique(all(a)),a.end())
#define pb(x)              push_back(x)
#define eb(x)              emplace_back(x) 
#define ppb(x)             pop_back(x)
#define pf(x)              push_front(x)
#define ppf(x)             pop_front(x)
#define in(x,y)            insert({x,y})
#define Sort(a)            sort(a.begin(),a.end())
#define mem(arr,a)         memset(arr,a,sizeof arr)
#define ins(a)             insert(a)
#define max2(a,b)          max(a,b)
#define max3(a,b,c)        max(a,max(b,c))
#define max4(a,b,c,d)      max(a,max3(b,c,d))
#define min2(a,b)          min(a,b)
#define min3(a,b,c)        min(a,min(b,c))
#define min4(a,b,c,d)      min(a,min3(b,c,d))
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<char> vc;
typedef vector<double> vd;
/*inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void Set(int & n, int b) { n |= two(b); }
inline void Reset(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }*/
/*int fx1[]={+1,-1,+0,+0};
int fy1[]={+0,+0,+1,-1};
int fx2={+0,+0,+1,-1,-1,+1,-1,+1};
int fy2={-1,+1,+0,+0,+1,+1,-1,-1};
*/

ll a,b,c,n,ans,cn1,cn2,cn3,t;
string s,s1,s2;


int main()
{
    FIO;
   // #ifndef ONLINE_JUDGE
   // freopen("input.txt","r",stdin);
   // freopen("output.txt","w",stdout);
   // #endif
    cin>>s1>>s2;
    cin>>a>>b;
    cin>>s;
    if(s==s1){
    	cout<<--a<<" "<<b<<endl;
    }else if(s==s2){
    	cout<<a<<" "<<--b<<endl;
    }
    

    
   	
    #ifdef ONLINE_JUDGE
    cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<<"s.\n";
    #endif
   return 0;
}
 


Measured memory_bytes: 256
import sys
import re
import math
import collections
import decimal
import bisect
import itertools
import fractions
import functools
import copy
import heapq
import decimal
import statistics

sys.setrecursionlimit(10000001)
INF = sys.maxsize
MOD = 10 ** 9 + 7

ni = lambda: int(sys.stdin.readline())
ns = lambda: map(int, sys.stdin.readline().split())
na = lambda: list(map(int, sys.stdin.readline().split()))


# ===CODE===
def main():
    n = ni()
    a = na()

    ave = sum(a) / n
    r = decimal.Decimal(str(ave)).quantize(decimal.Decimal("0"), rounding=decimal.ROUND_HALF_UP)
    ave = int(r)

    ans = 0
    for ai in a:
        ans += (ai - ave) ** 2

    print(int(ans))


if __name__ == '__main__':
    main()


Measured memory_bytes: 11108
N = int(input())
mod = int(1e+9)+7

answer = pow(10, N, mod)

notzero = pow(9, N, mod)
notq = pow(9, N, mod)

notzero_notq = pow(8, N, mod)

print((answer - notzero -notq +notzero_notq)%mod)

Measured memory_bytes: 61680
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

int check(int mid,int K,vector<int> &L) {

  int cnt = 0;
  for(int i = 0;i < L.size();i++) {
    double num = (double)L[i]/mid;
    if(mid <= L[i]) cnt += ceil(num) - 1;
  }

  if(cnt <= K) return 1;
  return 0;
}

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

  vector<int> L(N);
  for(int i = 0;i < N;i++) cin >> L[i];

  int ng = 0,ok = 1e9+1;
  while(abs(ok-ng) > 1) {
    int mid = (ok+ng)/2;
    if(check(mid,K,L)) {
      ok = mid;
    }else {
      ng = mid;
    }
  }

  cout << ok << endl;
  

}


Measured memory_bytes: 4060
N, W = map(int, input().split())

V = {}
V[0] = 0
for i in range(N):
  w, v = map(int, input().strip().split())
  keys = sorted(list(V.keys()), reverse=True)
  for vk in keys:
    if (vk + v) in V:
      V[vk + v] = min(V[vk + v], V[vk] + w)
    else:
      V[vk + v] = V[vk] + w

v_max = 0
for vk in V.keys():
  if ((V[vk] <= W) and (vk > v_max)):
    v_max = vk

print(v_max)


Measured memory_bytes: 12176
#include <stdio.h>
#include <stdlib.h>

int CountSort=0;

void swap(int *a,int *b){
  int tmp=*a;
  *a=*b; *b=tmp;
  CountSort++;
}

void BubbleSort(int a[],int num){
  int i,j;
  for(i=0;i<num;i++){
    for(j=num-1;j>i;j--){
      if(a[j]<a[j-1])swap(&a[j],&a[j-1]);
    }
  }
}

int main(void){
  int num,i;
  scanf("%d",&num);
  int array[200000];

  for(i=0;i<num;i++){
    scanf("%d",&array[i]);
  }

  BubbleSort(array,num);

  for(i=0;i<num-1;i++)printf("%d ",array[i]);
  printf("%d\n%d\n",array[i],CountSort);


  return 0;
}

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

struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

struct node *  nil;

struct node * listSearch(int key);
void init();
void printList();
void deleteNode(struct node * t);
void deleteFirst();
void deleteLast();
void delete(int key);
void insert(int key);

int main(){
  int key, n, i;
  int size = 0;
  char a[20];
  int np = 0, nd = 0;
  scanf("%d", &n);
  init();
  for ( i = 0; i < n; i++ ){
    scanf("%s%d", a, &key);
    if(!(0 <= key && key <= 2000000000)){printf("error");}
    if (a[0] == 'i' ){
      insert(key);
      np++;
      size++;
    }
    else if (a[0] == 'd' ){
      if (strlen(a) > 6){
	if (a[6] == 'F' ) deleteFirst();
	else if (a[6] == 'L' ) deleteLast();
      } else {
	delete(key);
	nd++; 
      }
      size--;
    }
    if ( size > 1000000 ){
      printf("error");
    }
  }

  
  if(!( np+nd <= 2000000)){printf("error") ;}
  if(!( nd <= 20)){printf("error") ;}
  printList();


  return 0;
}

struct node * listSearch(int key){
  struct node * cur = nil->next;
  while( cur != nil && cur->key != key ){
    cur = cur->next;
  }
  return cur;
}

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  struct node * cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(struct node * t){
  t->prev->next = t->next;
  t->next->prev = t->prev;
}

void deleteFirst(){
  struct node * t = nil->next;
  if ( t == nil ) return;
  deleteNode(t);
}

void deleteLast(){
  struct node * t = nil->prev;
  if ( t == nil ) return;
  deleteNode(t);
}

void delete(int key){
  struct node * t = listSearch(key);
  if ( t == nil ) return;
  deleteNode(t);
}


void insert(int key){
  struct node * x;
  x = malloc(sizeof(struct node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}



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

using namespace std;

int in(){ int a; cin >> a; return a; }
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

int main(){
  ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(0); cerr.tie(0);
  int n = in();
  if(n % 1000 == 0){
    cout << 0 << endl;
    return 0;
  }
  int a = (n / 1000 + 1) * 1000;
  cout << a - n << endl;
  return 0;
}



Measured memory_bytes: 3644
#include<bits/stdc++.h>
#include<unordered_map>
#include<algorithm>

/*
*▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
*    ▀▀       ▀▀▀▀▀▀    ▀     ▀▀▀▀▀▀      ▀    ▀
*   ▀  ▀      ▀         ▀     ▀            ▀  ▀
*  ▀    ▀     ▀ ▀ ▀     ▀     ▀ ▀ ▀         ▀
* ▀ ▀▀▀▀ ▀    ▀         ▀     ▀             ▀
*▀        ▀   ▀         ▀     ▀             ▀
*▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
*/
using namespace std;
void afify()
{
	ios::sync_with_stdio(0);
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
}
//===============================================
#define ll long
#define ld long double
#define mk make_pair
#define loop(i,intial,n)  for(int i=(intial);i<n;i++)
#define loopn(j,n,ends) for(int j=int(n-1);j>=ends;j--)
#define loopm(name)  for(auto it : name)
#define loopm2(name)  for(auto it2 : name)
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define all(v) v.begin(),v.end()
#define PI (ld)(3.14159265358979323846)
//===============================================
#define SF(a) scanf("%d",&a)
#define SF2(a,b) scanf("%d %d",&a,&b)
#define SFLL(a) scanf("%lld",&a)
#define SFLL2(a,b) scanf("%lld %lld",&a,&b)
#define PF(a) printf("%d\n",a)
#define PFLL(a) printf("%lld\n",a)
//===============================================
typedef vector <int> vi;
typedef vector <ll> vll;
typedef vector <ld> vld;
typedef vector <vi> vvi;
typedef vector <vll> vvll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<vpii> vvpii;
typedef stringstream ss;
const double EPS = 1e-4;
const ll oo = (ll) 10e7 + 7;
const ll N = 100018; 
const ll mod = 1073741824;
int dx[] = { 0, 0, -1, 1 };
int dy[] = { 1, -1, 0, 0 }; // 4 Direction*/
//int dx[]={1,1,0,-1,-1,-1,0,1};
//int dy[]={0,1,1,1,0,-1,-1,-1};//8 direction*/
//freopen("largest.in", "r", stdin);
//freopen("output.txt", "w", stdout);
//ifstream ifs("input.txt");
//ofstream ofs("output.txt");


int main()
{
	afify();
	string s;
	cin >> s;
	if (s[0] == s.back())cout << "Yes";
	else cout << "No";
	return 0;
}

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

using namespace std;

int main() {
  int H, W;
  cin >> H >> W;

  vector<vector<char> > a(H, vector<char>(W));
  for (int i = 0; i < H; i++) {
    for (int j = 0; j < W; j++) {
      cin >> a.at(i).at(j);
    }
  }
  
  for (int i = -1; i <= H; i++) {
    for (int j = -1; j <= W; j++) {
      if(i == -1 || i == H || j == -1 || j == W) {
        cout << "#";
      } else {
        cout << a.at(i).at(j);
      }
    }
    cout << endl;
  }
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>

int gcd(int m, int n) {
  while (n) std::swap(m%=n, n);
  return m;
}

int main() {
  int W, H, C;
  scanf("%d %d %d", &W, &H, &C);
  int g=gcd(W, H);
  printf("%d\n", W/g*H/g*C);
}



Measured memory_bytes: 2740
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <ctime>
 
using namespace std;
 
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
 
long gcd(long a, long b){
	if (a%b==0){
		return b;
	}
	else{
		return gcd(b,a%b);
	}
}
 
long lcm(long a, long b){
	return (a*b) / gcd(a,b);
}
 
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a < b) { a = b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a > b) { a = b; return 1; } return 0; }
 
typedef long long ll;
 
const ll INF = 1ll<<60;
const ll MOD = 1000000007;
const double EPS = 1e-10;

int main(){
	int a, b, x;
	
	cin >> a >> b >> x;
	
	if (x >= a && x-a <= b) cout << "YES" << endl;
	else cout << "NO" << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;

int main(){
  int a,b;
  cin >> a >> b;
  string aa,bb;
  aa = to_string(a);
  bb = to_string(b);
  string n = aa+bb;
  int num = stoi(n);
  for(int i=0;i<1000;i++){
    if(i*i==num){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
#include<iomanip>
#include<math.h>
#include<vector>
#include<cctype>
#include<string>
#include<map>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
std::string line;

int main(){
    int n,m;
    string s[110];
    string t[110];
    map <string,int> mps;
    map <string,int> mpt;

    cin >> n ;
    rep(i,n) {
        cin >> s[i] ;
        mps[s[i]]++;
    }
    cin >> m;
    rep(i,m) {
        cin >> t[i];
        mpt[t[i]]--;
    }


    int ans = 0;
    rep(i,n){
    int score = 0;
    bool flg=0;
        rep(j,m){
        if(s[i]==t[j]) {
            score = mps[s[i]] + mpt[t[j]];
            flg = 1;
        }
                }
        if(flg == 0) score = mps[s[i]];
        ans = max(ans,score);

    }

    cout << ans << endl;    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
//using namespace __gnu_pbds;
typedef long long ll;
typedef pair<int, int> pi;
typedef vector<int> vi;
template <class Key, class Compare = less<Key>>
using Tree = __gnu_pbds::tree<Key, __gnu_pbds::null_type, Compare, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>;





void Main() {
  int n, k;
  cin >> n >> k;
  vi h(n), dp(n);
  for (int i = 0; i < n; ++i) {
    cin >> h[i];
  }
  dp[0] = 0;
  for (int i = 1; i < n; ++i) {
    int mini = 1e9;
    for (int j = max(0, i-k); j < i; ++j) {
      mini = min(mini, dp[j] + abs(h[i] - h[j]));
    }
    dp[i] = mini;
  }
  cout << dp[n-1] << '\n';
}


int main() {
  ios::sync_with_stdio(false);
//  cin.tie(nullptr);
  #ifdef _DEBUG
//  freopen("in.txt", "r", stdin);
//  freopen("out.txt", "w", stdout);
  #endif
  Main();
  return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int64_t INF = 1LL << 60;
  int N,K;
  cin >> N >> K;
  vector<int> h(N);
  for (int i=0; i<N; i++) cin >> h.at(i);
  vector<int> c(K);
  for (int i=0; i<K; i++) c.at(i) = i + 1;
  
  vector<int64_t> dp(N, INF);
  dp.at(0) = 0;

  for (int i=1; i<N; i++) {
    for (int j=0; j<K; j++) {
      if (i - c.at(j) >= 0 )
        dp.at(i) = min(dp.at(i), dp.at(i - c.at(j)) + abs( h.at(i) - h.at(i - c.at(j)) ));
    }
  }

  cout << dp.at(N-1) << endl;
  
  return 0;
}

Measured memory_bytes: 1408
#include <stdio.h>
int main() {
    char s[5];
    int n = 0;
    scanf("%s", s);
    for (int i = 0; i < 4; i++) {
        if (s[i] == '+')
            n++;
        else
            n--;
    }
    printf("%d\n", n);
    return 0;
}


Measured memory_bytes: 128
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {
		FS reader = new FS();
		String X = reader.next();
		int len = 0;
		int stock = 0;
		for (int i=0; i<X.length(); i++) {
			if (X.charAt(i) == 'S') {
				stock++;
			} else {
				if (stock == 0) {
					len++;
				} else {
					stock--;
				}
			}
		}
		System.out.println(len * 2);
	}

	public static void solver() {
	}

	// Read Class
	static class FS {
		private final InputStream in = System.in;
		private final byte[] buffer = new byte[1024];
		private int ptr = 0;
		private int buflen = 0;
		private boolean hasNextByte() {
			if (ptr < buflen) {
				return true;
			} else {
				ptr = 0;
				try {
					buflen = in.read(buffer);
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (buflen <= 0) {
					return false;
				}
			}
			return true;
		}

		private int readByte() { return hasNextByte() ? buffer[ptr++] : -1;}
		private boolean isPrintableChar(int c) {return 33 <= c && c <= 126;}
		private void skipUnprintable() {while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}

		public boolean hasNext() { skipUnprintable(); return hasNextByte();}
		public String next() {
			if (!hasNext()) throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while(isPrintableChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}
		public int nextInt() {
			return (int)nextLong();
		}
		public long nextLong() {
			if (!hasNext()) throw new NoSuchElementException();
			long n = 0;
			boolean minus = false;
			int b = readByte();
			if (b == '-') {
				minus = true;
				b = readByte();
			}
			if (b < '0' || '9' < b) {
				throw new NumberFormatException();
			}
			while(true) {
				if ('0' <= b && b <= '9') {
					n *= 10;
					n += b - '0';
				} else if(b == -1 || !isPrintableChar(b)) {
					return minus ? -n : n;
				} else {
					throw new NumberFormatException();
				}
				b = readByte();
			}
		}
	}
}

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

using namespace std;

typedef long long BigInt;
int main() {
  double n;
  while (true) {
    cin >> n;
    if (n < 0) {
      return 0;
    }
    if ((n * 16) - BigInt(n * 16) == 0 and n < (1 << 8)) {
      for (int i = 0; i < 8; ++i) {
        cout << ((BigInt(n) & (1 << (7 - i))) > 0? 1: 0);
      }
      cout << ".";
      for (int i = 0; i < 4; ++i) {
        cout << ((BigInt(n * (2 << i)) & 1) > 0? 1: 0);
      }
      cout << endl;
    } else {
      cout << "NA" << endl;
    }
  }
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main(){
	int n,d;
	cin >> n >> d;
	int x[n][d];
	REP(i,n)
		REP(j,d)
			cin >> x[i][j];
	int cnt = 0;
	REP(i,n){
		REP(j,n){
			if(i != j){
				int num = 0;
				REP(k,d){
					num += abs(x[i][k] - x[j][k]) * abs(x[i][k] - x[j][k]);
				}
				int judge = 0;
				while(judge * judge < num) judge++;
				if(num == judge * judge){
					cnt++;
				}
			}
		}
	}
	cout << cnt  / 2 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int a=0,b=0,c=0,d=0;
  string s;
  while(n--)
  {
    cin>>s;
    if(s=="AC")
      a++;
    else if(s=="WA")
      b++;
   else if(s=="TLE")
     c++;
    else
      d++;
    
  }
   cout<<"AC x "<<a<<endl;
   cout<<"WA x "<<b<<endl;
   cout<<"TLE x "<<c<<endl;
   cout<<"RE x "<<d<<endl;
}


Measured memory_bytes: 3624
#include "bits/stdc++.h"

using namespace std;

#define ll long long

int main() {
	string s;
	int i;
	int n;
	int t = 1;
	int sum = 0;
	int chk[2019] = { 0 };
	int ans = 0;
	cin >> s;

	chk[0] = 1;
	n = s.size();
	for (i = n - 1; i >= 0; i--) {
		sum += (s[i] - '0')*t;
		sum %= 2019;
		ans += chk[sum];
		chk[sum]++;
		t = t * 10 % 2019;
	}

	cout << ans;
	return 0;
}

Measured memory_bytes: 3764
n = input()
A = [int(i) for i in input().split(' ')]

def trace(A):
    for index, v in enumerate(A):
        print(v, end='')
        if index != len(A) - 1:
            print(' ', end='')
    print()

trace(A)
# algorithm
# for i in range(1, len(A)):
#     v = A[i]
#     j = i - 1
#     while j >= 0 and A[j] > v:
#         A[j+1] = A[j]
#         j -= 1
#     A[j+1] = v
#     trace(A)

for index, value in enumerate(A):
    if index == 0:
        continue

    prev_idx = index - 1
    while prev_idx >= 0 and A[prev_idx] > value:
        A[prev_idx + 1] = A[prev_idx]
        prev_idx -= 1
    A[prev_idx + 1] = value
    trace(A)

Measured memory_bytes: 8452
#include<iostream>
#include <cstdio>
#include<cstring>
#include<string>
#include <cstdlib>  
#include<cmath>   
#include <cctype>
#include<string>
#include<set>
#include <iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<list>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility>
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(ll i=0;i<n;i++)
#define For(i,m,n) for(int i=m;i<n;i++)
#define FOR(i,m,n) for(ll i=m;i<n;i++)
using namespace std;
using ll = long long;

//cout << fixed << setprecision(10);
int searchint(string s, int suuji, int k, int n) {
	int t = 0;
	for (int i = k;i < n;i++) {
		if (s[i] - '0' == suuji) {
			t = 1;
			return i;
		}

	}if (t == 0)return -1;

}

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

	int fir[10], sec[10], thi[10];
	int ans=0;

	for (int j1 = 0;j1 < 10;j1++) {

		fir[j1] = searchint(s, j1, 0, n);
		sec[j1] = fir[j1];
		thi[j1] = fir[j1];
	}
	int seca, thia;

	for (int j1 = 0;j1 < 10;j1++) {
		if (fir[j1] == -1)continue;
		else {
			for (int j2 = 0; j2 < 10;j2++) {
				if (sec[j1] == -1)continue;
				else if (sec[j2] > fir[j1]) {
					for (int j3 = 0; j3 < 10;j3++) {
						if (thi[j3] == -1)continue;
						else if (thi[j3] > sec[j2]) { ans++; }
						else {
							thia = searchint(s, j3, sec[j2] + 1, n);
							if (thia == -1)continue;
							else { ans++; }
						}
					}
				}
				else {
					seca = searchint(s, j2, fir[j1] + 1, n);
					if (seca == -1)continue;
					else {
						for (int j3 = 0; j3 < 10;j3++) {
							if (thi[j3] == -1)continue;
							else if (thi[j3] > seca) { ans++; }
							else {
								thia = searchint(s, j3, seca + 1, n);
								if (thia == -1)continue;
								else { ans++; }
							}
						}
					}
				}
			}
		}
	}

	
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
int main(void){
    // Your code here!
    int i,d[6],b;
    char a[101];
    
    for(i=0;i<6;i++){
        scanf("%d", &d[i]);
    }
    
    scanf("%s",a);
    
    for(i=0;a[i]!='\0';i++){

            if(a[i]=='S'){
                b=d[0];
                d[0]=d[4];
                d[4]=d[5];
                d[5]=d[1];
                d[1]=b;
            }
            if(a[i]=='E'){
                b=d[0];
                d[0]=d[3];
                d[3]=d[5];
                d[5]=d[2];
                d[2]=b;
            }
            if(a[i]=='W'){
                b=d[0];
                d[0]=d[2];
                d[2]=d[5];
                d[5]=d[3];
                d[3]=b;
            }
            if(a[i]=='N'){
                b=d[0];
                d[0]=d[1];
                d[1]=d[5];
                d[5]=d[4];
                d[4]=b;
            }
    }
    printf("%d\n", d[0]);
    
    return 0;
}



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

#define ll long long int

int main()
{
    string s;
    ll sum=0;
    cin>>s;
    for(ll i=0;i<s.size();i++)
        sum+=s[i]-'0';
    if(sum%9==0)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}


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

int main() {
    int n;
    cin >> n;
    vector<int> vec(n);
    for(int i = 0; i < n; i++){
        cin >> vec.at(i);
    }
    sort(vec.begin(), vec.end());
    cout << vec.at(n/2) - vec.at(n/2-1) << endl;
}


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

int main(){

  int a,b,c,d;
  cin >> a>>b>>c>>d;
  if (a*b>c*d) {
    cout << a*b << endl;
  } else {
    cout << c*d << endl;
  }


}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fu(a,b) for(int i=a;i<b;i++)
#define fv(a,b) for(int j=a;j<b;j++)
using namespace std;

int main()
{
	int n;
	cin>>n;
	
	int p[3];
	int a[3];
	int np[3];
	fu(0,3)
	p[i]=0,np[i]=0;
	fu(1,n+1)
	{
		fv(0,3)
		cin>>a[j];
			fv(0,3)
			{
				for(int k=0;k<3;k++)
				{
					if(j!=k)
					{
						np[k]=max(np[k],p[j]+a[k]);
					}
				}
			}
			fv(0,3)
			{
				p[j]=np[j];
			}
	}
	cout<<max({p[0],p[1],p[2]});
}

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

int main()
{

    int n, m, ar[1001];
    float ans = 0,res = 0;

    cin >> n >> ar[0];
    ans = ar[0];
    for(int i = 1; i < n; i++) {
        cin >> ar[i];
        ans = __gcd(ar[i-1], ar[i]);
    }
    for(int i = 0; i < n; i++) {
        res += ans/ar[i];
    }
    printf("%.7f\n",1/(res/ans));
    //cout << 1/(res/ans) << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

main() {
  int n, i, j;
  int v[100];
  int matrix[100][100];
  for(i = 0; i < 100; i++) {
    for(j = 0; j < 100; j++) {
      matrix[i][j] = 0;
    }
  }
  scanf("%d", &n);
  
  for(i = 0; i < n; i++) {
    scanf("%d %d", &v[0], &v[1]);
    for(j = 2; j < v[1] + 2; j++) {
      scanf("%d", &v[j]);
      matrix[i][v[j] - 1] = 1;
    }
  }
  
  for(i = 0; i < n; i++) {
    for(j = 0; j < n; j++) {
      if(j == n - 1) {
	printf("%d\n", matrix[i][j]);
      }
      else {
	printf("%d ", matrix[i][j]);   
      }
    }
  }
  return 0;
}

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

const int size = 2e5 + 1;

int main() {
    ll N, K;
    cin >> N >> K;
    vector<int> A(N);
    rep(i, N) cin >> A[i];

    pair<int, int> g[N];
    vector<int> id(size, -1);
    rep(i, 2 * N) {
        int a = A[i % N];
        if (id[a] == -1)
            id[a] = i;
        else {
            g[id[a] % N] = {i % N, (id[a] < N && N <= i)};
            id[a] = i;
        }
    }
    int l = 0, v = 0;
    while (true) {
        l += g[v].second;
        v = g[v].first + 1;
        if (v == N) break;
    }
    
    K %= l + 1;
    l = v = 0;
    if (K == 0) return 0;
    while (true) {
        if (l == K - 1) break;
        l += g[v].second;
        v = g[v].first + 1;
    }

    deque<int> dq;
    while (v < N) {
        if (v < g[v].first)
            v = g[v].first + 1;
        else {
            dq.push_back(A[v]);
            v++;
        }
    }
    while (!dq.empty()) {
        cout << dq.front() << " ";
        dq.pop_front();
    }
    cout << endl;
}


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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set
#define l_l pair<ll, ll>
#define vll vector<ll>
#define mll map<ll, ll>

using namespace std;

const ll MOD = 1000000007LL;
const ll INF = (1LL << 60LL);

int main() {
  // std::cout << std::fixed << std::setprecision(10);
  ll N, X, M;
  scanf("%lld %lld %lld", &N, &X, &M);

  ll x = X;

  mll m;

  vll list;
  list.emplace_back(-1);

  ll i = 1;
  ll start;
  ll cycle;
  for (;;) {
    list.emplace_back(x);
    if (m[x]) {
      start = m[x];
      cycle = i - m[x];
      break;
    }
    m[x] = i;

    x = x * x % M;
    i++;
  }

  ll sum = 0;
  x = X;

  for (ll i = 1; i <= cycle; i++) {
    sum += list[i + start];
  }

  ll ans = 0;
  ll n = N;
  for (int i = 1; i < start; i++) {
    n -= 1;
    ans += list[i];
    if (n <= 0) {
      break;
    }
  }

  ll loops = n / cycle;
  ans += (sum * loops);

  n = n % cycle;

  if (n > 0) {
    for (int i = start;; i++) {
      n -= 1;
      ans += list[i];
      if (n <= 0) {
        break;
      }
    }
  }

  cout << (ans) << endl;
}


Measured memory_bytes: 5704
N=int(input())
W=list(map(int,input().split()))
x=len(W)
a=[]
tmp1=[]
tmp2=[]

for i in range(N):
    p=len(W)-2
    tmp1=sum(W[i:])
    tmp2=sum(W[:i])
    a.append(abs(tmp1-tmp2))
print(min(a))


Measured memory_bytes: 3060
#include <cstdio>
#include <algorithm>

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

using namespace std;

const int inf = ((long long)1 << 31) - 1;

int n, q;
int t[(1 << 18) - 1];

void init(){
	int m = 1;
	while(m < n){
		m *= 2;
	}
	n = m;
	fill_n(t, 2 * n - 1, inf);
}

int find(int a, int b, int l, int r, int k){
	if(b <= l || r <= a){
		return inf;
	}
	if(a <= l && r <= b){
		return t[k];
	}
	int p = find(a, b, l, (l + r) / 2, k * 2 + 1);
	int q = find(a, b, (l + r) / 2, r, k * 2 + 2);
	return min(p, q);
}

void update(int i, int x){
	i += n - 1;
	t[i] = x;
	while(i > 0){
		i = (i - 1) / 2;
		t[i] = min(t[i * 2 + 1], t[i * 2 + 2]);
	}
}

int main(){
	scanf("%d%d", &n, &q);
	init();
	rep(i, q){
		int a, b, c;
		scanf("%d%d%d", &a, &b, &c);
		if(a == 0){
			update(b, c);
		}
		else{
			printf("%d\n", find(b, c + 1, 0, n, 0));
		}
	}
	return 0;
}

Measured memory_bytes: 2052
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int main(){
	long long int n,ans=1;
	cin>>n;
	for(int i=1;i<=n;i++){
		ans=(ans*i)%(10*10*10*10*10*10*10*10*10+7);
		
	}
		cout<<ans<<endl;

}

Measured memory_bytes: 256
N = int(input())

def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr
  
if N <= 1:
  print(0)
else:
  factN = factorization(N)
  counter = 0
  for i in range(len(factN)):
    t = factN[i][1]
    e = 0
    while True:
      t -= e
      if t < 0:
        counter += e - 1
        break
      e += 1
  print(counter)

Measured memory_bytes: 63272
import java.util.*;
import java.io.*;
import java.math.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int[] nums = new int[n];
    int[] dp = new int[n];
    for (int i = 0; i < n; i++) {
      nums[i] = sc.nextInt();
    }
    Arrays.fill(dp, 1000000);
    dp[0] = 0;
    for (int i = 1; i < n; i++) {
      dp[i] = dp[i - 1] + Math.abs(nums[i] - nums[i - 1]);
      if (i > 1) {
        dp[i] = Math.min(dp[i], dp[i - 2] + Math.abs(nums[i] - nums[i - 2]));
      }
    }
    System.out.println(dp[n - 1]);
  }
}

Measured memory_bytes: 52268
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define rrep(i,n) for(int i=n-1;i>=0;--i)
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<typename T> inline bool chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
template<typename T> inline bool chmin(T &a,T b){if(b<a){a=b;return 1;}return 0;}
template<typename T> vector<T> make_vec(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_vec(size_t a,Ts... ts){return vector<decltype(make_vec<T>(ts...))>(a,make_vec<T>(ts...));}
template<typename T,typename U,typename... V>
typename enable_if<is_same<T,U>::value>::type fill_v(U &u,const V... v){u=U(v...);}
template<typename T,typename U,typename... V>
typename enable_if<!is_same<T,U>::value>::type fill_v(U &u,const V... v){for(auto &e:u)fill_v<T>(e,v...);}

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

    string s;
    cin >> s;
    if (s.substr(0, 4) == "YAKI") puts("Yes");
    else puts("No");
}


Measured memory_bytes: 3644