akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cassert>
using namespace std;
#define rep(i,n) for(int i = 0 ; i < n ; i++)
int W,H , d[22][22];
int ans;

int dx[] = {-1,0,1,0} , dy[] = {0,1,0,-1};
void f(int x,int y,int depth){
	if(depth >= ans) return;
	for(int i = 0 ; i < 4 ; i++){
		int tx = x + dx[i] , ty = y + dy[i];
		if(d[ty][tx] == 0 || d[ty][tx] == 3){
			tx = x , ty = y;
			while(d[ty+dy[i]][tx+dx[i]] == 0)tx += dx[i] , ty += dy[i];
			
			if( d[ty+dy[i]][tx+dx[i]] == 3){
				ans = min(depth+1,ans);
				return;
			}else if(d[ty+dy[i]][tx+dx[i]] != -1){
				d[ty+dy[i]][tx+dx[i]] = 0;
				f(tx,ty,depth+1);
				d[ty+dy[i]][tx+dx[i]] = 1;
			}
		}
	}
}
int main(){
	while(cin >> W >> H && W){
		rep(i,22)rep(j,22) d[i][j] = -1;
		int sx=-1,sy=-1;
		rep(i,H)rep(j,W){
			cin >> d[i+1][j+1];
			if(d[i+1][j+1] == 2) sx = j+1 , sy = i+1 , d[i+1][j+1] = 0;
		}
		ans = 11;
		f(sx,sy,0);
		if(ans == 11) cout << -1 << endl;
		else cout << ans << endl;
	}
}

Measured memory_bytes: 864
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#define FOR(n) for(ll i=0;i<n;i++)
#define FORJ(n) for(ll j=0;j<n;j++)
#define PRN(n) printf("%d\n",n)
#define PRF(n) printf("%lf\n",n)
#define PRL(n) printf("%lld\n",n)
#define PRS(s) printf("%s\n",s)
#define PRC(c) printf("%c",c)
#define INF 10000000000
#define mod 1000000007
#define X 1000000
typedef long long int ll;
ll finv[X];
ll fac[X];
ll inv[X];
ll usort(const void *a, const void *b){return *(ll*)a-*(ll*)b;}
ll dsort(const void *a, const void *b){return *(ll*)b-*(ll*)a;}
ll ssort(const void *a, const void *b){return strcmp((char*)a,(char*)b);}
ll min(ll a,ll b){
  if(a>b)return b;
  return a;
}
ll max(ll a,ll b){
  if(a>b)return a;
  return b;
}
ll z(ll a){return max(a,-a);}
ll gcd(ll a,ll b){if(!b){return a;}else{return gcd(b,a%b);}}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
ll kt(ll a){
  ll sum=0;
  while(a){
    a/=10;
    sum++;
  }
  return sum;
}
ll ks(ll a){
  ll sum=0;
  while(a){
    sum+=a%10;
    a/=10;
  }
  return sum;
}
ll nCr(int n,int k){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for (int i=2;i<X;i++){
    fac[i]=fac[i-1]*i%mod;
    inv[i]=mod-inv[mod%i]*(mod/i)%mod;
    finv[i]=finv[i-1]*inv[i]%mod;
  }
  return fac[n]*(finv[k]*finv[n-k]%mod)%mod;
}

int x[1000001];
int cnt[1000001];
int main(void){
  ll n,m;
  scanf("%lld %lld",&n,&m);
  ll a,ac=0,wa=0;
  char s[3];
  FOR(m){
    scanf("%lld %s",&a,s);
    if(x[a])continue;
    if(s[0]=='W')cnt[a]++;
    if(s[0]=='A'){
      wa+=cnt[a];
      ac++;
      x[a]++;
    }
  }
  printf("%lld %lld\n",ac,wa);
  return 0;
}


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

#ifdef LOCAL
#define DEBUG(...) debug(#__VA_ARGS__, __VA_ARGS__);
#else
#define DEBUG(...) 6;
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename C, typename T = decay<decltype(*begin(declval<C>()))>, typename enable_if<!is_same<C, string>::value>::type* = nullptr>
ostream& operator << (ostream &os, const C &c) {bool f = true; os << "["; for (const auto &x : c) {if (!f) os << ", "; f = false; os << x;} return os << "]";}
template<typename T> void debug(string s, T x) {cerr << s << " = " << x << "\n";}
template<typename T, typename... Args> void debug(string s, T x, Args... args) {cerr << s.substr(0, s.find(',')) << " = " << x << " | "; debug(s.substr(s.find(',') + 2), args...);}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n;
    cin >> n;
    int pred = -1;
    for (int i=0; i<n; i++) {
        int h;
        cin >> h;
        if (h - 1 >= pred)
            h--;
        if (h < pred) {
            cout << "No\n";
            return 0;
        }
        pred = h;
    }
    cout << "Yes\n";

    return 0;
}


Measured memory_bytes: 3648
//お勉強中
//これは高速ゼータ変換の応用なの？

#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 16;
char cn[cm], * ci = cn;
inline int getint() {
	char C = *ci++;
	int A = C - '0';
	while ((C = *ci++) >= '0') A = A * 10 + C - '0';
	return A;
}

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

	fread(cn, 1, cm, stdin);

	int N = getint(), M = getint();
	int n = 1 << N;
	int dp[1 << 12];
	rep(i, n) dp[i] = 1e9;

	rep(i, M) {
		int A = getint();
		int B = getint();
		int C = 0;
		rep(j, B) {
			int c = getint();
			C += 1 << (c - 1);
		}
		dp[C] = min(dp[C], A);
	}

	rep(j, N) {
		rep (i, n) {
			if (!(i >> j & 1)) dp[i] = min(dp[i], dp[i | 1 << j]);
		}
	}

	rep1(i, n - 1) {
		for (int j = i - 1 & i; j > 0; j = j - 1 & i) {
			dp[i] = min(dp[i], dp[j] + dp[i ^ j]);
		}
	}

	if (dp[n - 1] >= 1e9) printf("-1");
	else printf("%d", dp[n - 1]);


	Would you please return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <cstdio>
