akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define all(v) (v).begin() , (v).end()
#define popcnt(x) __builtin_popcount(x)
#define inf 0x3f3f3f3f
#define watch(x) cout << (#x) << " is " << (x) << endl
#define rand() (rand() << 15 | rand())
using namespace std;
typedef long long  ll;
#define EPS 1e-9
#define PI acos(-1.0)
int main() {
#ifndef ONLINE_JUDGE
#endif
   ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
   int n;
   cin >> n;
   string s , sorted;
   cin >> s;
   sorted = s;
   sort(all(sorted));
   int rs = 0;
   for(int i = 0 ; i < n ; ++i)
      rs += (sorted[i] != s[i]);
   cout << rs / 2 << "\n";
}

Measured memory_bytes: 3764
def main():
    n, a, b = map(int, input().split())
    r = (n // (a + b)) * a
    if n % (a + b) == 0:
        pass
    elif n % (a + b) > a:
        r += a
    elif n % (a + b) <= a:
        r += n % (a + b)
    print(r)
main()

Measured memory_bytes: 3060
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int Max = 1000000;
int main(){
  	int H, N;
  	cin >> H >> N;

  	int A;
  	int sum = 0;
  	for(int i=0;i<N;i++){
  		cin >> A;
  		sum += A;
  	}

  	if(sum >=H) cout << "Yes" <<endl;
  	else cout << "No" <<endl;


  	return 0;
}













Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const unsigned int MOD = 1000000007;
#define ll long long
#define PI 3.1416
#define Imax 1e9+5
#define LLmax 1e18
#define Imin -1e9-5
#define LLmin -1e18
string day [] = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
vector <string> v;
bool sortByFirst(const pair<int,int>&a,const pair<int,int>&b){
    return a.first>b.first;
}
void dfs (string str, string t = "", int cnt = 0) {
    if (cnt == 2) {
        v.push_back (t);
        return;
    } else {
        for (int i = 0; i <str.size (); i ++) {
            dfs (str, t + str [i], cnt + 1);
        }
    }
}
int main () {
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int h,n;
    while(cin>>h>>n){
        for(int i=1;i<=(h>=n?h:n);i++){
            h<=n?cout<<h:cout<<n;
        }
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int x = sc.nextInt();

        int patternCount = 0;
        for (int i = 0; i <= a; i++) {
            for (int j = 0; j <= b; j++) {
                for (int k = 0; k <= c; k++) {
                    int sum = (i*500) + (j * 100) + (50*k);
                    if (sum == x) patternCount++;
                }
            }
        }

        System.out.println(patternCount);
    }
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  string s, t;
  cin >> s >> t;
  cout << t << s << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    long double A;
    long double B;
    cin >> A >> B;
    cout << (ll)floor(A * B) << endl;
    return 0;
}

Measured memory_bytes: 3744
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PP;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
#define PI 3.141592653589
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
#define debug false
#define debug2 false

long long power(long long b,long long e){
  long long r=1;
  while(e){
      if(e&1){
          r=(r*b)%MOD;
      }
      b=(b*b)%MOD;
      e >>=1;
  }
  return r;
}


int main(void){
    ll N,M;
    cin >> N >> M;
    vector<ll> dp,dp2;
    vector<ll> pow2;
    pow2.push_back(1);
    REP(i,M){
        pow2.push_back((pow2[pow2.size()-1]*2)%MOD);
    }
    
    dp=pow2;
    dp2.resize(M+1,0);
    ll inv2 = power(2,MOD-2);
    
    
    //dp2[n][m]:=dp[n][m]*m*2^{-m}
    
    for(ll n=2;n<=N;n++){
        vector<ll> temp(M+1,0);
        
        //dp2[n][m]=dp[n][m]*m*2^{-m}
        ll invpow = inv2;
        for(ll m=1;m<=M;m++){
            dp2[m] = (((dp[m]*m)%MOD)*invpow)%MOD;
            invpow = (invpow*inv2)%MOD;
        }
        
        //tempはdp2の累積和
        for(ll m=1;m<=M;m++){
            if(m==1){
                temp[m]=dp2[m];
                temp[m]%=MOD;
            }else{
                temp[m]=temp[m-1]+dp2[m];
                temp[m]%=MOD;
            }
        }
        
        //そのtempに2^mをかける
        int pospow = 2;
        for(ll m=1;m<=M;m++){
            temp[m] = (temp[m]*pospow)%MOD;
            pospow = (pospow*2)%MOD;
        }
        
        //dpにm+1をかける
        for(ll m=1;m<=M;m++){
            dp[m] = (dp[m]*(m+1))%MOD;
        }
        
        //dp[m]とtemp[m-1]を足して完了
        for(ll m=2;m<=M;m++){
            dp[m] += temp[m-1];
            dp[m]%=MOD;
        }
        
        /*
        for(ll m=1;m<=M;m++){
            cout << dp[m] << " ";
        }cout << endl;
        */
    }
    
    cout << dp[M] << endl;
    
    
    return 0;
}



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

int main(){
    int N;
    cin >> N;
    int W[N] = {};
    for (int i = 0;i < N;i++){
        cin >> W[i];
    }
    int S[N] = {};
    S[0] = W[0];
    for (int i = 1;i < N;i++){
        S[i] = S[i - 1] + W[i];
    }
    int ans = abs(S[0] * 2 - S[N - 1]);
    for (int i = 0;i < N - 1;i++){
        if (ans > abs(S[i] * 2 - S[N - 1])) ans = abs(S[i] * 2 - S[N - 1]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
using namespace std;
using Graph=vector<vector<int>>;
inline int toInt(string s){int v;istringstream sin(s);sin>>v;return v;}
template<class T>inline string toString(T x){ostringstream sout;sout<<x;return sout.str();}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
  int N,ans=0;
  cin>>N;
  char S[N][2*N];
  REP(i,N){
    REP(j,N){
      cin>>S[i][j];
      S[i][j+N]=S[i][j];
    }
  }
  
  REP(k,N){
    bool CAN=true;
    for(int i=0; i<N; ++i){
      for(int j=0; j<=i; ++j){
        if(S[i][j+k]!=S[j][i+k]) CAN=false;
      }
    }
    
    if(CAN) ans++;
  }
  
  co(ans*N);
  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
using ll = long long;
using pii = pair<int,int>;
const int MOD = 1e9+7, N = 1e5 + 10; 

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   string s;
   cin >> s;
   int ans;
   if(s=="SUN"){
      ans = 7;
   }
   if(s=="MON"){
      ans = 6;
   }
   if(s=="TUE"){
      ans = 5;
   }
   if(s=="WED") ans = 4;
   if(s=="THU") ans = 3;
   if(s=="FRI") ans = 2;
   if(s=="SAT") ans = 1;
   cout << ans << '\n';
   return 0;
} 

Measured memory_bytes: 256
while True:
  ans = 0
  n, x = map(int, input().split())
  if n==0 and x==0:
    break
  for i in range(1,n+1):
    for j in range(i+1,n+1):
      for k in range(j+1,n+1):
        if i + j + k == x:
          ans += 1
  print(ans)




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

#define int long long
#define ll long long
#define pb push_back
#define mp make_pair
#define f(i,a,n) for(int i=a ; i<(int)n ; i++)
#define rf(i,n,a) for(int i=n ; i>=a ; i--)
#define F first
#define S second
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()
#define fast ios:: sync_with_stdio(false),cin.tie(nullptr);

typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef vector<pii> vpi;

const int inf = 1e9;
const int inf64 = 1e18;
const int MOD = inf + 7;

void solve(){
   string s;
   cin >> s;
   if(s == "ABC") cout << "ARC";
   else  cout << "ABC";
}

int32_t main(){
   fast;
   int t = 1;
//   cin >> t;
   while(t--)  solve();   
}

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

#define rep(i, n) for(int i = 0; i < n; ++i)
#define rrep(i, n) for(int i = n - 1; i > -1; --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
const long long INF = 1000000000;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<int, int> P;

int main() {
    string s;
    cin >> s;
    if(s[0] == s[1] || s[1] == s[2] || s[2] == s[3] || s[3] == s[4]){
        cout << "Bad" << endl;
    }else{
        cout << "Good" << endl;
    }
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define enld endl //* missspell check
const ll INF = 1LL << 60;


void solve(long long X, long long Y, long long Z){
    swap(X, Y); swap(X, Z);
    cout<<X<<" "<<Y<<" "<<Z<<endl;
}

int main(){
    long long X;
    scanf("%lld",&X);
    long long Y;
    scanf("%lld",&Y);
    long long Z;
    scanf("%lld",&Z);
    solve(X, Y, Z);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<list>
#include<set>
#include<string>
using namespace std;
int gcd(int a, int b) {
	int c = a % b;
	while (c != 0) {
		a = b;
		b = c;
		c = a % b;
	}
	return b;
}
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;
	}
};
typedef long long ll;

ll M = 1000000007;

vector<ll> fac(300001); //n!(mod M)
vector<ll> ifac(300001); //k!^{M-2} (mod M)

ll mpow(ll x, ll n) {
	ll ans = 1;
	while (n != 0) {
		if (n & 1) ans = ans * x % M;
		x = x * x % M;
		n = n >> 1;
	}
	return ans;
}
void setcomb() {
	fac[0] = 1;
	ifac[0] = 1;
	for (ll i = 0; i < 300000; i++) {
		fac[i + 1] = fac[i] * (i + 1) % M; // n!(mod M)
		ifac[i + 1] = ifac[i] * mpow(i + 1, M - 2) % M; // k!^{M-2} (mod M) ←累乗にmpowを採用
	}
}
ll comb(ll a, ll b) {
	if (a == 0 && b == 0)return 1;
	if (a < b || a < 0)return 0;
	ll tmp = ifac[a - b] * ifac[b] % M;
	return tmp * fac[a] % M;
}
// mod. m での a の逆元 a^{-1} を計算する
long long modinv(long long a) {
	long long b = M, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= M;
	if (u < 0) u += M;
	return u;
}
vector<vector<ll>> mul(vector<vector<ll>> a, vector<vector<ll>> b, int n) {
	int i, j, k, t;
	vector<vector<ll>> c(n);
	for (i = 0; i < n; i++) {
		for (j = 0; j < n; j++) {
			t = 0;
			for (k = 0; k < n; k++)
				t = (t + a[i][k] * b[k][j] % M) % M;
			c[i].push_back(t);
		}
	}
	return c;
}

template< typename Monoid >
struct SegmentTree {

	int sz;
	vector< Monoid > seg;

	const Monoid M1;

	SegmentTree(int n, const Monoid &M1) : M1(M1) {
		sz = 1;
		while (sz < n) sz <<= 1;
		seg.assign(2 * sz, M1);
	}

	void set(int k, const Monoid &x) {
		seg[k + sz] = x;
	}

	void build() {
		for (int k = sz - 1; k > 0; k--) {
			seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
		}
	}

	void update(int k, const Monoid &x) {
		k += sz;
		seg[k] = x;
		while (k >>= 1) {
			seg[k] = f(seg[2 * k + 0], seg[2 * k + 1]);
		}
	}

	Monoid query(int a, int b) {
		Monoid L = M1, R = M1;
		for (a += sz, b += sz; a < b; a >>= 1, b >>= 1) {
			if (a & 1) L = f(L, seg[a++]);
			if (b & 1) R = f(seg[--b], R);
		}
		return f(L, R);
	}

	Monoid value(const int &k) const {
		return seg[k + sz];
	}

	Monoid f(Monoid a, Monoid b) {
		return a + b;
	}
};

int main() {
	ll n, x[222222],cx[222222], i;
	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> x[i];
		cx[i] = x[i];
	}
	sort(cx, cx + n);
	for (i = 0; i < n; i++) {
		if (x[i] > cx[n / 2 - 1])
			cout << cx[n / 2 - 1] << endl;
		else
			cout << cx[n / 2] << endl;
	}
}

Measured memory_bytes: 10112
from itertools import permutations


def main():
    n, m = map(int, input().split())

    path = [[False for _ in range(n)] for _ in range(n)]

    for i in range(m):
        a, b = map(int, input().split())
        a -= 1
        b -= 1
        path[a][b] = True
        path[b][a] = True

    res = 0
    perms = list(permutations(list(range(1, n)), n - 1))
    for p in perms:
        visited = 1
        prev = 0
        for now in p:
            if path[prev][now]:
                visited += 1
                prev = now
            else:
                break
        if visited == n:
            res += 1

    print(res)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9388
def partition(A,p,r):
  x = A[r-1]
  i = p-1
  for j in range(p,r-1):
    if A[j] <= x:
      i += 1
      A[i],A[j] = A[j],A[i]
  A[i+1],A[r-1] = A[r-1],A[i+1]
  return i+1
n = int(input())
A = [int(i) for i in input().split()]
idx = partition(A,0,n)
A[idx] = "["+str(A[idx])+"]"
print(" ".join(map(str,A)))


Measured memory_bytes: 16368
#include <iostream>

int main()
{
    int h, w;
    std::cin >> h >> w;

    std::string alpha = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            std::string s;
            std::cin >> s;

            if (s == "snuke") {
                std::cout << alpha[j] << i + 1 << std::endl;
            }
        }
    }
}


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

