akhauriyash/Code-Regression huggingface dataset:
def dp_solve(dp0, dp1, dp2, n):
    for i in range(1, n):
        dp0[i] = max(dp1[i-1], dp2[i-1])+ax[i]
        dp1[i] = max(dp0[i-1], dp2[i-1])+bx[i]
        dp2[i] = max(dp0[i-1], dp1[i-1])+cx[i]
    return max(dp0[-1], dp1[-1], dp2[-1])


if __name__ == "__main__":
    n = int(input())
    ax = []
    bx = []
    cx = []
    for i in range(n):
        a, b, c = map(int, input().split())
        ax.append(a)
        bx.append(b)
        cx.append(c)

    dp0 = [ax[0]]+[0]*(n-1)
    dp1 = [bx[0]]+[0]*(n-1)
    dp2 = [cx[0]]+[0]*(n-1)
    print(dp_solve(dp0, dp1, dp2, n))


Measured memory_bytes: 27564
#include<bits/stdc++.h>
using namespace std;
#define ll long long
string max(string s1,string s2)
{
    if(s1.length()>s2.length())
        return s1;
    else
        return s2;
    
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    string s1,s2;
    cin>>s1>>s2;
    int n1=s1.length();
    int n2=s2.length();
    string dp[2][n2+1];
    for(int i=0;i<2;i++)
        dp[i][0]="";
    for(int j=1;j<=n2;j++)
        dp[0][j]="";
    for(int i=1;i<=n1;i++)
    {
        for(int j=1;j<=n2;j++)
        {
            dp[i%2][j]=max(dp[(i-1)%2][j],dp[i%2][j-1]);
            
            if(s1[i-1]==s2[j-1])
                dp[i%2][j]=max(dp[i%2][j],dp[(i-1)%2][j-1]+s1[i-1]);
            }
    }
    if(dp[n1%2][n2]=="")
        cout<<" ";
    else    
        cout<<dp[n1%2][n2];
    return 0;
}

Measured memory_bytes: 16820
using System;
class P
{
    public static void Main()
    {
        string[] str = Console.ReadLine().Split(' ');

        int h = int.Parse(str[0]);
        int w = int.Parse(str[1]);

        while (w != 0 || h != 0)
        {
            for (int i = 1; i <= h; i++)
            {
                //odd height
                if (i % 2 == 1)
                {
                    for (int j = 1; j <= w; j++)
                    {
                        if (j % 2 == 1)
                            Console.Write("#");
                        else if (j % 2 == 0)
                            Console.Write(".");
                    }
                    Console.WriteLine();
                }
                //even height
                else if(i % 2 == 0)
                {
                    for (int j = 1; j <= w; j++)
                    {
                    if (j % 2 == 1)
                        Console.Write(".");
                    else if (j % 2 == 0)
                        Console.Write("#");
                    }
                Console.WriteLine();
                }                        
            }
            Console.WriteLine();

            str = Console.ReadLine().Split(' ');
            h = int.Parse(str[0]);
            w = int.Parse(str[1]);
        }
    }
}


Measured memory_bytes: 15948
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <vector>

using namespace std;