using namespace std;

int N, M;

vector< vector<double> > calc(vector<int> &vec) {
    vector<double> p(M+1);
    p[0] = 1.0;
    for(int i=0; i<M; i++) {
        for(int j=M; j>=0; j--) {
            if(j + 1 <= M) p[j+1] += p[j] / 3.0;
            p[j] = p[j] * 2.0 / 3.0;
        }
    }
    for(int i=0; i<M; i++) {
        p[i+1] += p[i];
    }

    // first, second, third, worst
    vector< vector<double> > dp(M+1, vector<double>(4));
    for(int i=0; i<=M; i++) dp[i][0] = dp[i][3] = 1.0;

    for(int i=1; i<N; i++) {
        vector< vector<double> > swp(M+1, vector<double>(4));
        for(int j=0; j<=M; j++) {
            int val = vec[0] * j;
            int idx = (val + vec[i] - 1) / vec[i];
            double win = (idx == 0 ? 0 : p[min(idx-1, M)]);

            for(int k=0; k<3; k++) {
                swp[j][k] += dp[j][k] * win;
                if(k + 1 < 3) swp[j][k+1] += dp[j][k] * (1 - win);
            }
            swp[j][3] += dp[j][3] * (1 - win);
        }

        swap(dp, swp);
    }

    return dp;
}

int main() {
    cin >> N >> M;
    vector<int> vi(N), da(N), vo(N);
    for(int i=0; i<N; i++) {
        cin >> vi[i] >> da[i] >> vo[i];
    }

    auto dp1 = calc(vi), dp2 = calc(da), dp3 = calc(vo);

    double ans = -1e100;
    for(int A=0; A<=M; A++) {
        for(int B=0; A+B<=M; B++) {
            double sum = 0.0;
            int C = M - A - B;
            sum += (dp1[A][0] + dp1[A][1] + dp1[A][2]) * 5.0;
            sum += (dp2[B][0] + dp2[B][1] + dp2[B][2]) * 3.0;
            sum += (dp3[C][0] + dp3[C][1] + dp3[C][2]) * 2.0;
            sum -= (dp1[A][3] + dp2[B][3] + dp3[C][3]) * 1.0;
            ans = max(ans, sum);
        }
    }
    cout << fixed << setprecision(12) << ans <<  endl;
    return 0;
}


Measured memory_bytes: 3772
n,m,qu = map(int,input().split())
lr = [[0]*(n+1) for _ in range(n+1)]

for i in range(m):
  l,r = map(int,input().split())
  lr[l][r]+=1

for i in range(1,n+1):
  for j in range(i,n+1):
    lr[i][j]+=lr[i][j-1]
  
for i in range(1,n+1):
  for j in range(i):
    lr[i-j-1][i]+=lr[i-j][i]
    
for i in range(qu):
  p,q = map(int,input().split())
  print(lr[p][q])


Measured memory_bytes: 9424
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define mid ((l+r)/2)
#define mp make_pair
#define pb push_back
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define REP(x) for(int i=head[x],y=a[i].to;i;i=a[i].next,y=a[i].to) if(y!=fa)
typedef vector<int> ve;
typedef set<int> si;
#define fi first
#define se second


