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

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef pair<int, ii> iii;
typedef pair<ii, int> ri3;
#define mp make_pair
#define pb push_back
#define fi first
#define sc second
#define SZ(x) (int)(x).size()
#define ALL(x) begin(x), end(x) 
#define REP(i, n) for (int i = 0; i < n; ++i) 
#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define RFOR(i, a, b) for (int i = a; i >= b; --i)

const int mod = 1e9+7;

struct Matrix : vector<vector<int> > {
    int n;

    Matrix(int _n) {
        n = _n;
        resize(n);
        FOR(i,0,n-1) {
            at(i).assign(n, 0);
        }
        FOR(i,0,n-1) at(i).at(i) = 1;   // identity
    }

    Matrix mul(Matrix b) {
        Matrix c = Matrix(n);
        FOR(i,0,n-1){
            FOR(j,0,n-1){
                c[i][j] = 0;
                FOR(k,0,n-1){
                    c[i][j] += (int) (((ll)at(i).at(k) * b[k][j]) % mod);
                    c[i][j] %= mod;
                }
            }
        }
        return c;
    }
};

int n; ll k;

Matrix expo(Matrix a, ll p) {
    if (p == 0) return Matrix(n);
    if (p == 1) return a;

    Matrix b = expo(a, p/2);
    b = b.mul(b);
    if (p&1) b = b.mul(a);
    return b;
}


int main() {
    //freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin >> n >> k;
    Matrix a(n);
    FOR(i,0,n-1) FOR(j,0,n-1){
        cin >> a[i][j];
    }

    Matrix b = expo(a, k);
    int sum = 0;
    FOR(i,0,n-1) FOR(j,0,n-1) {
        sum = (sum + b[i][j]) % mod;
    }
    cout << sum << '\n';
}



Measured memory_bytes: 1024
#include <iostream>

using namespace std;


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

    if(a < b){
        if(b < c){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }else{
        cout << "No" << endl;
    }

    return 0;
}




Measured memory_bytes: 3084
#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);}
  double kouho=0;
  for(int i=0;i<n;i++){
  kouho+=vec.at(i);}
  kouho/=n;
  double thumb=10005;
    int ans=-1;
  for(int i=0;i<n;i++){
    if(abs(kouho-vec.at(i))<thumb){
    thumb=abs(kouho-vec.at(i));
    ans=i;}
  }
  cout << ans <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
const long long int sMod = 998244353;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
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; }
///////////////////////////////////////////////////////////////////////////////////