int main() {
  uint32_t N, *a;
  cin >> N;

  a = new uint32_t[N];
  for (uint32_t i = 0; i < N; i++) cin >> a[i];
  uint64_t sum = 0;
  for (uint32_t i = 0; i < N; i++) {
    sum += a[i];
  }
  if (sum == 0) {
    cout << "Yes" << endl;
    return 0;
  }
  if (N % 3 != 0) {
    cout << "No" << endl;
  } else {
    uint32_t A = a[0];
    uint32_t i = 1;
    while (a[i] == A && i < N) ++i;
    if (A == a[i]) {
      cout << "No" << endl;
      return 0;
    }
    uint32_t B = a[i];
    uint32_t C = A ^ B;
    uint32_t ANum = 0, BNum = 0, CNum = 0;
    for (i = 0; i < N; ++i) {
      if (a[i] == A) ANum++;
      if (a[i] == B) BNum++;
      if (a[i] == C) CNum++;
    }
    if (A == 0 || B == 0) {
      if (A == 0) {
        if (BNum == 2 * ANum)
          cout << "Yes" << endl;
        else
          cout << "No" << endl;
      } else {
        if (ANum == 2 * BNum)
          cout << "Yes" << endl;
        else
          cout << "No" << endl;
      }
    } else {
      if (ANum == BNum && ANum == CNum)
        cout << "Yes" << endl;
      else
        cout << "No" << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 640
import sys
import collections


def alg_combination(n, r):
    r = min(n - r, r)
    if r == 0:
        return 1
    else:
        denominator = 1
        for i in range(n, n - r, -1):
            denominator = (denominator * i)
        molecule = 1
        for i in range(1, r + 1):
            molecule = (molecule * i)
        return denominator // molecule


def solve():
    readline = sys.stdin.buffer.readline
    mod = 10 ** 9 + 7
    n = int(readline())
    d = collections.defaultdict(int)
    for i in range(n):
        d["".join(sorted(list(str(readline().rstrip().decode('utf-8')))))] += 1
    t = 0
    for k, v in d.items():
        if v >= 2:
            t += alg_combination(v, 2)
    print(t)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 58716
from decimal import Decimal
Q,H,S,D = [int(i) for i in input().split()]
costs = [[Q,Decimal("0.25")], [H,Decimal("0.5")], [S,Decimal("1")], [D,Decimal("2")]]
costs.sort(key=lambda x: Decimal(x[0]) / x[1])
N = int(input())
tc = 0
for c, a in costs:
    tc += c * (N // a)
    N %= a
print(int(tc))

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

int main(){
    ll a,b,n;
    cin>>a>>b>>n;
    if(n>=b){
        ll amari=n%b;
        n-=(amari+1);
    }
    ll fir=(a*n)/b;
    ll sec=a*(n/b);
    cout<<fir-sec<<endl;
    return 0;
}

Measured memory_bytes: 3624
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで

#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

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

    ll  a,b,c,d,e,n,k,maxi=0,f=0,mini=INF,sum=0,q;
	string str,stra,straa;
    ll x,y,w,z;
    char ca,cb,cc;
    cin>>n;
    if(n<=111) cout<<111;
    else if(n<=222) cout<<222;
else    if(n<=333) cout<<333;
    else if(n<=444) cout<<444;
 else   if(n<=555) cout<<555;
   else if(n<=666) cout<<666;
  else  if(n<=777) cout<<777;
   else if(n<=888) cout<<888;
   else if(n<=999) cout<<999;

    return 0;
}


Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>
#include <stdio.h>
#include <string>
#include<iomanip>
#include<limits>
using namespace std;
int main(void){
    string s;
    cin>>s;
    for(int i=0;i<s.length();i++){
        cout<<"x";
    }
    cout<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, a, b) for (int i = (a); i < (b); ++i)

using namespace std;
using ll = long long;

/**
 * main
 */
int main () {
  ll X; cin >> X;

  ll n500 = X / 500;
  ll n5 = (X % 500) / 5;

  cout << (n500 * 1000 + n5 * 5) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a=n%10;
    if(a==2||a==4||a==5||a==7||a==9)
        cout<<"hon"<<endl;
    else if(a==0||a==1||a==6||a==8)
        cout<<"pon"<<endl;
    else if(a==3)
        cout<<"bon"<<endl;
    return 0;
}


Measured memory_bytes: 3632
#include <algorithm>
#include <iostream>
#include <random>
#include <string>
#include <vector>

// ハッシュ計算で使う素数
constexpr int prime[] = {2,  3,  5,  7,  11, 13,  17,  19, 23, 29,
                         31, 37, 41, 43, 47, 53,  59,  61, 67, 71,
                         73, 79, 83, 89, 97, 101, 103, 107};

constexpr size_t alphabet = 26;
constexpr size_t str_len = 10;

inline int64_t hash(char *str, int start, int end) {
  int64_t result = 1;

  // アルファベット1文字ごとに素数を割り当てて掛け算結果をハッシュ値にする
  // オーバーフローしない限りは完全ハッシュ
  for (size_t i = start; i < end; ++i) {
    result *= prime[str[i] - 'a'];
  }

  return result;
}

int main() {
  int n;
  scanf("%d", &n);
  std::vector<int64_t> sn(n);

  // 最大入力数*1行の文字数(改行込み)
  char input[100000 * 11 + 5];

  // 文字列の一括入力
  fread(input, sizeof(char), sizeof(char) * 11 * n, stdin);

  for (int i = 0; i < n; ++i) {
    // 一文字目に改行(Nの後の改行のこと)が存在するので+1する
    sn[i] = hash(input, i * 11 + 1, i * 11 + 10 + 1);
  }

  // 文字列ソートではなく、数値ソートになる
  // unorderd_map使えばソートなくなるけど遅くなる
  std::sort(sn.begin(), sn.end());

  // 最後に合算する
  int64_t count = 0;
  int64_t local_count = 0;
  for (int i = 1; i < n; ++i) {
    if (sn[i - 1] == sn[i]) {
      count += (++local_count);
    } else {
      local_count = 0;
    }
  }

  // ldで出力しないとWAする
  printf("%ld\n", count);

  return 0;
}

Measured memory_bytes: 2048
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>

ll pow_mod(ll a, ll n, ll MOD){
  ll m[60]; m[0]=a; // m[i] : a^(2^i)をMODで割った余り
  rep(i,59) m[i+1] = (m[i]*m[i])%MOD;

  ll retval = 1;
  bitset<60> s(n);
  rep(i,60) if (s.test(i)) (retval *= m[i]) %= MOD;

  return retval; 
}

int main(){
  int N; cin >> N;
  vector<ll> cnt(N);
  int D; 
  ll MOD = 998244353;
  ll ans = 1;
  rep(i,N) {
    cin >> D;
    if (i==0 && D!=0) ans = 0;
    cnt[D]++;
  }

  bool is_tree = true;
  int tot = 0;
  rep(i,N){
    if (cnt[i]==0 && tot<N) is_tree = false;
    tot += cnt[i];
  }
  if (is_tree==false || cnt[0]!=1) ans = 0;


  rep(i,N-1){
    if (cnt[i]==0) break;
    (ans *= pow_mod(cnt[i],cnt[i+1],MOD))%= MOD;
  }
  cout << ans << endl;

  

  // cout << fixed << setprecision(10);
  
  return 0;
}


Measured memory_bytes: 4060
#include <bits/stdc++.h>
#define PI 3.14159265359
#define NIL (-1)
#define LL long long
using namespace std;
const int64_t MOD = 1e9 + 7;
const int INF = INT_MAX;

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

	if (a != c) cout << 1 << endl;
	else cout << 0 << endl;
}

Measured memory_bytes: 3600
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

using namespace std;

#define dprint(Exp,...) if(Exp){fprintf(stderr, __VA_ARGS__);}
#define printe(...) fprintf(stderr, __VA_ARGS__);
#define PrtExp(_Exp)  cerr<< #_Exp <<" = "<< (_Exp)
#define PrtExpN(_Exp)  cerr<< #_Exp <<" = "<< (_Exp) <<"\n"

#define SINT(n) scanf("%d",&n)
#define SINT2(n,m) scanf("%d %d",&n,&m)
#define SINT3(n,m,o) scanf("%d %d %d",&n,&m,&o)
#define SINT4(n,m,o,p) scanf("%d %d %d %d",&n,&m,&o,&p)
#define SINT5(n,m,o,p,q) scanf("%d %d %d %d %d",&n,&m,&o,&p,&q)
#define SLL(n) scanf("%lld",&n)
#define SLL2(n,m) scanf("%lld %lld",&n,&m)
#define SLL3(n,m,o) scanf("%lld %lld %lld",&n,&m,&o)
#define SST(s) scanf("%s",s)
#define SCH(c) scanf("%c",&c)

#define GC() getchar()

#define PINT(n) printf("%d",(int)(n))
#define PINT2(n,m) printf("%d %d",(int)(n),(int)(m))
#define PINT3(n,m,l) printf("%d %d %d",(int)(n),(int)(m),(int)(l))
#define PLL(n) printf("%lld",(long long)(n))
#define PST(s) printf("%s",(s))
#define PCH(s) printf("%c",(s))

#define PINTN(n) printf("%d\n",(int)(n))
#define PINT2N(n,m) printf("%d %d\n",(int)(n),(int)(m))
#define PINT3N(n,m,l) printf("%d %d %d\n",(int)(n),(int)(m),(int)(l))
#define PLLN(n) printf("%lld\n",(long long)(n))
#define PSTN(s) printf("%s\n",(s))
#define PCHN(s) printf("%c\n",(s))

#define PSP() printf(" ")
#define PN() printf("\n")

#define PC(c) putchar(c)
#define CSP (' ')
#define SN ("\n")

#define rep(i,a) for(int i=0;i<a;i++)
#define reP(i,a) for(int i=0;i<=a;i++)
#define Rep(i,a) for(int i=a-1;i>=0;i--)
#define ReP(i,a) for(int i=a;i>=0;i--)

#define rEp(i,a) for(i=0;i<a;i++)
#define rEP(i,a) for(i=0;i<=a;i++)
#define REp(i,a) for(i=a-1;i>=0;i--)
#define REP(i,a) for(i=a;i>=0;i--)

#define repft(i,a,b) for(int i=a;i<b;i++)
#define repfT(i,a,b) for(int i=a;i<=b;i++)
#define Repft(i,a,b) for(int i=a-1;i>=b;i--)
#define RepfT(i,a,b) for(int i=a;i>=b;i--)

#define foreach(a,it) for(auto it = a.begin(); it != a.end(); ++it)

#define FILL(a,v) fill(begin(a),end(a), v)
#define FILL0(a) memset(a,0,sizeof(a))
#define FILL1(a) memset(a,-1,sizeof(a))

typedef long long ll;

typedef unsigned long long ull;
typedef pair<int, int> Pi;
typedef pair<ll, ll>   Pll;


const int INF = 0x2aaaaaaa; // 715,827,882
const ll INFLL = 0x1f1f1f1f1f1f1f1fLL;//2,242,545,357,980,376,863

template <class A, class B> inline ostream& operator<<(ostream& st, const pair<A, B>& P) { return st << "(" << P.first << "," << P.second << ")"; };
template <class A, class B> inline pair<A, B> operator+(const pair<A, B>& P, const pair<A, B>& Q) { return pair<A, B>(P.first + Q.first, P.second + Q.second); };
template <class A, class B> inline pair<A, B> operator-(const pair<A, B>& P, const pair<A, B>& Q) { return pair<A, B>(P.first - Q.first, P.second - Q.second); };

#define fs  first
#define sc  second


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

	long double ret = 0;
	long double d = 1;
	rep(i, m) d /= 2;
	const long double Dm = 1 - d;
	const long double D = d;
	const long double r = (n - m) * 100 + m * 1900;
	long double R = r;

	d = 1;
	rep(i, 1000000) {
		ret += R*(d)*D;
		d *= Dm;
		R += r;
	}
	cout << ret << endl;

}


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

int main() { 
  int N,K, X;
  cin >> N >> K;
 X = 1;
  for (int i = 0;i < N; i++){
    if(X * 2 >X + K)
      X += K;
    else
      X *= 2;
  }
  cout << X << endl;
}


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

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

  vector<int> A(N);
  for (int i = 0; i < N; i++){
    cin >> A[i];
  }
  bool approve = true;
  for (int i = 0; i < N; i++){
    if (A[i] % 2 == 0){
      if (A[i] % 3 != 0 && A[i] %5 != 0){
         approve = false;
         break;
      }
    }
  }
  if(approve){
    cout << "APPROVED" << endl;
  } else{
    cout << "DENIED" << endl;
  }   
}