inline int read()
{
	int s=0,w=1;
	char ch=getchar();
	while(ch<'0'||ch>'9') {if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
	return s*w;
}
const int N=110;
int w[N][N],f[N][N],n,m;
char a[N][N];
int main()
{
    n=read();m=read();
    for(int i=1;i<=n;i++) {
        scanf("%s",a[i]+1);
        for(int j=1;j<=m;j++) w[i][j]=(a[i][j]=='#');
    }
    for(int i=1;i<=n+1;i++)
        for(int j=1;j<=m+1;j++)
            f[i][j]=f[i][j]=1e9;
    f[n][m+1]=f[n][m+1]=f[n+1][m]=f[n+1][m]=0;
    for(int j=n;j>=1;j--)
        for(int k=m;k>=1;k--) {
            int op=w[j][k];
            if(op==1) {
                f[j][k]=min(f[j][k],f[j+1][k]+(!w[j+1][k]));
                f[j][k]=min(f[j][k],f[j][k+1]+(!w[j][k+1]));
            }
            else f[j][k]=min(f[j+1][k],f[j][k+1]);

        }
    cout<<f[1][1]<<'\n';
}


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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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 int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

ll n;
vll G[100005];

void dfs(ll v, ll p, vll& cost){
  cost[v]=cost[p]+1;
  for(auto e: G[v]){
    if(e==p) continue;
    dfs(e,v,cost);
  }
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  cin>>n;
  rep(i,n-1){
    ll a,b; cin>>a>>b;
    a--,b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  vll costa(n);
  vll costb(n);
  dfs(0,-1,costa);
  dfs(n-1,-1,costb);
  ll cnt=0;
  rep(i,n){
    if(!i) continue;
    if(costa[i]<=costb[i]) cnt++;
  }
  
  if(cnt>=(n-cnt-1) && cnt!=0) cout<<"Fennec"<<endl;
  else cout<<"Snuke"<<endl;
}

Measured memory_bytes: 12032
/* author : akshatjai258 */
#include<bits/stdc++.h>
using namespace std;   
typedef long long ll; 
typedef pair<int, int> pii; 
typedef pair<ll, ll> pll; 
typedef pair<string, string> pss; 
typedef vector<int> vi; 
typedef vector<vi> vvi; 
typedef vector<pii> vii; 
typedef vector<ll> vl; 
typedef vector<vl> vvl; 
#define int ll
#define mod int(1e9+7)
#define inf int(1e9)
#define endl "\n"  
#define FOR(a, b, c) for (int(a) = (b); (a) < (c); ++(a)) 
#define FORN(a, b, c) for (int(a) = (b); (a) <= (c); ++(a)) 
#define fi first
#define mem0(a) memset(a,0,sizeof(a))
#define mem1(a) memset(a,-1,sizeof(a))
#define memf(a) memset(a,false,sizeof(a))
#define all(v) v.begin(),v.end() 
#define se second 
#define mp make_pair 
#define pb push_back 
#define w(x)   int x; cin>>x; while(x--)
#define ps(x,y)     fixed<<setprecision(y)<<x
void prep()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
/*#ifndef ONLINE_JUDGE
	freopen("input.txt","r",stdin);
	freopen("output.txt","w",stdout);
#endif*/
		
}
int32_t main()
{
	prep();
	int n;
	cin>>n;
	vvi dp(n+1,vi(3));
	dp[0][0]=0;
	dp[0][1]=0;
	dp[0][2]=0;
	for(int i=1;i<=n;i++)
	{
		vi arr(3);
		for(int j=0;j<3;j++)
		{
			cin>>arr[j];
		}
		dp[i][0]=max(arr[0]+dp[i-1][1],arr[0]+dp[i-1][2]);
		dp[i][1]=max(arr[1]+dp[i-1][0],arr[1]+dp[i-1][2]);
		dp[i][2]=max(arr[2]+dp[i-1][1],arr[2]+dp[i-1][0]);	
	}
	cout<<max(dp[n][0],max(dp[n][1],dp[n][2]));	
	return 0;
}



Measured memory_bytes: 5760
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(x) (x).begin(),(x).end()
#define dup(x,y) (((x)+(y)-1)/(y))
#define sz(x) (int)(x).size()
#define MOD 1000000007
#define pint pair<int,int>
#define pdouble pair<double,double>
using namespace std;
typedef long long ll;

int main(){
    int n, x;
    cin >> n >> x;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int p = 0;
    int ans = 1;
    rep(i,n){
        p += a[i];
        if(p <= x){
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 300010;

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

int main(){
    int h, w;
    while(scanf("%d%d", &h, &w) && h){
        string s[h];
        rep(i, h) cin >> s[i];
        map<string, int> mp;
        rep(sx, h)rep(sy, w)rep(i, 8){
            string tmp;
            int x = sx, y = sy;
            do{
                tmp += s[x][y];
                ++mp[tmp];
                x = (x + dx[i] + h) % h;
                y = (y + dy[i] + w) % w;
            }while(x != sx || y != sy);
        }

        string ans = "0";
        for(auto &p: mp)if(p.se >= 2){
            if(ans.size() < p.fi.size() || (ans.size() == p.fi.size() && ans > p.fi)){
                ans = p.fi;
            }
        }
        cout << ans << "\n";
    }
}


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


int main(){
    int x;
    cin >> x;
    int a = x/500;
    x %= 500;
    int b = x/5;
    cout << a*1000 + b*5 << endl;
}

Measured memory_bytes: 256
for i in range(31):
    n = int(input())
    if n == 0:
        break

    d = [1, 1, 2, 4]
    for i in range(4, n+1):
        d.append(d[i-3] + d[i-2] + d[i-1])

    q, r = divmod(d[n], 3650)

    print(q if r == 0 else q + 1)



Measured memory_bytes: 5592
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
typedef pair<int, int> P;
int main()
{
    int N;
    cin >> N;

    vector<int> A(N);
    rep(i, N) cin >> A[i];

    int cnt = 1;
    bool flg = (A[0] <= A[1]) ? true : false;
    bool check = false;
    repd(i, 2, N) {
        if (check) {
            if (A[i - 1] == A[i]) continue;
            flg = (A[i - 1] <= A[i]) ? true : false;
            check = false;
        }
        if (flg) {
            if (A[i - 1] > A[i]) {
                check = true;
                cnt++;
            }
        }
        else {
            if (A[i - 1] < A[i]) {
                check = true;
                cnt++;
            }
        }
    }

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 640
using System;
class B_ZOswap{
	static void Main(string[] args){
		int N = int.Parse(Console.ReadLine());
		string[] ps = Console.ReadLine().Split(' ');
		int DifC = 0;
		for(int i = 1;i <= N;i++){
			if(i != int.Parse(ps[i - 1]))DifC++;
		}
		Console.WriteLine(DifC <= 2 ? "YES" : "NO");
	}
}

Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a, b;
  string s;
  cin >> a >> b;
  cin >> s;
  for(int i = 0; i < s.size(); i++){
    if(i == b - 1) printf("%c", s[i] - 'A' + 'a');
    else cout << s[i];
  }
  printf("\n");
  return 0;
}


Measured memory_bytes: 256
import java.text.DecimalFormat;
import java.util.stream.LongStream;
import java.util.stream.IntStream;
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);

        AtCoder problem = new AtCoder(sc);
        problem.solve(out);

        out.flush();
    }

}

class AtCoder {

    String S;

    AtCoder(FastScanner sc) {
        S = sc.next();
    }

    void solve(PrintWriter out) {
        if (S.substring(5, 7).matches("0[1-4]")) {
            out.println("Heisei");
        } else {
            out.println("TBD");
        }
    }

}

// https://qiita.com/p_shiki37/items/a0f6aac33bf60f5f65e4
class FastScanner {

    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte()) {
            return buffer[ptr++];
        } else {
            return -1;
        }
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
            ptr++;
        }
        return hasNextByte();
    }

    public String next() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

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

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) {
            throw new NumberFormatException();
        }
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 21460
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pl;
typedef pair<int,int> pi;
typedef pair<ll,pl> pp;
const ll MOD = 1e9+7;
const ll MAX = 1e18*2;