int main() {
    int n; cin >> n;
    vector<int> a[2];
    for (int t = 0; t < 2; t++) {
        a[t].resize(n);
        for (int i = 0; i < n; i++) 
            cin >> a[t][i];
    }
    long long bal = 0;
    for (int i = 0; i < n; i++) {
        auto d = a[0][i]-a[1][i];
        if (d > 0) bal -= d;
        if (d < 0) bal += (-d)/2;
    }
    cout << (bal >= 0 ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 384
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<algorithm>


using namespace std;
using vi=vector<int>;
using ll=long long;


ll calc(vi&a)
{
	ll ret=0;
	int n=a.size();

	for(int i=1;i<n;i++)
	{
		ret+=abs(a[i]-a[i-1]);
	}
	return ret;
}


void max_u(ll&m, ll v)
{
	if(m<v) m=v;
}


int main(void)
{
	int n;

	while(scanf("%d", &n)==1)
	{
		vi a(n), b(n);
		int h=n/2;
		ll ans=0;

		for(int i=0;i<n;i++) scanf("%d", &a[i]);
		sort(a.begin(), a.end());

		if((n&1)==0) h--;
		{
			int p=h, f=h+1;
			int s=0, e=n-1;
			for(;;)
			{
				b[p--]=a[s++];
				if(s>e) break;
				b[f++]=a[e--];
				if(s>e) break;
				b[p--]=a[e--];
				if(s>e) break;
				b[f++]=a[s++];
				if(s>e) break;
			}
//			for(auto mb:b) printf("%d ", mb); printf("\n");
			max_u(ans, calc(b));
		}

		sort(a.rbegin(), a.rend());

		{
			int p=h, f=h+1;
			int s=0, e=n-1;
			for(;;)
			{
				b[p--]=a[s++];
				if(s>e) break;
				b[f++]=a[e--];
				if(s>e) break;
				b[p--]=a[e--];
				if(s>e) break;
				b[f++]=a[s++];
				if(s>e) break;
			}
//			for(auto mb:b) printf("%d ", mb); printf("\n");
			max_u(ans, calc(b));
		}

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

	return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<string>
using namespace std;
int main(){
    int n,i,sum1=0,sum2=0;
    string h,t;
    cin >> n;
    for(i=0;i<n;i++){
        cin >> t >> h;
        if (h == t) sum1++,sum2++;
        else if (h > t) sum2+=3;
        else sum1+=3;
    }
    cout << sum1 << " " << sum2 << endl;
}


Measured memory_bytes: 3148
#include <vector>
#include <iostream>
using namespace std;
const int mod = 100000;
int H, W;
int main() {
	H = W = 100;
	vector<vector<vector<int> > > dp(H, vector<vector<int> >(W, vector<int>(2)));
	dp[0][0][0] = dp[0][0][1] = 1;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			for (int k = i - (j ? 2 : 1); k >= 0; k--) dp[i][j][0] += dp[k][j][1];
			for (int k = j - (i ? 2 : 1); k >= 0; k--) dp[i][j][1] += dp[i][k][0];
			dp[i][j][0] %= mod;
			dp[i][j][1] %= mod;
		}
	}
	while (cin >> H >> W, H) {
		cout << (dp[H - 1][W - 1][0] + dp[H - 1][W - 1][1] + dp[H - 2][W - 1][1] + dp[H - 1][W - 2][0]) % mod << endl;
	}
	return 0;
}

Measured memory_bytes: 3576
#include<iostream>
#include <math.h>

using namespace std;

int main(){
    int D, N;
    cin >> D >> N;
    if(N==100){
        cout << int(pow(100,D)) * (N+1) << endl;
    }else{
        cout << int(pow(100,D)) * N << endl;
    }
}

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

int main(){
    int N,L,abs,x,eat,ans;
    cin >> N >> L;
    abs = 1000;
    for (int i=0;i<N;i++){
        x = L + i;
        if (L+i<0){
            x *= -1;
        }
        if (x<abs){
            abs = x;
            eat = i;
        }
    }
    for (int i=0;i<N;i++){
        if (i!=eat){
            ans += L+i;
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
 
using namespace std;
 
int main()
{
    string S("");
    string T("");
    cin >> S;
    cin >> T;
    int out=0;
    for(int i=0;i<S.length();++i){
      if (S[i]!=T[i]){
         out++ ;
      }
    }
     cout << out  << endl;
      
     return 0; 
}

Measured memory_bytes: 3836
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int main(){
  int n;
  double x,y;
  int cnt = 1;  
  while( cin >> n,n ){
    double sum = 0;
    cin >>  x >> y;
    double oldx = x,oldy = y;
    double fx = x,fy = y;
    for(int i = 1 ; i <= n ; i++ ){
      if(i == n){
	sum+= (oldx - fx)*(oldy + fy);
	break;
      }
      cin >>  x >> y;
      sum += (oldx - x)*(oldy + y);
      oldx = x;
      oldy = y;
    }
    printf("%d %.1f\n",cnt,fabs(sum/2));
    cnt++; 
  }
  return 0;
}

Measured memory_bytes: 1244
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
int main(void){
    int n;
    cin>>n;
    double a[n];
    for(int i=0;i<n;i++) cin>>a[i];
    sort(a,a+n);
    double b=(a[0]+a[1])/2;
    for(int i=2;i<n;i++){
        b=(b+a[i])/2;
    }
    printf("%.6f", b);
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
kaisuu = 0
while a[0]%2 == 0:
    for i in range(n):
        if a[i]%2 == 0:
            a[i] /= 2
            if i == n-1:
                kaisuu += 1
        else:
            break
else:
    print(kaisuu)

Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<cctype>
#include<climits>
#include<bitset>
#define ld long double
#define ll long long int
#define ull unsigned long long int
#define rep(i,n) for(i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define INF INT_MAX
#define vi vector<int>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define vvc vector<vector<char> >
#define vvs vector<vector<string> >
#define P 1000000007
using namespace std;
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;}
const long long LLINF=1LL<<60;
//set<int>::iterator it;
//|\_
//g++ -std=c++1z temp.cpp
//./a.out





int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
    
    string s,t;
    cin>>s>>t;
    sort(s.begin(),s.end());
    sort(t.rbegin(),t.rend());
    if(s<t)fin("Yes");
    else cout<<"No"<<endl;
    
//////////////////////////////////////////////////////
return 0;}


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {

  long n,k;
  scanf("%ld %ld", &n, &k);
  long x[n];
  for (long i = 0; i < n; i++) {
    scanf("%ld", &x[i]);
  }
  long min = -1;
  long time;
  for (long i = 0; i+k <= n; i++) {
    if (x[i+k-1] <= 0) {
      time = -x[i];
    } else if (x[i] < 0 && x[i+k-1] > 0) {
      if (-x[i] <= x[i+k-1]) {
        time = -x[i]*2+x[i+k-1];
      } else {
        time = -x[i]+x[i+k-1]*2;
      }
    } else {
      time = x[i+k-1];
    }
    if (min == -1 || time < min) {
      min = time;
    }
  }
  printf("%ld\n", min);

  return 0;
}

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

n, m = map(int, input().split())
g = [[] for _ in range(n)]
d = {}
for i in range(n):
    kl = list(map(int, input().split()))
    L = kl[1:]
    L = [l-1 for l in L]
    for l in L:
        if l not in d:
            d[l] = i
        else:
            g[d[l]].append(i)
            g[i].append(d[l])

from collections import deque
s = deque()
s.append(0)
visit = [-1]*n
visit[0] = 0
while s:
    x = s.pop()
    for nx in g[x]:
        if visit[nx] == -1:
            visit[nx] = 0
            s.append(nx)
if min(visit) != -1:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 62256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int a, b;
    cin >> a >> b;
    if(a == b)
    {
        cout << a + b << endl;
    }
    else if(a > b)
    {
        cout << a + a - 1 << endl;
    }
    else
    {
        cout << b +  b - 1 << endl;
    }
}



Measured memory_bytes: 256
import sys

N=int(input())
A=list(map(int,input().split()))
M=10**9+7

G={k:0 for k in range(-1,max(A)+1)}
G[-1]=3

X=1
for a in A:
    X*=G[a-1]-G[a]
    X%=M
    G[a]+=1
print(X)


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

int main(){
  int n;
  string a, b, c;
  cin >> n >> a >> b >> c;
  int ret=0;
  for(int i=0; i<n; i++){
    if(a[i]!=b[i] && b[i]!=c[i] && c[i]!=a[i])ret+=2;
    else if(a[i]==b[i] && b[i]==c[i])continue;
    else ret+=1;
  }
  cout << ret;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <string>
#define REP(i,n) for (int i=0;i<(n);i++)
using namespace std;

int main(){
    int n, x = 0, ans = 0;
    cin >> n;
    string s;
    cin >> s;

    REP(i, n){
        if(s[i] == 'I') ++x;
        else --x;
        ans =  max(x, ans);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <chrono>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;

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

void solve() {
  int n, k;
  cin >> n >> k;
  vector<int> v;
  for(int i = 0; i < n; i++) {
    int t;
    cin >> t;
    v.push_back(t);
  }
  int ret = 0;
  for(int lhs = 0; lhs <= k; lhs++) {
    for(int rhs = 0; lhs + rhs <= k && lhs + rhs <= n; rhs++) {
      vector<int> curr = v;
      vector<int> avail;
      for(int i = 0; i < lhs; i++) {
        avail.push_back(curr[0]);
        curr.erase(curr.begin());
      }
      for(int i = 0; i < rhs; i++) {
        avail.push_back(curr.back());
        curr.pop_back();
      }
      sort(avail.begin(), avail.end());
      for(int i = lhs+rhs+1; i <= k && avail.size() && avail[0] < 0; i++) avail.erase(avail.begin());
      int cand = 0;
      for(int out: avail) cand += out;
      ret = max(ret, cand);
    }
  }
  cout << ret << endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL); cout.tie(NULL);
  /*
  int t;
  cin >> t;
  for(int i = 1; i <= t; i++) {
    cout << "Case #" << i << ": ";
    solve();
  }
  */
  solve();
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
using namespace std;

#define Rep(b, e, i) for(int i = b; i <= e; i++)
#define rep(n, i) Rep(0, n-1, i)

void solve(void){
    int a, b, c, d;
    scanf("%d%d%d%d\n", &a, &b, &c, &d);
    int dx = c-a, dy = d-b;
    rep(dy, i) putchar('U');
    rep(dx+1, i) putchar('R');
    rep(dy+1, i) putchar('D');
    rep(dx+1, i) putchar('L');
    rep(1, i) putchar('U');
    rep(1, i) putchar('L');
    rep(dy+1, i) putchar('U');
    rep(dx+1, i) putchar('R');
    rep(dy+1, i) putchar('D');
    rep(dx, i) putchar('L');
    printf("\n");
}

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


Measured memory_bytes: 256
from operator import itemgetter
import bisect
from itertools import accumulate
N, W = map(int, input().split())
WV = [list(map(int, input().split())) for _ in range(N)]
WV.sort(key=itemgetter(0, 1))
w, v = zip(*WV)
w0 = w[0]
w1 = w0 + 1
w2 = w1 + 1
w3 = w2 + 1
i0 = bisect.bisect_left(w, w0)
i1 = bisect.bisect_left(w, w1)
i2 = bisect.bisect_left(w, w2)
i3 = bisect.bisect_left(w, w3)
v0 = sorted(v[i0:i1], reverse=True)
v1 = sorted(v[i1:i2], reverse=True)
v2 = sorted(v[i2:i3], reverse=True)
v3 = sorted(v[i3:], reverse=True)
a0 = list(accumulate(v0)) + [0]
a1 = list(accumulate(v1)) + [0]
a2 = list(accumulate(v2)) + [0]
a3 = list(accumulate(v3)) + [0]
n0 = 1 + len(v0)
n1 = 1 + len(v1)
n2 = 1 + len(v2)
n3 = 1 + len(v3)

ans = 0
for i0 in range(n0):
    for i1 in range(n1):
        for i2 in range(n2):
            for i3 in range(n3):
                if i0*w0 + i1*w1 + i2*w2 + i3*w3 <= W:
                    ans = max(ans, a0[i0-1]+a1[i1-1]+a2[i2-1]+a3[i3-1])
print(ans)



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


/*  
    
*/

void test_case(){
    int n; cin >> n;
    int a[n], b[n];
    
    for(int i = 0; i < n; i++){
        cin >> a[i] >> b[i];
    }
    
    for(int i = 0; i < n-2; i++){
        if( a[i] == b[i] && a[i+1] == b[i+1] && a[i+2] == b[i+2] ){
            cout << "Yes";
            return;
        }
    }
    cout << "No";
}

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

    int t; t = 1;
    //cin >> t;
    while(t--)
        test_case();
    return 0;
}


Measured memory_bytes: 3648
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int max = 0;
		int maxValue = 0;
		for (int i = 0; i < n; i++) {
			int a = sc.nextInt();
			int b = sc.nextInt();
			if (max < a) {
				max = a;
				maxValue = b;
			}
		}
		System.out.println(max + maxValue);
	}
}


Measured memory_bytes: 64584
#include <iostream>
#include <algorithm>

using namespace std;

main(){
  char in;
  int k = 0, u = 0, p = 0, c = 0;
  while(cin >> in){
    if(in == 'K') k++;
    if(in == 'U') u++;
    if(in == 'P') p++;
    if(in == 'C') c++;
  }
  cout << min(k, min(u, min(p, c))) << endl;
  return 0;
}

Measured memory_bytes: 0
def main():
    n = int(input())
    alis = sorted(map(int, input().split()))
    total = sum(alis)
    adic = {}
    for num in alis:
        if num in adic:
            adic[num] += 1
        else:
            adic[num] = 1
    
    anslis = []

    q = int(input())
    bclis = []
    for i in range(q):
        b, c = map(int,input().split())
        if b in adic:
            kazu = adic[b]
            adic[b] = 0
            total -= b * kazu
            if c in adic:
                adic[c] += kazu
            else:
                adic[c] = kazu
            total += c * kazu
        print(total)
    
    
if __name__ == "__main__":
    main()


Measured memory_bytes: 93436
#include <iostream>
#include <cmath>


using namespace std;

int main(void)
{
    int a, b;
    cin >> a >> b;
    int sum = a + b;
    if(sum < a - b){
        sum = a - b;
    }
    if(sum < a * b){
        sum = a * b;
    }

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 256
class dice:
    def __init__(self, label):
        self.d = label

    def roll(self, op):
        d = self.d
        if op == 'N':
            self.d = [d[1], d[5], d[2], d[3], d[0], d[4]]
        elif op == 'E':
            self.d = [d[3], d[1], d[0], d[5], d[4], d[2]]
        elif op == 'W':
            self.d = [d[2], d[1], d[5], d[0], d[4], d[3]]
        elif op == 'S':
            self.d = [d[4], d[0], d[2], d[3], d[5], d[1]]
label=list(map(int,input().split()))
oplist=list(input())
do=dice(label)
for op in oplist :
        do.roll(op)
print(do.d[0])

Measured memory_bytes: 7768
# https://atcoder.jp/contests/abc042/tasks/arc058_a


def exist(target, array):
    for token in list(str(target)):
        if token in array:
            return True
    return False


n, _ = map(int, input().split())
d = input().split()

x = n
while True:
    if not exist(x, d):
        break
    x += 1

print(x)


Measured memory_bytes: 2940
process.stdin.resume();
process.stdin.setEncoding('utf8');

var g_input = '';
process.stdin.on('data', function(chunk) {
    g_input += chunk;
});

process.stdin.on('end', function() {
    Main(g_input.split(/\r?\n/));
});

function Main(input) {
    var n = parseInt(input[0], 10);
    var k = parseInt(input[1], 10);
    var xstrs = input[2].split(' ');
    var x = new Array(n);
    for (var i = 0; i < n; i++) {
        x[i] = parseInt(xstrs[i], 10);
    }

    var total = 0;
    for (var i = 0; i < n; i++) {
        var move = Math.min(x[i], k - x[i]);
        total += move * 2;
    }

    console.log(total);
    return 0;
}


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

int l;
ll dp[200005][5];
ll solve(vector<ll>a){
    memset(dp,0,sizeof(dp));
   dp[0][0]=1;
   for(int i=1;i<=l;i++){
    for(int j=1;j<=5;j++){
        dp[i][j]=1001002003004005006ll;
        for(int k=1;k<=j;k++){
            chmin(dp[i][j],dp[i-1][k]);
             } 
        if(j==1||j==5)dp[i][j]+=a[i-1];
        else if(j==2||j==4)
        {
            if(a[i-1]==0)dp[i][j]+=2;
            else if(a[i-1]%2==0)continue;
            else dp[i][j]+=1;
        }else{
            if(a[i-1]%2==1)continue;
            else dp[i][j]+=1;
        }  
    }
   }
   ll ans=1001002003004005006ll;
   for(int j=1;j<=5;j++)chmin(ans,dp[l][j]);
    return ans;
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);

    cin>>l;
    vector<ll>a(l);
    rep(i,l)cin>>a[i];
    cout<<solve(a)<<endl;
    return 0;
}

Measured memory_bytes: 11264
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<ll,ll> P;
typedef pair<P,long double> Pi;
typedef pair <long double,int> Pd;
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
set<int> mp[200005];
ll dp[200005];
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
int n;cin>>n;
vector<int> c(n);
for(int i=0;i<n;i++)cin>>c[i];
c.erase(unique(all(c)),c.end());
for(int i=0;i<c.size();i++){
   mp[c[i]].insert(i);
}
dp[0]=1;
for(int i=0;i<c.size();i++){
   auto ite=mp[c[i]].find(i);
 if(ite!=mp[c[i]].begin()){
   ite--;
  (dp[i]+=dp[*ite])%=mod;
  }
  (dp[i+1]+=dp[i])%=mod;
   }
cout<<dp[c.size()]<<endl;
}



Measured memory_bytes: 21376
mod = 1000000007
n = int(input())
a = list(map(int, input().split()))

lap = 0
big = max(a)
while big > 0:
    big //= 2
    lap += 1

xor = [0 for _ in range(lap)]
for i in a:
    num = 0
    for j in range(lap):
        if i % 2 == 1:
            xor[num] += 1
        i //= 2
        num += 1

ans = 0
for i in range(lap):
    ans += pow(2, i, mod) * xor[i] * (n - xor[i]) % mod
    ans %= mod

print(ans)

Measured memory_bytes: 125624
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <climits>
#include <map>
#include <set>
const int mod = 1e9 + 7;
const int inf = 1 << 20;
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
using namespace std;


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

    for(int i = 0; i < s.size(); i++){
        if(s[i] + n <= 'Z'){
            char c =s[i] + n;
          cout << c;
        }else{
            char c = s[i] + n - ('Z'-'A')-1;
            cout << c;
        }
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<iostream>
#include<vector>
#include<utility>
#include<functional>
#include<algorithm>
#include<queue>
#include<map>
#include<string>
#include<numeric>


#define FOR(i, a, b) for(int i=a; i<b; i++)
#define COUT(a) cout << a << endl;

using namespace std;
using Int = long long;
using P = pair<Int, Int>;


int main(){
    Int N, M, X, Y;
    cin >> N >> M >> X >> Y;
    
    vector<Int> x(N);
    vector<Int> y(M);
    Int max_x = X, min_y = Y;


    FOR(i, 0, N){
        cin >> x[i];
        max_x = max(max_x, x[i]);
    }

    FOR(i, 0, M){
        cin >> y[i];
        min_y = min(min_y, y[i]);
    }

    if (max_x < min_y){
        COUT("No War");
    }else {
        COUT("War");
    }
    
}


Measured memory_bytes: 256
// A or...or B Problem
// * frank_c1
// * 2017 / 11 / 09
 
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
 
int a[100], b[100];
 
int main() {
	LL x; 
	scanf("%lld", &x);
	for (; x; x >>= 1) a[++a[0]] = x & 1;
	scanf("%lld", &x);
	for (; x; x >>= 1) b[++b[0]] = x & 1;
	if (a[0] == b[0]) {
		while (a[0] && a[a[0]] == b[b[0]]) --a[0], --b[0];
		while (a[0] && !a[a[0]]) --a[0]; 
		if (!a[0]) return printf("%lld\n", 1LL << b[0]), 0;
	}
	LL tmp = 0;
	for (int i = a[0]; i; --i) tmp = tmp * 2 + a[i];
	LL ret = (1LL << (b[0] - 1)) - tmp; int succ = 0;
	ret += ((1LL << (b[0] - a[0] - 1)) - 1) * (1LL << a[0]); b[b[0]] = 0;
	while (b[0] > a[0] + 1) if (b[b[0]--]) succ = 1; if (b[b[0]]) succ = 1; 
	if (succ) return printf("%lld\n", ret + (1LL << a[0])), 0;
	int p; for (p = a[0]; p && !b[p]; --p); ret += (1LL << p); tmp = 0; 
	if (a[0] == p) return printf("%lld\n", ret), 0; 
	for (int i = a[0]; i > p; --i) tmp = tmp * 2 + a[i]; 
	tmp = (1LL << (a[0] - p)) - tmp - 1; ret += tmp * (1LL << p); 
	do {
		while (p && a[p]) --p;
		int q = p; while (q && !a[q]) --q;
		ret += ((1LL << (p - q)) - 1) * (1LL << q); p = q; if (!p) ++ret;
	} while (p);
	return printf("%lld\n", ret), 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f(i,j,k) for(int i=j;i<k;i++)
using namespace std;
int main(){
    long long n,m;
    cin>>n>>m;
    long long v[n],w[n],dp[n+1][m+1];
    f(i,0,n){
        cin>>v[i]>>w[i];
    }
    
    for(int i=0;i<m+1;i++){
        dp[0][i]=0;
    }
    for(int i=0;i<n;i++){
        for(int j=0;j<m+1;j++){
            if(j>=w[i]) dp[i+1][j]=max(dp[i][j-w[i]]+v[i],dp[i][j]);
            else dp[i+1][j]=dp[i][j];
        }
    }
    cout<<dp[n][m]<<endl;
    return 0;
}


Measured memory_bytes: 11012
#include <iostream>
#include <map>
using namespace std;
using llong = long long;

llong n;
llong a[100005];
map<llong, llong> cnt;
llong sum = 0;

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

    llong q;
    cin >> q;
    while (q--) {
        llong b, c;
        cin >> b >> c;

        sum -= b * cnt[b];
        sum += c * cnt[b];
        cnt[c] += cnt[b];
        cnt[b] = 0;

        cout << sum << '\n';
    }

}


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

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;

typedef int _loop_int;
#define REP(i,n) for(_loop_int i=0;i<(_loop_int)(n);++i)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

const ll MOD = 1000000007ll;
#define FIX(a) ((a)%MOD+MOD)%MOD
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) { a = b; return true; }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) { a = b; return true; }
    return false;
}
int n;
ll v[100005][3];
ll dp[100005][3];