void solve(){
    string s;
    cin >> s;
    int n=s.size();
    if(s[n-1]=='s'){
        print(s+"es");
    }else{
        print(s+'s');
    }
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

Measured memory_bytes: 3660
#include <iostream>
using namespace std;
int main(){
  int n;cin>>n;
  int all = 1;
  int kis = 1;
  for(int i = 0; n > i; i++){
    int z;cin>>z;
    all *= 3;
    kis *= (z%2==0?2:1);
  }
  cout << all-kis << endl;
}
    

Measured memory_bytes: 256
N = int(input())
h = list(map(int,input().split()))

dp = [float("INF")]*N
dp[0] = 0
dp[1] = abs(h[1] - h[0])

for i in range(2, N):
  c1 = dp[i-1] + abs(h[i] - h[i-1])
  c2 = dp[i-2] + abs(h[i] - h[i-2])      
  dp[i] = min(c1, c2)

print(dp[N-1])

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

int main(){
  int n;
  cin>>n;
  int a[n];
  int b[10][1000]={};
  for(int i=0;i<n;i++){
  cin>>a[i];
  int k=a[i];
  for(int m=2;m<=k;){
    if(k==1){break;}
    if(k%m==0){k=k/m; b[i][m]+=1; continue;}
    m++;
  }}

  for(int g=2;g<=1000;g++){
      for(int m=1;m<n;m++){
	if(b[0][g]<b[m][g]){b[0][g]=b[m][g];}
      }}
  
  //for(int i=0;i<1000;i++){
  //if(b[0][i]==0){continue;}
  //cout<<i<<"*"<<b[0][i]<<" ";
  //}

  long long ans=1;
  for(int h=0;h<1000;h++){
    ans=ans*pow(h,b[0][h]);
      }

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



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

int main()
{
    int n, ans;
    cin >> n;
    ans = n + n * n + n * n * n;

    cout << ans << endl;

    return 0;
}

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

using namespace std;

int main()
{
    ///{}
    ios_base::sync_with_stdio(0);
    cin.tie(0);  cout.tie(0);
    long long k;
    cin>>k;
    vector<long long>v(50ll,49ll+k/50ll);
    long long m=k%50ll;
    long long mo=0;
    for(int i=0;i<m;i++){
        v[i]+=50ll-mo-m+1ll;
        mo++;

    }
    for(int i=m;i<50;i++){
        v[i]+=-m;

    }
    cout<<50<<'\n';
    for(int i=0;i<50;i++)
        cout<<v[i]<<' ';
    return 0;
}
/**
10
0 1 1 1 1 1 1 1 1 1
1 0 1 1 1 1 1 1 1 1
1 1 0 1 1 1 1 1 1 1
1 1 1 0 1 1 1 1 1 1
1 1 1 1 0 1 1 1 1 1
1 1 1 1 1 0 1 1 1 1
1 1 1 1 1 1 0 1 1 1
1 1 1 1 1 1 1 0 1 1
1 1 1 1 1 1 1 1 0 1
1 1 1 1 1 1 1 1 1 0
*/


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

using namespace std;

const int MAXN = 400;
const int INFV = 1001001001;

int N;
char S[MAXN + 1]; int A[MAXN];
int dp[MAXN + 1][MAXN + 1][MAXN + 1][3];
int cnts[3], locs[3][MAXN], prevs[3][MAXN];

void chmin(int& x, int y)
{
    x = min(x, y);
}

int main()
{
    scanf("%d%s", &N, S);

    for (int i = 0; i < N; ++i) {
        switch (S[i]) {
            case 'R': A[i] = 0; break;
            case 'G': A[i] = 1; break;
            case 'Y': A[i] = 2; break;
        }
    }

    for (int i = 0; i < 3; ++i) cnts[i] = 0;
    for (int i = 0; i < N; ++i) {
        locs[A[i]][cnts[A[i]]++] = i;
        for (int j = 0; j < 3; ++j) prevs[j][i] = cnts[j];
    }

    for (int a = 0; a <= cnts[0]; ++a) {
        for (int b = 0; b <= cnts[1]; ++b) {
            for (int c = 0; c <= cnts[2]; ++c) {
                for (int s = 0; s < 3; ++s) {
                    dp[a][b][c][s] = INFV;
                }
            }
        }
    }

    dp[0][0][0][0] = dp[0][0][0][1] = dp[0][0][0][2] = 0;

    for (int a = 0; a <= cnts[0]; ++a) {
        for (int b = 0; b <= cnts[1]; ++b) {
            for (int c = 0; c <= cnts[2]; ++c) {
                for (int s = 0; s < 3; ++s) {
                    if (s != 0 && a < cnts[0]) {
                        int p = locs[0][a];
                        chmin(dp[a + 1][b][c][0], dp[a][b][c][s] + max(0, prevs[1][p] - b) + max(0, prevs[2][p] - c));
                    }
                    if (s != 1 && b < cnts[1]) {
                        int p = locs[1][b];
                        chmin(dp[a][b + 1][c][1], dp[a][b][c][s] + max(0, prevs[0][p] - a) + max(0, prevs[2][p] - c));
                    }
                    if (s != 2 && c < cnts[2]) {
                        int p = locs[2][c];
                        chmin(dp[a][b][c + 1][2], dp[a][b][c][s] + max(0, prevs[0][p] - a) + max(0, prevs[1][p] - b));
                    }
                }
            }
        }
    }

    int ret = min({ dp[cnts[0]][cnts[1]][cnts[2]][0], dp[cnts[0]][cnts[1]][cnts[2]][1], dp[cnts[0]][cnts[1]][cnts[2]][2] });
    if (ret >= INFV) ret = -1;
    printf("%d\n", ret);

    return 0;
}


Measured memory_bytes: 164692
#include <bits/stdc++.h>
using namespace std;
string s, t;
set<string> S;
void check(){
    int lens = s.size();
    int lent = t.size();
    for(int i = 0; i < lens; i++){
        if(s[i] == '?' || s[i] == t[0]){
            string tmp = s;
            for(int j = 0; j < i; j++) if(tmp[j] == '?') tmp[j] ='a';
            bool can = false;
            for(int j = 0; j < lent; j++){
                if(tmp[i+j]!= '?' && tmp[i+j] != t[j]) break;
                tmp[i+j] = t[j];
                if(j == lent - 1) can = true;
            }
            if(can){
                for(int j = i + lent; j < lens; j++) if(tmp[j] == '?') tmp[j] = 'a';
                S.insert(tmp);
            }
        }
    }
    if(S.size() == 0) cout << "UNRESTORABLE";
    else cout << *S.begin();
}
int main(){
    cin >> s >> t;
    check();
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline


def main():
    N = int(input())
    A = list(map(int, input().split()))
    target = 1
    ans = 0
    for a in A:
        if a == target:
            target += 1
        else:
            ans += 1
    if ans == N:
        print(-1)
        return
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 25912
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
#define ll  unsigned long long
#define ull unsigned long long
#define IO ios::sync_with_stdio(false), cin.tie(0)
#define endl '\n'
#define main() int main()
#define ff1(i,n) for(int i=1;i<=n;++i)
#define ff0(i,n) for(int i=0;i<n;++i)
#define pi acos(-1.0)
#define ms(a, x) memset(a, x, sizeof(a))
#define lowbit(x) ((x)&(-(x)))
#define pb push_back
#define binarycount __builtin_popcount(x)
#define tr t[root]
#define lson t[root << 1]
#define rson t[root << 1 | 1]
#define fir first
#define sec second
#define debug(x) cout<<x<<'\n'
#define sa(a) scanf("%d", &a)
#define sab(a, b) scanf("%d%d", &a, &b)
#define pa(a) printf("%d",a)
#define pab(a,b) printf("%d%d",a,b)
#define pii pair<int,int>
using namespace std;

#define maxn 1000005
const int inf = 0x3f3f3f3f;
const int mod = 1e9+7;
const double eps = 1e-8;
ll gcd(ll a, ll b) {return b==0?a:gcd(b, a%b);}
ll lcm(ll a, ll b) {return a/gcd(a, b)*b;}
ll powmod(ll a,ll b){
    ll ans = 1, pow = a%mod;
    while(b) { if(b&1) ans = (ans*pow)%mod; pow = (pow*pow)%mod; b >>= 1; }
    return ans;
}
bool run(int year=NULL)
{
    if ((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))
        return true;
    else
        return false;
}
struct node{
	int x,y;
}a[20000];
int n;
ll k,ans[maxn],anss=0;
main(){
	IO;
	cin>>n>>k;
	for(ll x=k;x>=1;x--){
		ll y=k/x;
		ll cap=powmod(y,n);
		for(ll i=x+x;i<=k;i+=x)
		{
			cap=(cap-ans[i]+mod)%mod;
		}
		ans[x]=cap;
		anss=(anss+cap*x)%mod;
	}
	cout<<anss<<endl;
}

Measured memory_bytes: 4376
#include <math.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;

int main(void) {
  int scan; // scanf result
  int s; // to input 
  int w; // to input 

  scan = scanf("%d", &s);
  scan = scanf("%d", &w);

  if (s <= w)
    printf("unsafe");
  else
    printf("safe");
  return (0);
}


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

#define pb push_back
#define eb emplace_back
#define mk make_pair
#define fi first
#define se second
#define mset(a, b) memset(a, b, sizeof(a))
#define DBG(x) cout << "[" << #x << "]: " << x << endl
using ll = long long;
using pii = pair<int, int>;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

template<class Ty> Ty rnd(Ty a, Ty b) { return uniform_int_distribution<Ty>(a, b)(rng); }
template<class num> inline void rd(num& x) {
	char c; while(isspace(c = getchar()));
	bool neg = false;
	if(!isdigit(c)) neg = (c == '-'), x = 0;
	else x = c - '0';
	while(isdigit(c = getchar())) x = (x << 3) + (x << 1) + c - '0';
	x = neg ? -x : x; }
template <class... Args> inline void rd(Args&... args) { (rd(args), ...); }
template <class... Args> inline void rf(Args&... args) { (cin >> ... >> args); }
template <class... Args> inline void pr(Args&&... args) { (cout << ... << args); }

const int MAXN = 2e5 + 5, INF = 0x3f3f3f3f;

int main() {
	ll a, b, h, m;
	rd(a, b, h, m);

	long double hh = h;

	hh *= 5;
	hh += 5.0 * m / 60.0;

	const long double PI = acos(-1.0);

	long double ang = abs(hh - m) * (PI / 30);
	long double ans = a*a + b*b - 2 * a * b * cos(ang);
	printf("%.15Lf\n", sqrt(ans));
}

Measured memory_bytes: 4104
#include <iostream>
#include <cstdio>
#include <algorithm>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

#define print(x) printf("%d\n",x)

int getInt(){
  int ret = 0,c;
  c = getchar();
  while(!isdigit(c)) c = getchar();
  while(isdigit(c)){
    ret *= 10;
    ret += c - '0';
    c = getchar();
  }
  return ret;
}

using namespace std;

int rp[100][100], pp[100][100];
int cnt[100][100];

int main(){
  while(int n = getInt()){
    REP(i, n) REP(j, n)
      rp[j][i] = pp[i][j] = getInt();

    REP(i, n) REP(j, n)
      cnt[i][j] = 0;

    REP(i, n){
      int minv = *min_element(pp[i], pp[i] + n);
      int maxv = *max_element(rp[i], rp[i] + n);

      REP(j, n){
	if(minv == pp[i][j]) cnt[i][j]++;
	if(maxv == rp[i][j]) cnt[j][i]++;
      }
    }

    //REP(i, n) { REP(j, n) printf("%d ", cnt[i][j]); puts(""); }

    int ans = 0;
    REP(i, n) REP(j, n) if(cnt[i][j] == 2){
      ans = pp[i][j];
    }
    print(ans);
  }
  return 0;
}

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

#define ll long long
#define endl '\n'
#define all(x) x.begin(), x.end()
#define pi acos(-1.0)

using namespace std;

int main (){
    //freopen("input.txt", "r", stdin);

    ll  n, m;
    cin>>n>>m;
    ll arr[m+5];
    ll sum = 0;
    for(int i=1; i<=m; i++){
        cin>>arr[i];
        sum += arr[i];
    }
    if(sum > n) cout<<-1<<endl;
    else{
        cout<<n-sum<<endl;
    }
    return 0;
}

Measured memory_bytes: 3668
#include <iostream>
#include <unordered_map>
#include <vector>
#include <queue>

using namespace std;

int main() {

	int N, M, ans;
	cin >> N >> M;

	unordered_map<int, vector<int>> cango;

	int u, v;//行く前、行った先

	for (int i = 0; i < M; i++) {
		cin >> u >> v;
		cango[u].push_back(v);
	}

	int s, g;

	cin >> s >> g;

	int dst[100001][3] = { 0 };

	pair<int, int> next = { s,0 };

	queue<pair<int, int>> q;
	q.push(next);

	ans = -1;

	while (!q.empty()) {
		auto cc = q.front();
		q.pop();
		for (auto i : cango[cc.first]) {
			if (i == g && (cc.second + 1) % 3 == 0) {
				dst[i][(cc.second + 1) % 3] = dst[cc.first][cc.second] + 1;
				goto loopend;
			}
			if (dst[i][(cc.second + 1) % 3] == 0) {
				dst[i][(cc.second + 1) % 3] = dst[cc.first][cc.second] + 1;
				next.first = i;
				next.second = (cc.second + 1) % 3;
				q.push(next);
			}
		}

	}

loopend:

	if (dst[g][0] != 0)ans = dst[g][0] / 3;

	cout << ans << endl;

}

Measured memory_bytes: 10276
#include <bits/stdc++.h>
using namespace std;
#define ll          long long int
#define pb          push_back
#define pll         pair<ll,ll>
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define mod         1000000007
#define inf         1000000000000000000LL
#define vl          vector<ll>
#define F           first
#define S           second
#define db          long double
#define sz(x)       (ll)x.size()
#define fix(n)      cout<<fixed<<setprecision(n)
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define all(x)      x.begin(),x.end()
#define pi          3.14159265358979323

ll n;
ll ps[10], pn[10];
ll moves;


void pre()
{
       ps[0]=1;
       pn[0]=1;
       for(ll i=1; i<10; i++) ps[i] = ps[i-1]*6;
       for(ll i=1; i<10; i++) pn[i] = pn[i-1]*9;
}


void brute(ll num, ll steps)
{
       if(num==0) { moves=min(moves, steps); return; }
       for(ll i=0; i<10; i++)
       {
              if(ps[i] > num)
              {
                     brute(num - ps[i-1], steps+1);
                     break;
              }
       }
       for(ll i=0; i<10; i++)
       {
              if(pn[i] > num)
              {
                     brute(num - pn[i-1], steps+1);
                     break;
              }
       }
}

void solve()
{
       cin>>n;
       moves=n;
       pre();
       brute(n, 0);
       cout<<moves<<endl;
}

int main()
{
       speed_up;
       ll T=1;
       //cin>>T;
       while(T--) solve();
	return 0;
}


Measured memory_bytes: 256
n=int(input())
sl=0
sr=0
sz=0
lr=[]
rl=[]
for i in range(n):
    s=input()
    l=0
    r=0
    z=0
    for j in s:
        if j=="(":
            l+=1
        else:
            r+=1
        z=max(z,r-l)
    sl+=l
    sr+=r
    if z==0 and l>=r:
        sz+=l-r
    elif l>=r:
        lr.append((z,l-r))
    else:
        rl.append((z,l-r))
if sl!=sr:
    print("No")
    quit()
lr.sort()
for z,i in lr:
    if sz<z:
        print("No")
        quit()
    else:
        sz+=i
rl.sort(key=lambda x:x[0]+x[1] ,reverse=True)
for z,i in rl:
    if sz<z:
        print("No")
        quit()
    else:
        sz+=i
print("Yes")

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

int main()
{
	int a,b,c;
	cin >> a >> b >>c;
	vector<int> v;
	v.push_back(a);
	v.push_back(b);
	v.push_back(c);
	sort(v.begin(), v.end());
	vector<int>::iterator vi = v.begin();
	cout << *vi;
	++vi;
	for (;vi!=v.end();++vi) {
		cout <<" "<< *vi;
	}
	cout << endl;
	
	return 0;
}



Measured memory_bytes: 3152
#include <iostream>
#include <vector>
#include <algorithm>
#define ll long long
using namespace std;
int main(){
    int k;
    cin>>k;
    if(0==k%2){
        cout<<k*k/4;
    }else{
        cout<<(k/2)*(k/2+1);
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
using namespace std;
#define REP(i, limit) for(int i=0; i< limit; ++i)
#define LINT long long

int main(){
  int N, Y;
  cin>>N>>Y;
  int x, y, z;
  int sum;

  REP(i, N+1){
    REP(j, N-i+1){
      if(i*10000 + j * 5000 + (N-i-j)*1000 == Y){
        cout << i <<" "<<j<<" "<<(N-i-j)<<endl;
        return 0;
      }
    }
  }
  cout<<"-1 -1 -1"<<endl;




  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

		int n = Integer.parseInt(sc.next());

		while (n > 0) {
			n -= 1000;
		}
		n *= -1;
		System.out.println(n);
	}

}


Measured memory_bytes: 35568
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl '\n'
int M = 1e9 + 7;
int32_t main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  int n;
  cin >> n;
  int a[n];
  for (int i = 0; i < n; ++i)
  {
    cin >> a[i];
  }
  int ans = 0;
  map<int, int> f, s;
  for (int i = 0; i < n; ++i)
  {
    int x = i - a[i];
    f[x]++;
  }
  for (int i = 0; i < n; ++i)
  {
    int x = i + a[i];
    s[x]++;
  }
  for (auto it : f)
  {
    int search = it.first;
    int val1 = it.second;
    if (s.find(search) != s.end())
    {
      ans += (val1 * s[search]);
    }
  }
  cout << ans;


}

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

# define ll long long

ll solve(ll n, ll a, ll b){
  if(a > b) return 0;
  if(n == 1) return (a==b);
  ll low = b + (n-1)*a;
  ll upr = a + (n-1)*b;
  return upr - low + 1;
}

int main(){
  ll n,a,b;
  cin >> n >> a >> b;
  cout << solve(n,a,b) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const string ln = "\n";
constexpr int INF = 1001001001;
constexpr int MOD = 1000000007;

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

  ll n, a, b;
  cin >> n >> a >> b;

  ll m = n - 2;
  ll ans = m * b - m * a;
  if (ans < 0) {
    ans = 0;
  } else {
    ans++;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define MOD int(1e9+9)
#define PI 3.1415926535898
using namespace std;
int main(int argc, char const *argv[]) {
    ll dp[101][100001], val[101], w[101], n, W;
    cin >> n >> W;
    for(int i = 0; i < n; i++) {
        cin >> w[i] >> val[i];
    }
    for(int i = 0; i <= n; i++)dp[i][0] = 0;
    for(int i = 1; i <= n; i++) {
        for(int j = 0; j <= W; j++) {
            if(i == 0 && j == 0)dp[i][j] = 0;
            if(j < w[i - 1]) {
                dp[i][j] = dp[i - 1][j];
            } else {
                dp[i][j] = max(dp[i - 1][j],
                               val[i - 1] + dp[i - 1][j - w[i - 1]]);
            }
        }
    }
    cout << dp[n][W] << endl;
}




Measured memory_bytes: 78848
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define x first
#define y second

using namespace std;

typedef long long ll;

const ll INF = (ll) 1e18;

ll dx[8] = {-1, -1, -1, -1, 1, 1, 1, 1}, dy[8] = {-1, -1, 1, 1, -1, -1, 1, 1}, dz[8] = {-1, 1, -1, 1, -1, 1, -1, 1};
ll a[1005], b[1005], c[1005];
ll dp[1005][1005][8];

int main()
{
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
        cin >> a[i] >> b[i] >> c[i];
    for (int i = 0; i < 8; i++)
        dp[0][0][i] = 0;
    for (int i = 1; i <= n; i++)
        for (int j = 0; j < 8; j++)
            dp[0][i][j] = -INF;

    for (int i = 1; i <= n; i++)
        for (int j = 0; j <= m; j++)
            for (int z = 0; z < 8; z++)
            {
                dp[i][j][z] = dp[i - 1][j][z];
                if (j != 0 && dp[i - 1][j - 1][z] != -INF) dp[i][j][z] = max(dp[i][j][z], dp[i - 1][j - 1][z] + dx[z] * a[i] + dy[z] * b[i] + dz[z] * c[i]);
            }
    ll ans = 0;
    for (int i = 0; i < 8; i++)
        ans = max(ans, dp[n][m][i]);
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 63104
#include<bits/stdc++.h>
using namespace std;
struct _IO{_IO(){ios::sync_with_stdio(0);cin.tie(0);}}_io;

typedef long long ll;
typedef long double db;
typedef unsigned long long ull;
typedef vector<int> vi; typedef vector<vi> vii;
typedef pair<int, int> pi;
typedef tuple<int, int, int> t3;
typedef map<int, int> mi;
#define fi first
#define se second
#define vt vector
#define be begin()
#define ed end()
#define sz size()
#define cl clear()
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define lb(v, x) lower_bound(v.begin(), v.end(), x)
#define lbi(v, x) (lb(v, x) - v.begin())
#define tp(t, x, y) t x, y; tie(x, y)
#define tp3(t, x, y, z) t x, y, z; tie(x, y, z)
#define mp make_pair
#define mt make_tuple
#define co const
#define fc(x) for(int x = 1, _end = ri(); x <= _end; x++)
void uni(vi &v) { sort(v.begin(), v.end()); v.erase(unique(v.begin(), v.end()), v.end()); }

db rd() { db x; cin >> x; return x; }
ll ri() { ll x; cin >> x; return x; }
string rs() { string s; cin >> s; return s; }
pi rpi() { pi x; cin >> x.fi >> x.se; return x; }
vi rvi(int n, int f = 0) { vi v(n + f); for (int i = f; i < v.size(); i++) cin >> v[i]; return v; }
vii rvii(int n, int m, int f = 0) { vii v(n + f, vi(n + f)); for (int i = f; i < v.size(); i++) for (int j = f; j < v[0].size(); j++) cin >> v[i][j]; return v; }
void pr() {}; template <class T, class ...U> void pr(T x, U ...y) { cout << x << ' ', pr(y...); }
void prl() { cout << '\n'; }; template <class T, class ...U> void prl(T x, U ...y) { cout << x << ' ', prl(y...); }
void pr(const vi &v, int f = 0) { for (int i = f; i < v.size(); i++) cout << v[i] << ' '; }
void prl(const vi &v, int f = 0) { pr(v, f); cout << '\n'; }
void pr(const pi &x) { cout << x.fi << ' ' << x.se; };
void prl(const pi &x) { pr(x); cout << '\n'; }

#define rep(i, l, r) for (int i = l; i < r; i++)
#define per(i, l, r) for (int i = l; i >= r; i--)

const int N = 2e5 + 5, M = 1e9 + 7;

int fa[N];
int fi(int x) {
  return !fa[x] || fa[x] == x ? x : fa[x] = fi(fa[x]);
}

vi g[N];
map<int, vi> cnt;
bool vis[N];
void dfs(int u) {
  vis[u] = 1;
  cnt[fi(u)].pb(u);
  for (auto &v : g[u]) {
    if (!vis[v]) dfs(v);
  }
}

int main() {
  int n = ri(), a = ri(), b = ri();
  rep(i, 0, a) {
    int x = ri(), y = ri();
    fa[fi(x)] = fi(y);
  }
  rep(i, 0, b) {
    int u = ri(), v = ri();
    g[u].pb(v);
    g[v].pb(u);
  }
  vi ans(n + 1);
  rep(i, 1, n + 1) {
    if (!vis[i]) {
      cnt.clear();
      dfs(i);
      for (auto &p : cnt) {
        for (auto &v : p.se) {
          ans[v] = p.se.sz;
        }
      }
    }
  }
  pr(ans, 1);
}


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

#pragma region Macros
using ll = long long;
#define int ll
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
template<class T = ll> using V = vector<T>;
template<class T = ll> using VV = V<V<T>>;
#define IOS\
    ios::sync_with_stdio(false);\
    cin.tie(0);\
    cout.tie(0);
#define FOR(i,l,r) for(ll i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(ll i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define SORT(name) sort(name.begin(), name.end())
#define RSORT(name)\
    SORT(name);\
    reverse(all(name));
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
inline void Yes(bool b = true) {cout << (b ? "Yes" : "No") << '\n';}
inline void YES(bool b = true) {cout << (b ? "YES" : "NO") << '\n';}
template <class T> inline void print(T x){ cout << x << '\n';}
template<typename T1,typename T2> inline void chmin(T1 &a, T2 b){ if(a > b) a = b; }
template<typename T1,typename T2> inline void chmax(T1 &a, T2 b){ if(a < b) a = b; }

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
#pragma endregion

#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const int MOD = 1000000007;
const int MAX_N = 100010;

signed main() {
    IOS;

    int N;
    V<> L;
    cin >> N;
    L.resize(N);
    REP(i, N) {
        cin >> L[i];
    }

    int ans = 0;
    for(int i = 0; i < N; ++i) {
        for(int j = i + 1; j < N; ++j) {
            for(int k = j + 1; k < N; ++k) {
                if(L[i] != L[j] && L[j] != L[k] && L[i] != L[k] &&
                 (L[i] < L[j] + L[k]) && (L[j] < L[i] + L[k]) && (L[k] < L[i] + L[j]) ) { ans++; }
            }
        }
    }
    print(ans);

    return 0;
}


Measured memory_bytes: 3652
/* ---------- STL Libraries ---------- */

// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

/* ---------- Namespace ---------- */

using namespace std;

/* ---------- Type Abbreviation ---------- */

using ll = long long;

template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using GPQ = priority_queue<T, vector<T>, greater<T>>;

#define mp make_pair
#define mt make_tuple

/* ----------- debug ---------- */

template <class L, class R>
ostream& operator<<(ostream& os, pair<L, R> p);

template <class T>
ostream& operator<<(ostream& os, vector<T> v) {
    os << "[";
    for (auto vv : v)
        os << vv << ",";
    return os << "]";
}

template <class T>
ostream& operator<<(ostream& os, set<T> v) {
    os << "[";
    for (auto vv : v)
        os << vv << ",";
    return os << "]";
}

template <class L, class R>
ostream& operator<<(ostream& os, pair<L, R> p) {
    return os << "(" << p.first << "," << p.second << ")";
}

/* ---------- Constants ---------- */

// const ll MOD = 1000000007;
// const ll MOD = 998244353;
// const int INF = 1 << 25;
// const ll INF = 1LL << 50;
// const double PI = acos(-1);
// const double EPS = 1e-10;
// mt19937 mert(LL(time(0)));

/* ---------- Short Functions ---------- */

template <typename T>
inline T sq(T a) { return a * a; }

template <typename T>
T gcd(T a, T b) {
    if (a < b) return gcd(b, a);
    return b == 0 ? a : gcd(b, a % b);
}

template <typename T, typename U>
T mypow(T b, U n) {
    if (n == 0) return 1;
    if (n == 1) return b /* % MOD */;
    if (n % 2 == 0) {
        return mypow(b * b /* % MOD */, n / 2);
    } else {
        return mypow(b, n - 1) * b /* % MOD */;
    }
}

ll pcnt(ll b) {
    return __builtin_popcountll(b);
}

template <typename T>
T iceil(T n, T d) {
    return (n + d - 1) / d;
}

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */

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

    ll x[m];
    for (int i = 0; i < m; ++i) cin >> x[i];
    sort(x, x + m);

    ll d[m - 1];
    for (int i = 0; i < m - 1; ++i) d[i] = x[i + 1] - x[i];
    sort(d, d + m - 1);

    cout << accumulate(d, d + max(0, m - n), 0LL) << endl;
    return 0;
}


Measured memory_bytes: 1792
n = int(input())
aaa = list(map(int, input().split()))
def gcd(a,b):
  if b==0:
    return a
  return gcd(b, a%b)

ans = gcd(aaa[0], aaa[1])
if n == 2:
  print(ans)
else:
  for i in range(2,n):
    ans = gcd(ans, aaa[i])
  print(ans)
  

Measured memory_bytes: 14252
#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>

using namespace std;

int main() {
    int n;  cin >> n;
    vector<pair<long long, long long> > p;
    for (int i = 0; i < n; i++) {
        long long a, b; cin >> a >> b;
        p.push_back(pair<long long, long long>(b, a));
    }

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

    long long t = 0;

    for (int i = 0; i < n; i++) {
        long long a = p[i].second, b = p[i].first;

        if (t+a > b) {
            cout << "No" << endl;
            return 0;
        }
        else 
            t += a;
    }

    cout << "Yes" << endl;

    return 0;
}

Measured memory_bytes: 6384
while True:
    n,m = map(int,input().split())
    if n == m == 0:
        break
    score = [0 for i in range(n)]
    for i in range(m):
        hokan = list(map(int,input().split()))
        for j in range(n):
            score[j] += hokan[j]
    score.sort(reverse = True)
    print(score[0])
    
    


Measured memory_bytes: 5648
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FUNCTION__ << endl;
#define int long long

using namespace std;

signed main(){
    int  N;
    string S;
    cin >> N >> S;
    dump(N);
    dump(S);


    //close left
    int left_needed = 0;
    int depth = 0;
    for (auto c: S){
        switch (c)
        {
        case '(' :
            depth++;
            break; 
        case ')' : 
            if (depth > 0) {
                depth--;
            } else {
                left_needed++;
            }
        default:
            break;
        }
    }
    for (int i = 0; i < left_needed; i++)
    {
        cout << '(';
    }
    cout << S;
    for (int i = 0; i < depth; i++)
    {
        cout << ')';
    }
    return 0;
}


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

using namespace std;

typedef long long ll;

int main() {
  ll L, R;
  cin >> L >> R;
  R = min(R, L + 4038);
  ll res = 2018;
  for (ll i = L; i <= R; ++i) {
    for (ll j = i + 1; j <= R; ++j) {
      ll x = i * j % 2019;
      res = min(res, x);
    }
  }
  cout << res << endl;
}

Measured memory_bytes: 256
using System;

namespace ConsoleApp2
{
    public class Program
    {
        static void Main(string[] args)
        {
            int k, a, b;

            k = int.Parse(Console.ReadLine());
            var buf = Console.ReadLine().Split(' ');
            a = int.Parse(buf[0]);
            b = int.Parse(buf[1]);

            for (int i = a; i <= b; i++)
            {
                if (i % k == 0)
                {
                    Console.WriteLine("OK");
                    return;
                }
            }
            Console.WriteLine("NG");
        }
    }
}


Measured memory_bytes: 17864
#include<iostream>

int prim();

using namespace std;
static const int MAX=100;
static const int INFTY=(1<<21);
static const int WHI=0;
static const int GRA=1;
static const int BLA=2;

int n,M[MAX][MAX];

int main()
{

  cin>>n;
  
  for(int i=0;i<n;i++)
    {
      for(int j=0;j<n;j++)
	{
	  int e;
	  cin>>e;
	  M[i][j]=(e==-1)?
	    INFTY:e;
	}
    }

  cout << prim() << endl;

  return 0;
}

int prim()
{
  int u,minv;
  int d[MAX],p[MAX],color[MAX];

  for(int i=0;i<n;i++)
    {
      d[i]=INFTY;
      p[i]=-1;
      color[i]=WHI;
    }

  d[0]=0;

  while(1)
    {
      minv=INFTY;
      u=-1;
      for(int i=0;i<n;i++)
	{
	  if(minv>d[i]&&color[i]!=BLA)
	    {
	      u=i;
	      minv=d[i];
	    }
	}
      if(u==-1)
	break;

      color[u]=BLA;
      for(int v=0;v<n;v++)
	{
	  if(color[v]!=BLA&&M[u][v]!=INFTY)
	    {
	      if(d[v]>M[u][v])
		{
		  d[v]=M[u][v];
		  p[v]=u;
		  color[v]=GRA;
		}
	    }
	}
    }

  int sum=0;
  for(int i=0;i<n;i++)
    {
      if(p[i]!=-1)
	sum+=M[i][p[i]];
    }

  return sum;
}
	
    




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

int main(){
  int n,m;
  cin >> n >> m;
  int a[n][m];
  for(int i=0;i<n;++i)
    for(int j=0;j<m;++j)
      a[i][j] = 0;
  for(int i=0;i<n;++i){
    int k;
    cin >> k;
    for(int j=0;j<k;++j)
      cin >> a[i][j];
  }

  int count = 0;
  for(int f=1;f<=m+1;++f){
    int g = 0;
    for(int i=0;i<n;++i){
      for(int j=0;j<m;++j)
        if(a[i][j] == f) g++;
    }
    if(g == n) count++;
  }
  cout << count << endl;

  return 0;
}

Measured memory_bytes: 888
#include <bits/stdc++.h>
//#pragma once
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
#define int long long
#define double long double
typedef pair<double,double> P;
const ll INF = 1e18;
const int MOD = 1000000007;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 



int h, w;int a[510][510];
deque<pair<P,P>> ans;

signed main(){
  cin>>h>>w;bool p = false;
  rep(i,h)rep(j,w)cin>>a[i][j];
  rep(i,h){
    if(i%2 == 0){
      rep(j,w){
        if(i == h-1 && j == w-1)break;
        if(a[i][j]%2 == 0){
          if(p && j < w-1){
            ans.push_back(pair<P,P>(P(j,i), P(j+1, i)));
          }else if(p && j == w-1){
            ans.push_back(pair<P,P>(P(j,i), P(j, i+1)));
          }
        }else{
          if(p)p = false;
          else if(j < w-1){
            p = true;
            ans.push_back(pair<P,P>(P(j,i), P(j+1, i)));
          }else if(j == w-1){
            p = true;
            ans.push_back(pair<P,P>(P(j,i), P(j, i+1)));
          }
        }
      }
    }else{
      for(int j=w-1;j >= 0;j--){
        if(i == h-1 && j == 0)break;
        if(a[i][j]%2 == 0){
          if(p && j > 0){
            ans.push_back(pair<P,P>(P(j,i), P(j-1, i)));
          }else if(p && j == 0){
            ans.push_back(pair<P,P>(P(j,i), P(j, i+1)));
          }
        }else{
          if(p)p = false;
          else if(j > 0){
            p = true;
            ans.push_back(pair<P,P>(P(j,i), P(j-1, i)));
          }else if(j == 0){
            p = true;
            ans.push_back(pair<P,P>(P(j,i), P(j, i+1)));
          }
        }
      }
    }
  }
  cout << ans.size() << endl;
  while(!ans.empty()){
    auto p = ans.front();ans.pop_front();
    cout << p.first.second+1 << " " << p.first.first +1 << " " << p.second.second +1<< " " << p.second.first+1 << endl;
  }
}


Measured memory_bytes: 12304
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;

int main()
{
	ll N,r,p=2,q=1;
	cin>>N;
	if(N==0)r=p;
	else if(N==1)r=q;
	else
		for(int i=2;i<=N;i++)
		{
			r=p+q;
			p=q;
			q=r;
		}
	cout<<r<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<sstream>
#include<iomanip>
#include<map>

using namespace std;

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

string convert(int i) {
    ostringstream ss;
    ss << setw(3) << setfill('0') << i;
    return ss.str();
}

bool ok(string s1, string s2) {
    int cur = 0;
    rep(i, s1.size()) {
        while(1) {

            if (cur == s2.size()) return false;
            if (s1[i] == s2[cur]) {
                cur++;
                break;
            }
            cur++;
        }
    }
    return true;
}

int main() {
    int N;
    string S;
    cin >> N >> S;
    int ans = 0;
    rep(i, 1000) {
        if (ok(convert(i), S)) {
            // cout << convert(i) << endl;
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define rep(i,N) for(int i = 0; i < (N); i++)
#define erep(i,N) for(int i = N - 1; i >= 0; i--)
const ll INF = 1000000000;
//const ll MOD = 1000000007;
const ld PI = (acos(-1));
using Graph = vector<vector<int>>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true;} return false;}
typedef pair<int, int> pair;
double rad(double a) {return a * 180 / PI;}

struct UnionFind {
    vector<int> par; // par[i]:iの親の番号 (例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};

//dpTable
int dp[100050];

int main(){
    int H,W,M;
    cin >> H >> W >> M;
    vector<int> h(M);
    vector<int> w(M);
    vector<int> Bh(H,0);
    vector<int> Bw(W,0);
    rep (i,M) {
        cin >> h.at(i) >> w.at(i);
        Bh.at(h.at(i) - 1)++;
        Bw.at(w.at(i) - 1)++;
    }
    int ansH = 0,ansW = 0;
    rep (i,H) {
        if (ansH < Bh.at(i)) {
            ansH = Bh.at(i);
        }
    }
    rep (i,W) {
        if (ansW < Bw.at(i)) {
            ansW = Bw.at(i);
        }
    }
    vector<int> memH;
    vector<int> memW;
    rep (i,H) {
        if (ansH == Bh.at(i)) memH.push_back(i);
    }
    rep (i,W) {
        if (ansW == Bw.at(i)) memW.push_back(i);
    }
    int hoge = 0;
    for (int i = 0; i < M; i++) {
        if (binary_search(memH.begin(),memH.end(),h.at(i) - 1) && binary_search(memW.begin(),memW.end(),w.at(i) - 1)) {
            hoge++;
        }
    }
    cout << ansH + ansW - (hoge == memH.size() * memW.size()) << endl;
    return 0;
}

Measured memory_bytes: 12068
import math
import itertools
import sys

class Dice:
  numbers = []
  faces = {
    'top': None,
    'back': None,    
    'right': None,    
    'left': None,    
    'front': None,    
    'bottom': None,
  }

  def __init__(self, int_array):
    self.numbers = int_array
    self.faces['top'] = self.numbers[0]
    self.faces['back'] = self.numbers[1]
    self.faces['right'] = self.numbers[2]
    self.faces['left'] = self.numbers[3]
    self.faces['front'] = self.numbers[4]
    self.faces['bottom'] = self.numbers[5]

  def getNum(self, n):
    return self.numbers[n-1]

  def getFace(self, f):
    return self.faces[f]

  def rotate(self, direction):
    if direction == 'N':
      top = self.faces['top'] #一時保存

      self.faces['top'] = self.faces['back']
      self.faces['back'] = self.faces['bottom']
      self.faces['bottom'] = self.faces['front']
      self.faces['front'] = top
      
    elif direction == 'E':
      top = self.faces['top'] #一時保存

      self.faces['top'] = self.faces['left']
      self.faces['left'] = self.faces['bottom']
      self.faces['bottom'] = self.faces['right']
      self.faces['right'] = top
      
    elif direction == 'S':
      top = self.faces['top'] #一時保存

      self.faces['top'] = self.faces['front']
      self.faces['front'] = self.faces['bottom']
      self.faces['bottom'] = self.faces['back']
      self.faces['back'] = top
      
    else:
      top = self.faces['top'] #一時保存

      self.faces['top'] = self.faces['right']
      self.faces['right'] = self.faces['bottom']
      self.faces['bottom'] = self.faces['left']
      self.faces['left'] = top
      
def main():
  number = list(map(int, input().split()))
  order = input()

  dice = Dice(number)

  for o in order:
    dice.rotate(o)

  print(dice.getFace('top'))


if __name__ == '__main__':
  main()


Measured memory_bytes: 5712
n = int(input())
a_1_list = list(map(int, input().split()))
a_2_list = list(map(int, input().split()))
ans_sum = 0

for i in range(n):
    temp_sum = 0
    temp_sum += sum(a_1_list[0:i+1])
    temp_sum += sum(a_2_list[i:n])
    if temp_sum > ans_sum:
        ans_sum = temp_sum
print(ans_sum)


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

int main(){
  int H,W; cin>>H>>W;
  
  vector<vector<int>> WF(10,vector<int>(10));
  REP(i,10) REP(j,10) cin>>WF[i][j];
  
  REP(i,10) REP(j,10) REP(k,10)
    WF[j][k]=min(WF[j][k],WF[j][i]+WF[i][k]);
  
  int a,ans=0;
  REP(i,H*W) {
    cin>>a; if(a!=-1) ans+=WF[a][1];
  }
  cout<<ans<<endl;
}

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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
typedef long long ll;


int main() {
    int A,B; cin >> A >> B;
    if(A>8 || B>8) cout << ":(" << endl;
    else cout << "Yay!" << endl;
    return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
typedef long long       ll;
#define MOD ((int)1e9+7)
#define N ((int)2e5+123)
void reads(string& x){ char kk[N]; scanf("%s",kk); x = kk;}

ll n, k;

void solve(){
    scanf("%lld%lld", &n,&k);
    n = n - k*(n/k);
    n = min(n,abs(n-k));
    printf("%lld\n", n);
}

int main(){
    ios_base::sync_with_stdio(0);
    int t = 1; //scanf("%d",&t);
    for(int caso=1;caso<=t;caso++){
        solve();
    }
}

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


int main(void){
    int n;
    cin>>n;
    vector<vector<int> > v(15, vector<int>(15, -1));
    rep(i, n){
        int a;
        cin>>a;
        rep(j, a){
            int x, y;
            cin>>x>>y;
            --x;
            v[i][x]=y;
        }
    }
    int ans=0;
    for(int bit=0;bit<(1<<n);bit++){
        vector<int> d(n);
        rep(j, n){
            if((bit>>j)&1) d[j]=1;
        }
        bool ok = true;
        rep(i, n){
            if(d[i]){
                rep(j, n){
                    if(v[i][j]==-1) continue;
                    if(v[i][j]!=d[j]) {
                        ok = false;
                        break;
                    }
                }   
            }
        }
        if(ok) ans=max(ans, __builtin_popcount(bit));
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
H, W = map(int, input().split())
S = ['.' + input() + '.' for _ in range(H)]
S = ['.'*(W+2)] + S + ['.'*(W+2)]
ans = [[0]*W for _ in range(H)]

for i in range(1, H+1):
    for j in range(1, W+1):
        if S[i][j] != '#':
            tmp = S[i-1][j-1]=='#'
            tmp += S[i][j-1]=='#'
            tmp += S[i+1][j-1]=='#'
            tmp += S[i+1][j]=='#'
            tmp += S[i+1][j+1]=='#'
            tmp += S[i][j+1]=='#'
            tmp += S[i-1][j+1]=='#'
            tmp += S[i-1][j]=='#'
            tmp = str(tmp)
        else:
            tmp = '#'
        ans[i-1][j-1] = tmp
        
for i in ans:
    print(*i, sep='')

Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
int arr[110][110];
int cek(int x,int y,int d)
{
	int i;
	int temp=0;
	for(i=1;i<=d;i++)
	{
		temp+=pow(abs(arr[x][i]-arr[y][i]),2);
	}
	int save=sqrt(temp);
	return save*save==temp;
}
int main(){
	int n,d;
	cin>>n>>d;
	int x,y;
	for(x=1;x<=n;x++)
	{
		for(y=1;y<=d;y++)
		{
			cin>>arr[x][y];
		}
	}
	int ans=0;
	for(x=1;x<=n;x++)
	{
		for(y=x+1;y<=n;y++)
		{
			if(cek(x,y,d))
			{
				ans++;
			}
		}
	}
	cout<<ans<<endl;
}

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

void swap( int , int , int , int , int* );
void check( int* );
int comp( int* , int* );

int main(void){
    // Your code here!
    int dice1[6];
    int dice2[6];
    int *p1 , *p2;
    int i,j;
    p1 = dice1;
    p2 = dice2;
    int ok = 0;
    
    for( int i = 0 ; i < 6 ; i++ ){ scanf( "%d" , p1 + i ); }
    for( int i = 0 ; i < 6 ; i++ ){ scanf( "%d" , p2 + i ); }
    

            for( i = 0 ; i < 4 ; i++ ){
                if( comp( p1 , p2 ) ){ ok = 1; break; }
                for( j = 0 ; j < 4 ; j++ ){
                    swap( 1 , 2 , 4, 3 , p1 );//スピン
                    if( comp( p1 , p2 ) ){ ok = 1; break; }
                    //check(dice1);
                }
                swap( 0 , 1 , 5 , 4 , p1 );//N
            } 

            for( i = 0 ; i < 4 ; i++ ){
                if( comp( p1 , p2 ) ){ ok = 1; break; }
                for( j = 0 ; j < 4 ; j++ ){
                    swap( 1 , 2 , 4, 3 , p1 );//スピン
                    if( comp( p1 , p2 ) ){ ok = 1; break; }
                    //check(dice1);
                }
                swap( 0 , 2 , 5 , 3 , p1 );//W
            }
            
            /*
            switch( t[idx][0] ){
                case 'N'://1 -> 5 / 5 -> 6 / 6 -> 2 / 2 -> 1 // 1と5 → 1と2 → 2と6
                    swap( 0 , 1 , 5 , 4 , p1 );
                    break;
                case 'R'://1 -> 5 / 5 -> 6 / 6 -> 2 / 2 -> 1 // 1と5 → 1と2 → 2と6
                    swap( 0 , 1 , 5 , 4 , p1 );
                    swap( 0 , 1 , 5 , 4 , p1 );
                    break;
                case 'S':
                    swap( 0 , 4 , 5 , 1 , p1 );
                    break;
                case 'E':
                    swap( 0 , 3 , 5, 2 , p1 );
                    break;
                case 'W':
                    swap( 0 , 2 , 5 , 3 , p1 );
                    break;
                default:
                    break;
            }
            */

        



        //check( dice );
        if( ok ){
            printf("Yes\n");
        }else{
            printf("No\n");
        }
}


int comp( int *dice1 , int *dice2 ){
    for( int i = 0; i < 6; i++ ){
        if( dice1[i] != dice2[i] ){
            return 0;
        }
    }
    return 1;
}


void swap( int x1, int x2 , int x3 , int x4 , int *dice ){
    int tmp;
    tmp = *( dice + x1 );
    *( dice + x1 ) = *( dice + x2 );
    *( dice + x2 ) = *( dice + x3 );
    *( dice + x3 ) = *( dice + x4 );
    *( dice + x4 ) = tmp;
    return;
};

void check(int *dice){
    for( int i = 0 ; i < 6 ; i++ ){
        printf( "%d " , dice[i] );
    }
    printf("\n");
}



Measured memory_bytes: 2108
n = int(input())
a = sorted(list(map(int, input().split())),reverse = True)
Alice = 0
Bob = 0
count = 0

while True:
    Alice += a[count]
    count += 1
    if count == n:
        print(Alice - Bob)
        exit()
    Bob += a[count]
    count += 1
    if count == n:
        print(Alice - Bob)
        exit()

Measured memory_bytes: 9156