struct nd{int x,y;string s;};

int used[3333][3333];
int dp[3333][3333];

int main(){
  string s,t;
  cin>>s>>t;
  for(int i=0;i<s.size();i++){
    for(int j=0;j<t.size();j++){
	 dp[i][j+1]=max(dp[i][j+1],dp[i][j]);
	 dp[i+1][j]=max(dp[i+1][j],dp[i][j]);
	 if(s[i]==t[j])dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j]+1);
    }
  }
  ll ans=0;
  int a,b;
  for(int i=0;i<=s.size();i++){
    for(int j=0;j<=t.size();j++){
    if(ans<dp[i][j]){
	 ans=dp[i][j];
	 a=i;
	 b=j;
    }
    }
  }
  //  cout<<ans<<endl;
  if(ans==0){
    cout<<""<<endl;
    return 0;
  }
  queue<nd> q;
  q.push((nd){a,b,""});
  while(q.size()){
    nd tmp=q.front();
    q.pop();
    int x=tmp.x;
    int y=tmp.y;
    // cout<<x<<" "<<y<<endl;
    string l=tmp.s;
    if(x==0&&y==0){
	 reverse(l.begin(),l.end());
	 cout<<l<<endl;
	 break;
    }
    if(used[x][y])continue;
    used[x][y]=1;
    if(x!=0&&dp[x][y]==dp[x-1][y])q.push((nd){x-1,y,l});
    if(y!=0&&dp[x][y]==dp[x][y-1])q.push((nd){x,y-1,l});
    if((x>0&&y>0)&&dp[x][y]==dp[x-1][y-1]+1&&s[x-1]==t[y-1]){
	 l+=s[x-1];
	 q.push((nd){x-1,y-1,l});
    }
  }
  return 0;
}


Measured memory_bytes: 82176
a = input()
n,f = 0,1
if 'N' in a:
    if 'S' in a:
        n = 1
    else:
        f = 0
if 'W' in a:
    if 'E' in a:
        n = 1
    else:
        f = 0
if 'S' in a:
    if 'N' in a:
        n = 1
    else:
        f = 0
if 'E' in a:
    if 'W' in a:
        n = 1
    else:
        f = 0
if (n*f) == 1:
    print('Yes')
else:
    print('No')

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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll n;
    cin >> n;
    vector<vector<ll>> graph(n);
    for(i = 0;i < n-1;++i){
        ll a,b;
        cin >> a >> b;
        --a;    --b;
        graph.at(a).push_back(b);
        graph.at(b).push_back(a);
    }
    vector<ll> f(n,-1);
    vector<ll> snu(n,-1);
    queue<ll> que;
    f.at(0) = 0;
    que.emplace(0);
    while(!que.empty()){
        ll now = que.front();
        ll dist = f.at(now);
        que.pop();
        for(i = 0;i < graph.at(now).size();++i){
            ll next = graph.at(now).at(i);
            if(f.at(next) == -1){
                f.at(next) = dist+1;
                que.emplace(next);
            }
        }
    }
    snu.at(n-1) = 0;
    que.emplace(n-1);
    while(!que.empty()){
        ll now = que.front();
        ll dist = snu.at(now);
        que.pop();
        for(i = 0;i < graph.at(now).size();++i){
            ll next = graph.at(now).at(i);
            if(snu.at(next) == -1){
                snu.at(next) = dist+1;
                que.emplace(next);
            }
        }
    }
    ll fval = 0;
    ll snuval = 0;
    for(i = 0;i < n;++i){
       if(f.at(i) <= snu.at(i)) ++fval;
       else ++snuval;
    }
    if(fval > snuval) cout << "Fennec" << endl;
    else cout << "Snuke" << endl;
    return 0;
}

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


int main() {
    int A, B, C;
    cin >> A >> B >> C;

    if(A == B && B == C){
        cout << "No" << endl;
    }

    else if(A == B || B == C || C == A){
        cout << "Yes" << endl;
    }

    else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#![allow(non_snake_case)]

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_line(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let A = iter.next().unwrap().parse::<isize>().unwrap();
    let B = iter.next().unwrap().parse::<isize>().unwrap();
    let C = iter.next().unwrap().parse::<isize>().unwrap();

    let sum = (A..B + 1).fold(0usize, |sum, x| if C % x == 0{sum + 1}else{sum});
    println!("{}", sum);
}



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

typedef long long ll;
typedef unsigned long long ull;

using namespace std;

unordered_map<int, int> m;
int getD(int x){
    int l = x % 10;
    int f = 0;
    while(x != 0){
        f = x % 10;
        x /= 10;
    }
    return f * 10 + l;
}
int main() {
    int n, cnt = 0;
    scanf("%d", &n);
    for(int i = 1; i <= n ; i++)m[getD(i)]++;
    for(int i = 1; i < 10; i++){
        for(int j = 1 ; j < 10; j++){
            cnt += m[i*10+j]*m[j*10+i];
        }
    }
    printf("%d\n", cnt);
    
}



Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <string.h>
#include <vector>

using namespace std;

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)
#define REPIT(i,x) for(auto i{(x).begin()}; i != (x).end(); i++)