const int a = 0;
const int b = 1;
const int c = 2;

int main() {
    cin>>n;
    REP(i,n){
        cin>>v[i][a]>>v[i][b]>>v[i][c];
    }

    REP(day,n){
        REP(i,3) REP(j,3){
            if(i==j) continue;
            chmax(dp[day+1][j], dp[day][i]+v[day][j]);
        }
    }

    ll ans = 0;

    REP(i,3) ans = max(ans, dp[n][i]);

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

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
const int INF=1001001000;
const int mINF=-1001001000;
const ll LINF=1010010010010010000;
template<class T> inline bool chmin(T& a, T b) {
if (a > b) {
a = b;
return true;
}
return false;
}
template<class T> inline bool chmax(T& a, T b) {
if (a < b) {
a = b;
return true;
}
return false;
}
int main(){
    int n;cin >> n;
    vl a(n);
    rep(i,n) cin >> a[i];
    sort(a.rbegin(),a.rend());
    int mx=a[0];
    int hf=a[0]/2;
    int hf2=(a[0]+1)/2;
    int d=hf;
    int ans=-1;
    for(int i=1;i<n;i++){
        if(min(abs(hf-a[i]),abs(hf2-a[i]))<=d){
            d=min(abs(hf-a[i]),abs(hf2-a[i]));
            ans=a[i];
        }
    }
    cout << a[0] << " " << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
import copy
import bisect as b
n=int(input())
l=[3,5,7]
s=[3,5,7]
ll=[]
for i in range(8):
    w=copy.deepcopy(l)
    for j in w:
        for k in s:
            l.append(int(str(j)+str(k)))
for i in range(len(l)):
    if len(set(str(l[i])))==3:
        ll.append(l[i])
ll=list(set(ll))
ll.sort()
print(b.bisect(ll,n))

Measured memory_bytes: 15548
NM = [int(x) for x in input().split()]
N = NM[0]
M = NM[1]
X = [int(x) for x in input().split()]
X.sort()
#print(X)
LL = 0
if N > M:
    print(LL)
else:
    L = [0] * (M - 1)
    for i in range (0, M - 1):
        L[i] = X[i + 1] - X[i]
    L.sort()
    #print(L)
    for i in range(0, M - N):
        LL += L[i]
    print(LL)

Measured memory_bytes: 13840
#include <bits/stdc++.h>
using namespace std;
const long long inf = 1e18;
typedef long long ll;
#define rp(i, f, t) for (int i = f; i < t; i++)
#define pr(i, f, t) for (int i = t - 1; i >= f; i--)
int main()
{
    ll n;
    cin >> n;
    ll p[n];
    rp(i, 0, n) cin >> p[i];
    ll m = inf;
    ll ans = 0;
    rp(i, 0, n)
    {
        if (p[i] < m)
            ans++;
        m = min(m, p[i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <climits>
#include <cstdlib>
using namespace std;

int N, W;

long long dp[110][100100];
int w[110];
int v[110];

int main() {
  cin >> N >> W;
  for (int i = 0; i < N; i++) {
    cin >> w[i];
    cin >> v[i];
  }
  for (int i = 0; i < 100100; i++) {
    dp[0][i] = 0;
  }

  for (int i = 0; i < N; i++) {
    for (int sw = 0; sw <= W; sw++) {
      if (sw >= w[i]) {
        if (dp[i][sw-w[i]] < (dp[i][sw-w[i]] + v[i])) {
          dp[i+1][sw] = dp[i][sw-w[i]] + v[i];
        }
      }
      if (dp[i+1][sw] < dp[i][sw]) {
        dp[i+1][sw] = dp[i][sw];
       }
    }
  }

  cout << dp[N][W] << endl;
  return 0;
}

Measured memory_bytes: 80128
using System;
using System.Collections.Generic;

namespace ABC106A
{
    class MainClass
    {
        public static void Main(string[] args)
        {

            // N M みたいな入力
            string[] input1 = Console.ReadLine().Split(' ');
            int A = int.Parse(input1[0]);
            int B = int.Parse(input1[1]);  



            //出力
            Console.WriteLine((A-1)*(B-1));
        }
    }
}


Measured memory_bytes: 13140
#include<bits/stdc++.h>
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3f
#define EPS (1e-10)
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int>P;

signed main() {
	ll n; cin >> n;
	int Min = INT_MAX;
	for (ll i = 1; i*i <= n; i++) {
		if (n%i == 0)Min = min(Min, (int)max(to_string(i).size(), to_string(n / i).size()));
	}
	printf("%d\n", Min);
}

Measured memory_bytes: 256
#pragma GCC target (*sse4.2*)
#pragma GCC optimization ("O3")
#pragma GCC optimize ("Ofast")
#define mod 1000000007
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define PB push_back
#define all(x) x.begin(),x.end()
#define vi vector<int>
#define ii pair<int,int>
#define vii vector<ii>
#define vvii vector<vii>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define read(x) long long x;cin>>x;
#define FOR(a,b,c,d) for(int a=b;a<=c;a+=d)
#define MP make_pair
#define F first
#define S second
#define debug(x) cout<<("#x)<<": "<<(x)<<"\n"
#define SZ(x) x.size()
#define INF (1<<63)-1

using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> pbds;
typedef long long ll;
typedef unsigned long long ull;
typedef long double d64;

const int N=10000001;
vector<int>c(10000001);

void Cribe(){
for(int i=0;i<=N;i++){
    c[i]=i;
}
c[0]=c[1]=-1;
for(int i=2;i*i<=N;i++){
    if(c[i]==i)
        for(int j=i+i;j<=N;j+=i)
        c[j]=i;

}
}
int divi=1;
void fp(int x){
    if(x<=1)return;
    int a=1;
    int y=x/c[x];
    while(c[x]==c[y]){
        a++;
        y=y/c[y];
    }
    divi=divi*(a+1);
    fp(y);
}

int main(){
fast
ull sum=0;
Cribe();
read(n);
for(long long i=1;i<=n;i++){
    fp(i);
 sum=(ull)sum+(divi*i);
divi=1;
}
cout<<sum;
return 0;
}


Measured memory_bytes: 42184
#include <algorithm>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <queue>
#include <stack>
#include <utility>
#include <vector>
using std::cin;
using std::cout;
using std::endl;

int main(void) {
    cout << std::fixed << std::setprecision(10);
    cin.tie(0);
    std::ios::sync_with_stdio(false);
    int64_t n, a;
    std::vector<int> vec;
    int64_t dp[50][51][2501] = {};
    cin >> n >> a;
    for (int i = 0; i < n; i++) {
        int m1;
        cin >> m1;
        vec.push_back(m1);
    }

    dp[0][0][0]      = 1;
    dp[0][1][vec[0]] = 1;

    for (int s = 1; s < n; s++) {
        for (int t = 0; t <= n; t++) {
            for (int u = 0; u <= n * a; u++) {
                dp[s][t][u] += dp[s - 1][t][u];
                if (t > 0) {
                    if (u - vec[s] >= 0) {
                        dp[s][t][u] += dp[s - 1][t - 1][u - vec[s]];
                    }
                }
                // cout << s << " " << t << " " << u << " " << dp[s][t][u] <<
                // endl;
            }
        }
    }

    int64_t result = 0;
    for (int t = 1; t <= n; t++) {
        for (int u = 1; u <= n * a; u++) {
            if (a * t == u) {
                result += dp[n - 1][t][u];
                //cout << t << " " << u << " " << dp[n - 1][t][u] << endl;
            }
        }
    }

    cout << result << endl;

    return 0;
}


Measured memory_bytes: 50048
#include <bits/stdc++.h>
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define divceil(A, B) ((A + (B - 1)) / B)
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()
#define CERR if(false) cerr

typedef long long ll;

using namespace std;

int main(){

    int n;
    cin >> n;

    vector<int> v;

    rep(i,n){
        int tmp;
        cin >> tmp;

        v.pback(tmp);
    }

    int ans = 0;

    for(int i = 0; i < n - 1; i++){
        for(int j = i + 1; j < n; j++){
            ans += v[i] * v[j];
        }
    }

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


Measured memory_bytes: 256