Measured memory_bytes: 256
from collections import deque

n,k = map(int, input().split())
r,s,p = map(int, input().split())
t = deque(list(s for s in input()))

best_hand = {'r': 'p', 's': 'r', 'p': 's'}
ban = []
cand = ''

while t:
    cpu = t.popleft()
    
    if len(ban) < k:
        add_hand = best_hand[cpu]
    else:
        ban_hand = ban.pop(0)
        if best_hand[cpu] == ban_hand:
            add_hand = 'e'
        else:
            add_hand = best_hand[cpu]
    ban.append(add_hand)
    cand += add_hand
    
print(p*cand.count('p') + s*cand.count('s') + r*cand.count('r'))

Measured memory_bytes: 4896
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<int, int> i_i;

#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define ALL(v) v.begin(), v.end()
#define SZ(x) ((ll)(x).size())

const double PI  = acos(-1.0);
const double EPS = 1e-9;
const ll INF = 1e9+10;
const ll MOD = 1e9+7;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
#define print(x) cerr << #x << " is " << x << endl;

#define AB 0
#define BC 1
#define CA 2
int X[200000];
int ans[20000];

//#define print(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; 
int main() {
    int N, A, B, C, V[3];
    cin >> N >> A >> B >> C;
    
    rep(i, N){
        string s;
        cin >> s;
        if (s == "AB")X[i] = AB;
        if (s == "BC")X[i] = BC;
        if (s == "AC")X[i] = CA;
    }
    V[0] = A;
    V[1] = B;
    V[2] = C;
    rep(i, N){
        int x = X[i];
        int y = (X[i] + 1)%3;
        int m = 0;
        if (V[x] == 0 && V[y] == 0){
            cout << "No";
            return 0;
        }
        if (V[x] != V[y] || i == N - 1){
            ans[i] = (V[x] > V[y])? y: x;
        } else {
            int x2 = X[i + 1];
            int y2 = (X[i + 1] + 1)%3;
            ans[i] = (x == x2 || x == y2)? x: y;

        }
        if (ans[i] == x)m = y;
        else m = x;
        V[ans[i]]++;
        V[m]--;
        
    }
    cout << "Yes" << endl;
    rep(i, N)
    fprintf(stdout, "%c\n", 'A' + ans[i]);
    return 0;
}