#define PB push_back
#define MP make_pair
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

typedef int64_t ll;
typedef double dbl;
typedef vector<bool> Vb;
typedef vector<int> Vi;
typedef vector<ll> Vl;
typedef vector<string> Vs;
typedef vector<vector<int> > VVi;
typedef vector<vector<ll> > VVl;

template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
inline void swap(ll& a, ll& b) { a ^= b; b ^= a; a ^= b; }
inline void swap(int& a, int& b) { a ^= b; b ^= a; a ^= b; }
inline void YES() { cout << "YES" << endl; } inline void Yes() { cout << "Yes" << endl; }
inline void NO() { cout << "NO" << endl; } inline void No() { cout << "No" << endl; }

const int inf = 1 << 28;
const ll linf = 1LL << 60;
const int MOD = 1000000007;

int a, b;

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

	cout << max(0, a - b - b) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(){
	int n; 
	vector<int> bv;
	cin >> n;
	for(int i = 0; i < n-1; i++){
		int b;
		cin >> b;
		bv.push_back(b);
	}
	int sum = 0;
	for(int j = 0; j < n-1; j++){
		sum += min(bv[j], bv[j+1]);
	}
	cout << sum + bv.back() + bv.front() << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
using ll = long long;
using namespace std;
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> s(n);
    REP(i, n) cin >> s[i];
    sort(s.begin(), s.end());
    int sum = 0;
    REP(i, n) sum += s[i];
    if (sum % 10 != 0) {
        cout << sum << endl;
        return 0;
    }
    REP(i, n) {
        if (s[i] % 10 != 0) {
            cout << sum - s[i] << endl;
            return 0;
        }
    }
    cout << 0 << endl;
}


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

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

	int n;
	cin >> n;

	for(int i = 0; i < n; ++i){
		int x, y, b, p;
		cin >> x >> y >> b >> p;
		int ans = 0;
		if(b >= 5 && p >= 2){
			ans = (b * x + p * y) * 0.8;
		}
		else {
			int a1 = b * x + p * y;
			if(b >= 5){
				int a2 = (b * x + 2 * y) * 0.8;
				ans = min(a1, a2);
			}
			else if(p >= 2){
				int a3 = (5 * x + p * y) * 0.8;
				ans = min(a1, a3);
			}
			else {
				int a4 = (5 * x + 2 * y) * 0.8;
				ans = min(a1, a4);
			}
		}
		cout << ans << endl;
	}

	return 0;
}

Measured memory_bytes: 1196
n = int(input())
a = [int(i) for i in input().split()]
m = len(list(filter(lambda x: x < 0, a)))
s = [abs(i) for i in a]
if m % 2 == 0 or 0 in a:
    print(sum(s))
else:
    print(sum(s) - 2 * min(s))


Measured memory_bytes: 14332
#include <cstdio>
#include <stdint.h>
#include <algorithm>

int main(){
  int64_t as[3];
  for(int64_t i=0;i<3;i++){
    scanf("%ld",&as[i]);
    if(as[i]%2==0){
      printf("0\n");
      return 0;
    }
  }
  std::sort(as,as+3);
  printf("%ld\n",as[0]*as[1]);
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <cstdlib>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <stack>
#include <queue>
#include <set>
#include <cstring>

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

#define MAX_V 1000000

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

  int n;
  cin >> n;
  long double a[n];
  long double total_multi = 1;
  rep(i, 0, n) {
      cin >> a[i];
      total_multi *= a[i];
  }

  long double denominator = 0;
  rep(i, 0, n) denominator += total_multi / a[i];
  long double rsl = total_multi / denominator;
  cout << rsl << endl;
}


Measured memory_bytes: 256
// atcoder/agc023/A/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; }
template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }
template<typename P, typename Q> inline pair<Q, P> reverse(pair<P, Q> p) { return make_pair(p.second, p.first); }

using lli = long long int;
using ull = unsigned long long;
using point = complex<double>;
using str = string;
template<typename T> using vec = vector<T>;

constexpr lli mod = 1e9 + 7;

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);

  int n;
  while (cin >> n) {
    vector<lli> a(n);
    cin >> a;
    a.insert(a.begin(), 1LL << 59);
    map<lli, lli> cnt;
    lli x = 0;
    lli sum = 0;
    each (i, a) {
      sum += i;
      x += cnt[sum];
      ++cnt[sum];
    }
    cout << x << endl;
  }

  return 0;
}


Measured memory_bytes: 14308
#include<bits/stdc++.h>
using namespace std;
int main()
{ string s;
int count=0;
  for(int i=1;i<=3;i++)
   {  cin>>s[i];
   if(s[i]=='7')
    count++;
}
if(count==0)
{ cout<<"No\n"<<endl;
} 
    else
  cout<<"Yes\n"<<endl;
 return 0;
}
 

Measured memory_bytes: 3588
#include <iostream>

using namespace std;

int n, m, h, d;
char in[31][10];

bool judge();
main(){
  while(1){
    cin >> n;
    if(n==0) break;
    cin >> m >> h >> d;
    for(int i=0;i<d;i++){
      for(int j=0;j<n-1;j++){
	cin >> in[i][j];
      }
    }
    if(judge()){
      cout << 0 << endl;
      continue;
    }
    bool end=false;
    for(int i=0;i<d;i++){
      for(int j=0;j<n-1;j++){
	if(in[i][j]=='0'){
	  if(j!=0 && j!=n-1){
	    if(in[i][j-1]=='1') continue;
	    if(in[i][j+1]=='1') continue;
	  }
	  if(j==0){
	    if(in[i][j+1]=='1') continue;
	  }
	  if(j==n-1){
	    if(in[i][j-1]=='1') continue;
	  }
	  in[i][j]='1';
	  if(judge()){
	    printf("%d %d\n", i+1, j+1);
	    end=true;
	    break;
	  }
	  in[i][j]='0';
	}
      }
      if(end) break;
    }
    if(end) continue;
    cout << 1 << endl;
  }
  return 0;
}

bool judge(){
  int tmp=m-1;
  int i;
  for(i=0;i<d;i++){
    if(tmp==0){
      if(in[i][0]=='1') tmp=1;
    }else if(tmp==n-1){
      if(in[i][n-2]=='1') tmp=n-2;
    }else{
      if(in[i][tmp]=='1') tmp++;
      else if(in[i][tmp-1]=='1') tmp--;
    }
  }
  if(tmp==h-1) return true;
  else return false;
}

Measured memory_bytes: 0
import math
A,B,H,M=map(int,input().split())

p=2*math.pi

m_r = p*M/60
h_r = p*((H/12)+(M/60)/12)
d_r = abs(m_r - h_r)

C=A**2 + B**2 - 2*A*B*math.cos(d_r)
print(C**(1/2))

Measured memory_bytes: 9504
#[allow(unused_imports)]
use std::cmp;

// Input macro from https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
  (source = $s:expr, $($r:tt)*) => {
    let mut iter = $s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
  ($($r:tt)*) => {
    #[allow(unused_mut)]
    let mut s = {
      use std::io::Read;
      let mut s = String::new();
      std::io::stdin().read_to_string(&mut s).unwrap();
      s
    };
    let mut iter = s.split_whitespace();
    input_inner!{iter, $($r)*}
  };
}

macro_rules! input_inner {
  ($iter:expr) => {};
  ($iter:expr, ) => {};

  ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
    let $var = read_value!($iter, $t);
    input_inner!{$iter $($r)*}
  };
}

macro_rules! read_value {
  ($iter:expr, ( $($t:tt),* )) => {
    ( $(read_value!($iter, $t)),* )
  };

  ($iter:expr, [ $t:tt ; $len:expr ]) => {
    (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
  };

  ($iter:expr, chars) => {
    read_value!($iter, String).chars().collect::<Vec<char>>()
  };

  ($iter:expr, usize1) => {
    read_value!($iter, usize) - 1
  };

  ($iter:expr, $t:ty) => {
    $iter.next().unwrap().parse::<$t>().expect("Parse error")
  };
}

fn main() {
  input! {
    n: usize,
    a: [[i64; n]; n]
  }
  let mut dp = vec![0i64; 1 << n];
  for set in 0 .. 1 << n {
    for i in 0 .. n {
      if set >> i & 1 == 0 {
        continue;
      }
      for j in 0 .. i {
        if set >> j & 1 == 0 {
          continue;
        }
        dp[set] += a[i][j];
      }
    }
    let mut sub = set;
    while sub > 0 {
      dp[set] = cmp::max(dp[set], dp[sub] + dp[set ^ sub]);
      sub = (sub - 1) & set;
    }
  }
  println!("{}", dp[(1 << n) - 1]);
}


Measured memory_bytes: 4352
#include<stdio.h>
#include<string.h>
#define rep(i,X) for(i=0;i<X;i++)
char s[102],c[27];n,C,S,A,i,j,k,l;main(tab){scanf("%d%s",&n,c);C=strlen(c);rep(i,n){scanf("%s",s);S=strlen(s);rep(j,S){if(s[j]-c[0])continue;rep(k,199){tab=k+1;rep(l,199){if(l>=C){l=1;break;}if(j+tab*l>=S || s[j+tab*l]-c[l]){l=0;break;}}if(l){A++;goto E;}}}E:;}C=!printf("%d\n",A);}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define dbg puts("It's Just Begining.Wait For The End!!!!!\n")
#define CHECK(x) cout << (#x) << " is " << (x) <<"\n";
#define endl printf("\n")
typedef pair<ll,ll> pii;
#define pb push_back
#define ms(a,b) memset(a, b, sizeof(a))
#define in(x) scanf("%lld",&x)
#define out(x) printf("%lld",x)
#define X first
#define Y second
#define sps printf(" ")
#define dou(x) cout<<fixed<<setprecision(6)<<x
#define all(v) v.begin(),v.end()
#define dis(it,it1) distance(it,it1)+1
#define MAX 100005
#define INF 9223372036854775807LL
#define MOD 1000000007
#define print(cs) printf("Case %lld: ",cs)
#define Yesno(ok) if(ok)puts("YES");else puts("NO")
#define yesno(ok) if(ok)puts("Yes");else puts("No")
ll lcm(ll a,ll b){return ((a*b)/__gcd(a,b));}
int main()
{
     ll test=1,cas=1;
     while(test--)
     {
		ll i,j,k,l,n,m,r;
		string s;
		cin>>s;
		if(s.size()==2)
        {
            if(s[0]==s[1])puts("1 2");
            else puts("-1 -1");
        }
        else
        {
            l=-1,r=-1;
            for(i=0;i<s.size()-2;i++)
            {
                if(s[i]==s[i+1]||s[i+1]==s[i+2]||s[i]==s[i+2])
                {
                    l=i+1;
                    r=i+3;
                }
            }
            cout<<l<<" "<<r;endl;
        }
     }
}


Measured memory_bytes: 512
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <utility>
#include <numeric>

using namespace std;

const uint64_t MOD = 1000000000 + 7;

int main()
{
	int64_t r, d, x;
	cin >> r >> d >> x;

	int64_t old = x;
	for (int i = 0; i < 10; i++)
	{
		int64_t x = r * old - d;

		cout << x << endl;

		old = x;
	}

	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define debug(var)  do{std::cout << #var << " : ";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
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; }

const int MOD = 1000000007;
const int INF = 1e9;

const int mod = 1000000007;
const int inf = 1e9;
#define PI acos(-1);
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


int main(){
    //入力＋ソート
    int n; ll k;
    cin >> n >> k;
    vector<ll> a(n), f(n);
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < n; i++) cin >> f[i];
    sort(a.begin(), a.end());
    sort(f.rbegin(), f.rend());

    //目標の成績kを達成可能かどうかを判定する関数
    auto ok = [&](ll x) {
        ll cost = 0;
        for(int i = 0; i < n; i++) {
            cost += max(0LL, a[i] - x/f[i]);
        }
        return cost <= k;
    };

    //二分探索
    ll l = -1, r = 1e18;
    while(r-l>1) {
        ll mid = (r+l)/2;
        if(ok(mid)) r = mid;
        else l = mid;
    }
    cout << r << endl;
}


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

const ll mod=1e9+7;
int main(){
    int n; string s;
    cin>>n>>s;
    map<char,int>mp;
    rep(i,n){
        mp[s[i]]++;
    }
    for(auto&p:mp)p.second++;
    ll ans=1;
    for(auto&p:mp){
        ans*=p.second;
        ans%=mod;
    }
    cout<<ans-1<<endl;
}

Measured memory_bytes: 512
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

  public static void main(String[] args) throws IOException {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt( br.readLine() );
      String[] line = br.readLine().split(" ");

      int[] a = new int[n];
      for (int i = 0; i < n; i++) {
        a[i] = Integer.parseInt(line[i]);
      }

      insertionSort(a, n);
    }
  }

  public static void insertionSort(int a[], int max) {
    for (int i=0,j=0,v=0; i < max; i++) {
      for( j = i-1, v = a[i]; j>=0 && a[j]>v; j-- ) {
        a[j+1] = a[j];
      }
      a[j+1] = v;
      dispIntArray(a);
    }
  }
  public static void dispIntArray(int a[]) {
    StringBuilder line = new StringBuilder(a.length*4);
    for (int i=0, max = a.length-1; i < max; i++) {
     line.append(a[i]).append(" ");
    }
    System.out.println( line.append(a[a.length-1]) );
  }
}