Measured memory_bytes: 4180
#include<bits/stdc++.h>
using namespace std;
vector<vector<int> > adj1;
vector<vector<int> > adj2;
vector<int> visited1;
vector<int> visited2;
void dfs(int s,int parity)
{
    if(parity==0)
    {
        visited1[s]=1;
        for(auto it:adj1[s])
        {
            if(!visited2[it])
            {
                dfs(it,parity^1);
            }
        }
    }
    else
    {
        visited2[s]=1;
        for(auto it:adj2[s])
        {
            if(!visited1[it])
            dfs(it,parity^1);
        }
    }
    
}
int main()
{
    int n,m;
    cin>>n>>m;
    adj1.resize(n+1);
    visited1.resize(n+1);
    adj2.resize(m+1);
    visited2.resize(m+1);
    for(int i=1;i<=n;i++)
    {
        int k;
        cin>>k;
        for(int j=0;j<k;j++)
        {
            int x;
            cin>>x;
            adj2[x].push_back(i);
            adj1[i].push_back(x);
        }
    }
    dfs(1,0);
    for(int i=1;i<=n;i++)
    {
        if(!visited1[i])
        {
            cout<<"NO";
            return 0;
        }
    }
    cout<<"YES"<<endl;
}

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

#define FAST_IO ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define FOR(i,l,r) for(long long i=l; i<r; i++)
#define FOR_REV(i,r,l) for(long long i=r; i>=l; i--)
#define pb push_back
#define mp make_pair

int main()
{
	ll n, w;
  	cin>>n>>w;

    ll val[110], weight[100007];
    FOR(i,1,n+1)
    {
        cin>>weight[i]>>val[i];
    }

    ll dp[100005] = {0};
    FOR(i,1,n+1)
    {
        FOR_REV(j,w,weight[i])
        {
            if (i==0 || j==0)
                dp[j] = 0;
            if (weight[i] <= j)
            {
                dp[j] = max((val[i]+dp[j-weight[i]]), dp[j]);
            }
        }
    }

    cout<<dp[w]<<endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mx 100005
#define mod 1000000007

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

   if(b*2<a)
    cout<<a-b*2<<endl;
   else cout<<0<<endl;


    return 0;
}


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

// int/long:		-2147483648 - 2147483648 (-2^31 <= int < 2^31)
// long/long long:	-9223372036854775808 - 9223372036854775807 (-2^63 <= long < 2^63)
#define	INF (1<<29)
//536870912

#define	MOD 1000000007