Measured memory_bytes: 26720
n,y = map(int,input().split())

price = 0
ok = 0

for i in range(n+1):
    for j in range(n+1-i):
            k = n - i - j
            if k < 0:
                k = 0

            price = 10000 * i + 5000 * j + 1000 * k   
            
            if price == y and i+j+k == n:
                print(i, j, k)
                ok = 1
                break

    else:
        continue
    break

if ok == 0:
    print(-1, -1, -1 )

Measured memory_bytes: 3064
# -*- coding: utf-8 -*-


def pow(x, n, M=1):
    if n == 0:
        return 1
    res = pow((x * x) % M, n // 2, M)
    if n % 2 == 1:
        res = (res * x) % M
    return res


if __name__ == '__main__':

    M = 1000000007
    m, n = map(int, input().split())
    print(pow(m, n, M))



Measured memory_bytes: 5604
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<cstdlib>
#include<cstring>
using namespace std;
inline int read()
{
	int x=0,f=1;char ch=getchar();
	while(ch<'0' || ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9')x=x*10+ch-'0',ch=getchar();
	return x*f;
}
int stack[20];
inline void write(int x)
{
	if(x<0){putchar('-');x=-x;}
	if(!x){putchar('0');return;}
	int top=0;
	while(x)stack[++top]=x%10,x/=10;
	while(top)putchar(stack[top--]+'0');
}
inline void pr1(int x){write(x),putchar(' ');}
inline void pr2(int x){write(x),puts("");}
int main()
{
    //freopen("a.in","r",stdin);
    //freopen("a.out","w",stdout);
    int sx=read(),sy=read(),ex=read(),ey=read(),n=read();
    pr2((ex-sx)*60+ey-sy-n);
    return 0;
}

Measured memory_bytes: 1488
S=input()
a=int(S[:2])
b=int(S[2:])
if 1<=a<=12:
    if 1<=b<=12:
        ans='AMBIGUOUS'
    else:
        ans='MMYY'
else:
    if 1<=b<=12:
        ans='YYMM'
    else:
        ans='NA'
print(ans)
    

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

int main(){
    int n;
    cin>>n;
    vector<int> a(n+1),b(n);
    for(int i=0; i<n+1; i++)cin>>a[i];
    for(int i=0; i<n; i++)cin>>b[i];
    ll ans=0;
    for(int i=0; i<n; i++){
        int l = min(a[i],b[i]);
        b[i]-=l;
        int r = min(a[i+1],b[i]);
        a[i+1]-=r;
        ans+=l+r;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 1024
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) cout << #x << " = " << (x) << endl;
using namespace std;
using ll = long long;
using pii = pair<int,int>;
int main(){
    int n;
    cin >> n;
    vector<int>a(n+1);
    rep(i,n)cin >> a[i+1];
    int ans = 0;
    rep(i,n){
        if(a[i] < a[i+1])ans += a[i+1]-a[i];
    }
    cout << ans << endl;
}

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

typedef long long ll;

vector<vector<pair<int,ll>>> G;
vector<ll> point;
vector<bool> visited;
vector<int> flag;

void dfs(int x, int p, int d){
    if(!visited[x]){
        point[x] = d;
        visited[x] = true;
    }
    else{
        if(flag[x] != -1){
            flag[x] = ((point[x] == d) ? 1:-1);
        }
        return;
    }
    for(auto nx:G[x]){
        if(nx.first == p)continue;
        dfs(nx.first, x, d + nx.second);
    }
}

int main() {
    int N,M;
    cin>>N>>M;
    G.resize(N);
    point.assign(N,0);
    visited.assign(N,false);
    flag.assign(N, 0);
    rep(i,M){
        int L,R,D;
        cin>>L>>R>>D;
        L--;R--;
        G[L].push_back({R,D});
        G[R].push_back({L,-D});
    }
    rep(i,N){
        if(!visited[i]){
            dfs(i,-1,0);
        }
    }
    string ans = "Yes";
    rep(i,N){
        if(flag[i] == -1){
            ans = "No";
        }
    }
    cout<< ans <<endl;
}

Measured memory_bytes: 16896
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define MIN(a,b) ((a) <= (b) ? (a) : (b))
#define ALL(v) (v).begin(), (v).end()
#define SORT(v) sort( ALL(v) )

using namespace std;
using ll = long long;
using P = pair<int,int>;

int arr[1000000]{};
int main()
{

        int n; cin>>n;

        set<int> st;
        for(int i  = 0 ; i<n ; i++)
        {
            int x; cin>>x;
            st.insert(x);
        }

        if(st.size()==n)
        {
            cout<<"YES"<<endl;
        }
        else
        {
            cout<<"NO"<<endl;
        }



    return 0;
}


Measured memory_bytes: 11008
import java.util.Scanner;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long h = sc.nextLong();
    long w = sc.nextLong();
    if (h == 1 || w == 1) {
      System.out.println(1);
    } else if (h % 2 == 0) {
      System.out.println(h / 2 * w);
    } else {
      long r = 0;
      for (long i = 0; i < w; i++) {
        if (i % 2 == 0) {
          r += (h + 1) / 2;
        } else {
          r += (h - 1) / 2;
        }
      }
      System.out.println(r);
      sc.close();
    }
  }
}


Measured memory_bytes: 35768
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
ll factorial(int i) {       //階乗
    if (i == 0) return 1;
    return (factorial(i - 1)) * i;
}

int main() {
    int n;
    cin >> n;
    map<string, int> ma;
    vector<string> s(n);
    rep(i, n) {
        string S;
        cin >> S;
        s[i] = S;
    }
    sort(s.begin(), s.end());
    rep(i, n) if(!ma.count(s[i])) ma[s[i]]++;
    rep(i, n) if(s[i] == s[i + 1]) ma[s[i]]++;
    int Max = -1;
    rep(i, n) Max = max(Max, ma[s[i]]);
    // cout << Max << endl;
    rep(i, n) if(ma[s[i]] == Max) {
        cout << s[i] << endl;
        i += Max - 1;
    }
    // cout << ma.size() << endl;
}

Measured memory_bytes: 25104
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <sstream>
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
long long a[1000005];
int main(){
  long long n;
  cin>>n;
  for (long long i=0;i<n;i++)
    cin>>a[i];
  sort (a,a+n);
  if(n % 2 != 0){
  	long long ans = 2100000000;
    long long l = a[n-1]/2;
    long long r = a[n-1]/2+1;
    for(long long i=0;i<n-1;i++){
      if(abs(l-ans) > abs(a[i]-l))  ans=a[i];
      if(abs(r-ans) > abs(a[i]-r))  ans=a[i];
    }
  cout<<a[n-1]<<" "<<ans;
  }
  else{
    long long ans = 2100000000;
  	long long val = a[n-1]/2;
    for(long long i=0;i<n-1;i++)
      if(abs(val-ans) > abs(a[i]-val))
        ans=a[i];
    cout<<a[n-1]<<" "<<ans;
}
  return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<math.h>
using namespace std;

int main() {
	int a[3];
	int K;
	cin >> a[0] >> a[1] >> a[2];
	cin >> K;
	sort(a, a + 3);
	for (int i = 0; i < K; i++) {
		a[2] *= 2;
	}
	cout << a[0] + a[1] + a[2];

}

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


    using namespace std;


    int main()
    {
       char arr[2][3];
       for(int i=0;i<2;i++)
       {
           for(int j=0;j<3;j++)
            cin>>arr[i][j];
       }
       if(arr[0][0]==arr[1][2]&&arr[0][1]==arr[1][1]&&arr[0][2]==arr[1][0])
        cout<<"YES";
       else cout<<"NO";

        return 0;
    }


Measured memory_bytes: 256
// Problem : C - Maximum Volume
// Contest : AtCoder Beginner Contest 159
// URL : https://atcoder.jp/contests/abc159/tasks/abc159_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/coder3101/cp-editor)

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

#ifdef LOCAL
#define DEBUG(...) cerr << #__VA_ARGS__ << ": ", debug(__VA_ARGS__);
#else
#define DEBUG(...)
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator << (ostream &os, const vector<T> &v) {os << "["; for (int i=0; i<(int)v.size(); i++) {if (i) os << ", "; os << v[i];} return os << "]";}
void debug() {cerr << "\n";} template<typename T, typename... Args> void debug(T x, Args... args) {cerr << x << "; "; debug(args...);}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    
    int l;
    cin >> l;
    
    double tre = l / 3.0;
    cout << fixed << setprecision(10) << tre * tre * tre << "\n";

    return 0;
}


Measured memory_bytes: 256