int	main() {
	int n;
	cin >>n;
	vector<int> a(26, 50);
	for (int i=0; i<n; i++) {
		vector<int> aa(26, 0);
		string S;
		cin >>S;
		for (int j=0; j<S.size(); j++) {
			int c=S.at(j)-'a';
			aa.at(c)++;
		}
		for (int j=0; j<26; j++)
			a.at(j)=min(a.at(j), aa.at(j));
	}
	string SS="";
	for (int i=0; i<26; i++) {
		for (int j=0; j<a.at(i); j++)
			SS.push_back('a'+i);
	}
	cout <<SS <<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// ----------------------R00TDADA------------------------------
#define rep(i, a, b) for (__typeof((b)) i = (a); i < (b); i++)
#define nrep(i, a, b) for (__typeof((b)) i = (a); i > (b); i--)
#define all(a) (a).begin(), (a).end()
#define ff first
#define ss second
#define ppi pair<int, int>
#define pppi pair<ppi, int>
#define vi vector<int>
#define vii vector<ppi>
#define viii vector<pppi>
#define vs vector<string>
#define pb push_back
#define mp make_pair
#define sz(x) (int)x.size()
#define M_PI 3.14159265358979323846
#define rootdada ios_base::sync_with_stdio(false)
#define int long long
#define M 1000000007
#define MAX 100005
int A[MAX], tree[4 * MAX];
int power(int x, int p)
{
    if (p == 0)
        return 1;
    int y = power(x, p / 2);
    y *= y;
    y %= M;
    if (p % 2 == 0)
        return y;
    y *= x;
    y %= M;
    return y;
}
void build(int node, int start, int end)
{
    if (start == end)
        //Leaf node will have a single element
        tree[node] = start;
    else
    {
        int mid = (start + end) / 2;
        //Recurse on the left child
        build(2 * node, start, mid);
        //Recurse on the right child
        build(2 * node + 1, mid + 1, end);
        // Internal node will have the sum of both of its children
        tree[node] = tree[2 * node] + tree[2 * node + 1];
    }
}
void update(int node, int start, int end, int idx, int val)
{
    if (start == end)
    {
        //Leaf Node
        A[idx] = val;
        tree[node] += val;
    }
    else
    {
        int mid = (start - end) / 2 + end;
        if (start <= idx && idx <= mid)
        {
            // If idx is in the left child, recurse on the left child
            update(2 * node, start, mid, idx, val);
        }
        else
        {
            // if idx is in the right child, recurse on the right child
            update(2 * node + 1, mid + 1, end, idx, val);
        }
        // Internal node will have the sum of both of its children
        tree[node] = tree[2 * node] + tree[2 * node + 1];
    }
}
int query(int node, int start, int end, int l, int r)
{
    if (r < start || l > end)
    {
        // range represented by a node is completely outside the given range
        return 0;
    }
    if (l <= start && end <= r)
    {
        // range represented by a node is completely inside the given range
        return tree[node];
    }
    // range represented by a node is partially inside and partially outside the given range
    int mid = (start + end) / 2;
    int p1 = query(2 * node, start, mid, l, r);
    int p2 = query(2 * node + 1, mid + 1, end, l, r);
    return p1 + p2;
}
void Baap_ko_mat_sikha()
{
    int k, x;
    cin >> k >> x;
    if (k * 500 >= x)
        cout << "Yes" << endl;
    else
    {
        cout << "No" << endl;
    }
}

signed main()
{

    rootdada;
    int t;
    t = 1;
    while (t--)
    {
        Baap_ko_mat_sikha();
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9,MOD = 1e9+7,ohara = 1e6;
const ll LINF = 1e18;
using namespace std;

#define rep(i,n) for(ll (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrrep(i,a,b) for(ll i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl

ll n,cnt=0,ans=0,a[ohara],b,c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos,le,ri,f[ohara],fr[ohara];
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

ll mod_pow(ll xx,ll nn,ll mod){
    ll ret=1;
    while(nn>0){
        if(nn&1)ret=ret*xx%mod;
        xx=xx*xx%mod;
        nn>>=1;
    }
    return ret;
}

ll ncr(ll nn,ll r){
    if(nn<r)return 0;
    return f[nn]*fr[r]%MOD*fr[nn-r]%MOD;
}

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

    cin>>n;
    f[0]=1;
    rrep(i,1,n+3){
        f[i]=f[i-1]*i%MOD;
    }
    fr[n+2]=mod_pow(f[n+2],MOD-2,MOD);
    rrrep(i,n+1,0){
    fr[i]=fr[i+1]*(i+1)%MOD;
    }

    map<ll,ll> mp;
    map<ll,ll> left;
    rep(i,n+1){
        cin>>a[i];
        mp[a[i]]++;
        if(mp[a[i]]==2)pos=a[i],le=left[a[i]],ri=n-i;
        left[a[i]]=i;
    }
    rep(i,n+1){
        Cout((ncr(n+1,i+1)-ncr(le+ri,i)+MOD)%MOD);
    }
    return 0;
}


Measured memory_bytes: 22656
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
typedef long long ll;

int main()
{
    fastIO;
    int n;
    cin >> n;
    vector<ll> add(n), diff(n);
    ll x,y;
    for (int i=0; i<n; i++) {
        cin >> x >> y;
        add[i] = x+y;
        diff[i] = x-y;
    }   
    ll ans1 = *max_element(add.begin(), add.end()) - *min_element(add.begin(), add.end());
    ll ans2 = *max_element(diff.begin(), diff.end()) - *min_element(diff.begin(), diff.end());
    cout << max(ans1, ans2) << '\n';
}

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

const int inf = 1e9 + 17;

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

signed main () {
    int n, m, x;
    cin >> n >> m >> x;
    vector < pair < int, vector < int > > > b(n);
    for (int i = 0; i < n; ++i) {
        cin >> b[i].first;
        b[i].second.resize(m);
        for (int &y: b[i].second) 
            cin >> y;
    }
    int required = inf;
    for (int mask = 0; mask < (1 << n); ++mask) {
        vector < int > level(m, 0);
        int money = 0;
        for (int i = 0; i < n; ++i) {
            if (mask & (1 << i)) {
                money += b[i].first;
                for (int j = 0; j < m; ++j)
                    level[j] += (b[i].second)[j];
            }
        }
        bool ok = 1;
        for (int y: level) {
            if (y < x)
                ok = 0;
        }
        if (ok)
            chmin(required, money);
    }
    if (required == inf)
        required = -1;
    cout << required << '\n';
}


Measured memory_bytes: 3632
r, c = map(int, raw_input().split())

data = [0 for i in range(r)]
temp = [0 for i in range(c)]

for i in range(r):
    data[i] = map(int, raw_input().split())
    
for i in range(r):
    data[i].append(0)
    data[i][c] = sum(data[i])
for i in range(c):
    for j in range(r):
        temp[i] += data[j][i]
temp.append(sum(temp))
data.append(temp)

for i in range(r+1):
    print " ".join(map(str, data[i]))

Measured memory_bytes: 6464
import java.util.Scanner;


public class Main {

	
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		
		boolean primes[] = new boolean[10001];
		
		primes[0] = false;
		primes[1] = false;
		for(int i = 2; i < 10001; i++){
			primes[i] = true;
		}
		
		for(int i = 2; i < 101; i++){
			if(primes[i]){
				for(int j = 2*i; j < 10001; j += i){
					primes[j] = false;
				}
			}
		}
		
		while(true){
			final int N = sc.nextInt();
			
			if(N == 0){
				break;
			}
			
			int twin = 5;
			for(int i = 2; i <= N; i++){
				if(primes[i-2] && primes[i]){
					twin = i;
				}
			}
			
			System.out.println((twin - 2) + " " + twin);
		}
		
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
int main() {
  int H1,M1,H2,M2,K;
  cin>>H1>>M1>>H2>>M2>>K;
  cout<<60*H2+M2-60*H1-M1-K<<endl;
  return 0;}

Measured memory_bytes: 3636
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define vi vector<int>
#define pb push_back
#define INF 999999999

int n;

bool solve(vector<int> data,set<int> dp[31][51],int day){
    set<int> tmp;
    rep(i,data.size()){
        for(auto &elm:dp[day-1][ data[i] ]){
            tmp.insert(elm);
        }
    }
    if(tmp.size()==n)return true;

    rep(i,n)dp[day][i] = dp[day-1][i];

    rep(i,data.size()) dp[day][ data[i] ] = tmp;

    return false;
}


int main(){
    while(cin>>n&&n){
        vector<int> data[31];
        rep(i,n){
            int m;
            cin>>m;
            rep(j,m){
                int a;
                cin>>a;
                data[a].pb(i);
            }
        }
        
        set<int> dp[31][51];
        rep(i,n)dp[0][i].insert(i);
        
        int ans = INF;
        for(int i=1;i<=30;i++){
            if(solve(data[i],dp,i)){
                ans = i;
                break;
            }
        }
        if(ans==INF)cout<<-1<<endl;
        else cout<<ans<<endl;
    }
}

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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
template<typename T> using v = vector<T>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
void dumplist_debug(T list) {
#ifdef MY_DEBUG
    each(e, list) cout << e << " ";
    printf("\n");
#endif
}

ll inl() {
    ll x;
    cin >> x;
    return (x);
}

string ins() {
    string x;
    cin >> x;
    return x;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

class DAG {
private:
    ll v, e;
    vvl table;
    vl in_d; // 頂点の入力次数
public:
    // v: 頂点数
    // e: 辺の数
    DAG(ll v, ll e) {
        this->v = v;
        this->e = e;
        table.resize(v);
        in_d.resize(v);
    }

    void add(ll from, ll to) {
        table[from].eb(to);
        in_d[to]++;
    }

    // O(v + e)
    vl sort() {
        stack<ll> st; // 入力次数が0の頂点集合

        dumplist_debug(in_d);
        rep(i, v) if (in_d[i] == 0) st.push(i);
        vl ans; // ソート後のグラフ

        while (!st.empty()) {
            ll i = st.top();
            st.pop();
            ans.eb(i);
            each(j, table[i]) {
                in_d[j]--;
                if (in_d[j] == 0) st.push(j);
            }
        }

        return ans;
    }
};

int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
    while (true) {
#pragma clang diagnostic pop
#endif
        ll v, e;
        cin >> v >> e;
        DAG dag(v, e);
        rep(i, e) {
            ll s = inl(), t = inl();
            dag.add(s, t);
        }
        vl ans = dag.sort();
        each(m, ans) cout << m << endl;

#ifdef MY_DEBUG
    }
#endif
    return 0;
}


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

using namespace std;

#define ll long long int

int main() {

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

    ll n,k; cin >> n >> k;

    ll ans = k;

    for(int i = 1; i < n; i++) ans *= (k-1);

    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 256
N = int(input())
S = []
P = []

for i in range(N):
    s, p = input().split()
    S.append(s)
    P.append(int(p))

name = list(sorted(set(S)))

for i in range(len(name)):
    score = []
    number = []
    for j in range(N):
        if S[j] == name[i]:
            score.append(P[j])
            number.append(j+1)
    for k in range(S.count(name[i])):
        place = score.index(max(score))
        print(number[place])
        del number[place]
        del score[place]


Measured memory_bytes: 9156
import numpy as np
n = int(input())

P = [int(s) for s in input().split()]

K = [int(i+1) for i in range(n)]

P = np.array(P)
K = np.array(K)
P_K = P - K

c = 0
for i in range(n):
    if P_K[i] != 0:
        c += 1
    else:
        pass
if c <= 2:
    print("YES")
else:
    print("NO")


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

using namespace std;

const int MN = 123456;
int n;
int a[MN], dp[MN];

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

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

    fill(dp + 1, dp + n, numeric_limits<int>::max());
    for (int i = 0; i < n - 1; i++) {
        for (int j = 1; j <= 2; j++) {
            if (i + j >= n) break;
            dp[i + j] = min(dp[i + j], dp[i] + abs(a[i] - a[i + j]));
        }
    }
    cout << dp[n - 1] << '\n';
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main() {
	long long n, a; cin >> n >> a;
	if (a == 1) {
		cout << 0 << endl;
	}
	else {
		cout << n - a << endl;
	}
	cin >> n;
}

Measured memory_bytes: 256
#include <stdio.h>



int main(void)
{
	//変数の宣言
	int n;
	int p[100010];
	int i;
	int count=0;
	
	
	//データの読み込み
	scanf("%d",&n);
	
	for(i=1;i<n+1;i++){
		scanf("%d",&p[i]);
	}
	
//	printf("nは%dです\n", n);
//	printf("データの読み込み終了\n");
	//実際の処理
	
	i=1;
	while(i<n+1){
		if(p[i]==i){
			count++;
			i++;
		}
		i++;
	}
	
//	printf("計算部分終了\n");
	
	//出力
	
	printf("%d",count);
	
//	printf("結果の出力終了\n");
	
	return 0;
}



Measured memory_bytes: 512
//
// Created by Hideaki Imamura on 2019-06-06.
//

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

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

    cout << (t / a) * b << endl;

    return 0;
}

Measured memory_bytes: 256
# /user/bin/python
# -*- coding: utf-8 -*-
import sys


D,G = list(map(int, input().split()))
PC = [0]+[list(map(int, input().split())) for _ in range(D)]
 
def function(G, i):
	if i == 0:
		return 1e9
	n = min(G//(i*100), PC[i][0])
	s = n*i*100
	if n == PC[i][0]:
		s += PC[i][1]
	if s < G:
		n += function(G-s, i-1)
	return min(n, function(G,i-1))

print(function(G, D))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pll = pair<ll, ll>;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rrep(i, m, n) for(ll i = m; i > n; i--)
#define Rep(i, m, n) for(ll i = m; i < n; i++)
#define all(vec) vec.begin(), vec.end()
#define lmax(x, y) max<ll>(x, y)
#define lmin(x, y) min<ll>(x, y)
#define tmax(x, y, z) lmax((x), lmax((y), (z)))
#define tmin(x, y, z) lmin((x), lmin((y), (z)))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define ZERO(a) memset(a, 0, sizeof(a))
const ll INF = 1LL << 60;
const ll MM = 1000000000; const ll MOD = MM + 7; const ll MMM=9223372036854775807;//2^63 -1
#define ADD(a,b) a = (a + ll(b)) % MOD
#define MUL(a,b) a = (a * ll(b)) % MOD
ll GCD(ll x, ll y){ if(y == 0) return x; else return GCD(y, x % y);}
ll LCM(ll x, ll y){ return x / GCD(x, y) * y;}
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;}
template<typename A, size_t N, typename T> void FILL(A (&array)[N], const T &val){ fill( (T*)array, (T*)(array+N), val );}
// struct edge{ ll from, to, cost; };
// struct edge{ ll to, cost; };
// using Graph = vector<vector<ll>>;  // 重み無し
// using Graph = vector<edge>;  // 辺
// using Graph = vector<vector<edge>>;  // 重み付き
ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
ll ddx[8] = {1, 1, 0, -1, -1, -1, 0, 1}, ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

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


int main(){
    ll n, x, m; cin >> n >> x >> m;
    ll sum = 0, more = 0, bef = 0, shu = 0, bef_long = 0, shu_long = 0;
    // set<ll> s;
    vector<ll> shu_v, A(100000);
    map<ll, ll> mp;
    bool found = false, shuuki = false;
    Rep(i, 1, n+1){
        if(i == 1) A[i-1] = x;
        else A[i-1] = A[i-2]*A[i-2] % m;
        ll tmp = A[i-1];
        mp[tmp]++;
        if(mp[tmp] == 2){
            if(!shuuki) bef_long = i-1;
            shuuki = true;
            shu += tmp;
            sum += tmp;
            shu_v.push_back(tmp);
        }
        else if(mp[tmp] == 3){
            shu_long = i - bef_long - 1;
            found = true;
            break;
        }
        else{
            sum += tmp;
            bef += tmp;
        }
    }
    if(mp.count(0)){
        cout << sum << endl;
        return 0;
    }
    if(!found){
        cout << sum << endl;
        return 0;
    }
    rep(i, (n-bef_long)%shu_long){
        more += shu_v[i];
    }
    cout << bef + shu * ((n-bef_long)/shu_long) + more << endl;
}


Measured memory_bytes: 7688
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int N;
    cin >> N;
    vector<ll> a(N);
    for (int i = 0; i < N; i++) cin >> a[i];
    vector<ll> sum(N);
    sum[0] = a[0];
    for (int i = 1; i < N; i++) sum[i] = sum[i-1] + a[i];

    // 次の2通りの並べ方
    // - + - + ...
    // + - + - ...
    // 符号が異なるなら -x -> 1, x -> -1に変換
    // cum: 値の累計
    // cnt: 操作回数
    vector<ll> cum(2), cnt(2);
    for (int i = 0; i < N; i++) {
        int i1 = i % 2, i2 = (i + 1) % 2;
        if (sum[i] + cum[i1] <= 0) {
            ll d = abs(sum[i] + cum[i1]) + 1;
            cnt[i1] += d;
            cum[i1] += d;
        }
        if (sum[i] + cum[i2] >= 0) {
            ll d = abs(sum[i] + cum[i2]) + 1;
            cnt[i2] += d;
            cum[i2] -= d;
        }
    }
    cout << min(cnt[0], cnt[1]) << '\n';
}


Measured memory_bytes: 4856
#include <bits/stdc++.h>
#include <iostream>
#include <math.h>

using namespace std;

int main() {
  int n;
  cin >> n;
  vector<int> a(n),b(n-1);
  for(int i=0;i<n-1;i++){
    cin >> b.at(i);
  }
  for(int i=1;i<=n-2;i++){
    a.at(i) = min(b.at(i-1),b.at(i));
  }
  a.at(0) = b.at(0);
  a.at(n-1) = b.at(n-2);
  int ans=0;
  for(int i=0;i<n;i++){
    ans += a.at(i);
  }
  
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yn(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YN(ans) if(ans)printf("YES\n");else printf("NO\n")
#define vector1d(type,name,...) vector<type>name(__VA_ARGS__)
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }
ll updivide(ll a,ll b){if(b==1) return a;else if(a%b==0) return a/b;else return (a/b)+1;}

int main(){
    string s,t;
    cin>>s>>t;
    set<char> kind;
    char c='a';
    int ans=1;
    for(int i=0;i<26;i++){
        for(int j=0;j<s.length();j++){
            if(s[j]==c){
                kind.insert(t[j]);
            }
        }
        if(kind.size()>=2){
            ans=0;
            break;
        }else{
            kind.clear();
        }
        for(int j=0;j<s.length();j++){
            if(t[j]==c){
                kind.insert(s[j]);
            }
        }
        if(kind.size()>=2){
            ans=0;
            break;
        }else{
            kind.clear();
        }
        c++;
    }
    yn(ans);
}

Measured memory_bytes: 3932
def resolve():
    '''
    code here
    '''

    grid = [[int(i) for i in input().split()] for _ in range(3)]

    is_flag = True

    for i in range(3):
        A = grid[0][i-1] -grid[0][i]
        C = grid[2][i-1] -grid[2][i]
        B = grid[1][i-1] -grid[1][i]

        if  A == B and B == C:
            pass
        else:
            is_flag = False

    print('Yes') if is_flag else print('No')



if __name__ == "__main__":
    resolve()


Measured memory_bytes: 3064
///In the name of GOD
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
const ll MXN = 1e6 + 10;
bool is_pal(string s){
    string t = s;
    reverse(t.begin(), t.end());
    return (s == t);
}
int main(){
    ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
    string s, m1, m2;
    ll n;
    cin >> s; n = s.size();
    m1 = s.substr(0, n / 2);
    m2 = s.substr(n / 2 + 1, n / 2);
    cout << (is_pal(s) && is_pal(m1) && is_pal(m2) ? "Yes" : "No");
    return 0;
}
/*!
    Be careful who you share your weaknesses with.
    Some people can't wait for the opportunity to use them against you!!
*/
//! N.N


Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define NIL -1
#define MAX 25

struct Node{
  int p, l, r;
};

int n;
Node T[MAX+1];

void preorder(int u){
  cout << " " << u ;
  if ( T[u].l != NIL){
    preorder(T[u].l);
  }
  if ( T[u].r != NIL){
    preorder(T[u].r);
  }
}

void inorder(int u){
  if ( T[u].l != NIL){
    inorder(T[u].l);
  }
  cout << " " << u ;
  if ( T[u].r != NIL){
    inorder(T[u].r);
  }
}

void postorder(int u){
  if ( T[u].l != NIL){
    postorder(T[u].l);
  }
  if ( T[u].r != NIL){
    postorder(T[u].r);
  }
  cout << " " << u ;
}

int main(){
  cin >> n;
  int id, l, r, root = 0;

  for ( int i = 0; i < n; i++){T[i].p = T[i].r = T[i].l = NIL;}

  for ( int i = 0; i < n; i++){
    cin >> id >> l >> r;
    T[id].l = l;
    T[id].r = r;
    if ( l != NIL){ T[l].p = id; }
    if ( r != NIL){ T[r].p = id; }
  }

  while(T[root].p != NIL){
    root = T[root].p;
  }

  cout << "Preorder" << endl;
  preorder(root);
  cout << endl;

  cout << "Inorder" << endl;
  inorder(root);
  cout << endl;

  cout << "Postorder" << endl;
  postorder(root);
  cout << endl;

  return 0;
}



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

bool solve() {
    ll H, W;
    cin >> H >> W;
    vector<string> S(H);
    for ( int h = 0; h < H; h++ ) {
        cin >> S[h];
    }
    vector<int> dh = {0, 1, 0, -1}, dw = {1, 0, -1, 0}, hh = {0, 1, 0, 1};
    for ( int h0 = 0; h0 < H; h0++ ) {
        for ( int w0 = 0; w0 < W; w0++ ) {
            if ( S[h0][w0] == '#' ) {
                int c = 0;
                for ( int ii = 0; ii < 4; ii++ ) {
                    int h = h0 + dh[ii];
                    int w = w0 + dw[ii];
                    if ( h < 0 || h >= H || w < 0 || w >= W ) continue;
                    if ( S[h][w] == '#' ) c++;
                }
                if ( c == 0 ) return false;
            }
        }
    }
    return true;
}

int main() {
    string ans = solve() ? "Yes" : "No";
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
int main(){
  int n,m,i;
  long long a=1,b=1,ans=0;
  scanf("%d%d",&n,&m);
  for(i=1; i<=n; i++){
    a*=i;
    a%=1000000007;
  }
  for(i=1; i<=m; i++){
    b*=i;
    b%=1000000007;
  }
  if(abs(n-m)>=2){
    ans=0;
  }
  else if(n==m){
    ans=(a*b*2)%1000000007;
  }
  else{
    ans=(a*b)%1000000007;
  }
  printf("%lld\n",ans);
  return 0;
}


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

using namespace std;
using ll = long long;

int gcd(int a, int b) { return (b == 0) ? a : gcd(b, a % b); }

#define CIN(T, x) T x; cin >> x;
#define CINS(T, x, N) vector<T> x(N); for(int i = 0; i < (N); i++) { cin >> x[i]; }
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << " "; } cout << "\n";
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << "\n";


int main() {

    CIN(int, N);
    vector<ll> A(N+10, 0);

    A[0] = 0;
    A[N + 1] = 0;
    ll sum = 0;

    for (int i = 1; i <= N; i++) {
        cin >> A[i];
        sum += fabs(A[i] - A[i-1]);
    }
    sum += fabs(A[N + 1] - A[N]);

    for (int i = 1; i <= N; i++) {
        ll ans = sum;
        ans -= fabs(A[i] - A[i - 1]);
        ans -= fabs(A[i] - A[i + 1]);
        ans += fabs(A[i + 1] - A[i - 1]);
        cout << ans << "\n";
    }

    return 0;
}

Measured memory_bytes: 2048
from fractions import Fraction 
N,M = map(int,input().split())
A = list(map(int,input().split()))

ans = 0
for i in range(N):
    if A[i] >= sum(A)*Fraction(1,4*M):
        ans += 1
    else:
        continue

if ans >= M:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 10420
#include <bits/stdc++.h>
#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 FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VRSORT(v) sort(v.rbegin(), v.rend());//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  vector<vector<ll>> dp(1e5+10,vector<ll>(3,0));

  for(int i=0;i<n;i++){
    ll a,b,c;
    cin>>a>>b>>c;
      dp[i+1][0] = max(dp[i][1],dp[i][2])+a;//aを選ぶ
      dp[i+1][1] = max(dp[i][0],dp[i][2])+b;//bを選ぶ
      dp[i+1][2] = max(dp[i][0],dp[i][1])+c;//cを選ぶ
  }
  ll ans=0;
  REP(i,3){
    ans = max(ans,dp[n][i]);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 5760