akhauriyash/Code-Regression huggingface dataset:
n = int(input())
a = [int(input()) for i in range(n)]
x = 1
total = 0
while type(a[x-1])==int and x != 2:
    k = x-1
    x = a[x-1]
    a[k] = "loop"
    total += 1
else:
    if type(a[x-1])==str:
        print(-1)
    elif x == 2:
        print(total)


Measured memory_bytes: 7084
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = (s); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) for(int i = (n); i >= 0; i--)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
constexpr int MOD = 998244353;

int mod(const ll &x){
    return x > 0 ? x % MOD : (x+MOD) % MOD;
}

int modm(const ll &x,const ll &m){
    return (x % MOD) * (m % MOD) % MOD;
}

int modpow(ll x, ll p) {
    int ret = 1;
    while(p > 0) {
        if (p & 1) ret = modm(ret,x);
        x = modm(x,x);
        p >>= 1;
    }
    return ret;
}

// x * modinv(d)
int modd(ll x,ll d) {
    return modm(x,modpow(d,MOD-2));
}

int main(void)
{
    constexpr int FACT = 200000;
    int fact[FACT];
    fact[0] = 1;
    FOR(i,1,FACT) fact[i] = modm(fact[i-1],i);
    auto comb = [&](int x,int y) {
                int r = fact[x];r = modd(r,fact[y]);r = modd(r, fact[x-y]);return r;};
        // n種類のものから重複を許してr個配った時の組み合わせ数(重複組み合わせnHr)
        // n個のボールにr-1個仕切りを立てる、または、r個のボールにn-1個仕切りを立てる
    // auto multicomb = [&](int n,int r) {return comb(n+r-1,r);};

    IOS
    int N, M, K;
    cin >> N >> M >> K;
    int ans = 0;
    REP(i,K+1) {
        int tmp = M;
        tmp = modm(tmp,comb(N-1,i));
        tmp = modm(tmp,modpow(M-1,N-1-i));
        ans = mod(ans+tmp);
    }

    cout << ans << '\n';

    return 0;
}

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

const int MOD = 1000000000 + 7;

int N;
int v[21][21];
int dp[22][1 << 21];

int solve(const int i, const int j)
{
    if (dp[i][j] != -1)
    {
        return dp[i][j];
    }

    if (i == N)
    {
        return dp[i][j] = 1;
    }

    int ans = 0;
    for (int k = 0; k < N; k += 1)
    {
        if (!v[i][k] or !(j & (1 << k)))
        {
            continue;
        }
        ans += solve(i + 1, j ^ (1 << k));
        if (ans >= MOD)
        {
            ans -= MOD;
        }
    }
    return dp[i][j] = ans;
}

int main()
{
    std::ios_base::sync_with_stdio(0);
    std::cin.tie(0);

    std::cin >> N;
    for (int i = 0; i < N; i += 1)
    {
        for (int j = 0; j < N; j += 1)
        {
            std::cin >> v[i][j];
        }
    }

    std::memset(dp, -1, sizeof dp);
    std::cout << solve(0, (1 << N) - 1) << std::endl;
}


Measured memory_bytes: 180480
#include<stdio.h>
#define N 100
#define W 0
#define G 1
#define B 2
#define I 10000001

int n,g[N][N],u;

void dij(){
  int i,u,v;
  int min;
  int d[N],color[N];

  for(i=0;i<n;i++){
    d[i]=I;
    color[i]=W;
  }
  d[0]=0;
  color[0]=G;
  while(1){
    min=I;
    u=-1;
    for(i=0;i<n;i++){
      if(min > d[i] && color[i] != B){
	u=i;
	min=d[i];
      }
    }

    if(u == -1)break;

    color[u]=B;

    for(v=0;v<n;v++){
      if(color[v]!=B && g[u][v]!=I){
	if(d[v] > d[u] + g[u][v]){
	  d[v] = d[u] + g[u][v];
	  color[v]=G;
	}
      }
    }
  }

  for(i=0;i<n;i++){
    printf("%d %d\n",i,(d[i] == I ? -1 : d[i] ));
  }
}

int main(){
  int i,j;
  int k,v,c;
  scanf("%d",&n);
  for(i=0;i<n;i++)for(j=0;j<n;j++)g[i][j]=I;


  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d%d",&v,&c);
      g[u][v]=c;
    }
  }

  dij();
  return 0;
}



Measured memory_bytes: 2104
#include <bits/stdc++.h>
typedef long long LL;
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

using namespace std;
LL p = 1000000007ll;

class UnionFind {
  std::vector<int> p;

public:
  UnionFind(int n) : p(n, -1) {}
  int root(int x) { return p[x] < 0 ? x : p[x] = root(p[x]); }
  bool same(int x, int y) { return root(x) == root(y); }
  bool unite(int x, int y) {
    x = root(x);
    y = root(y);
    if (x == y) return false;
    if (p[y] < p[x]) std::swap(x, y);
    if (p[x] == p[y]) --p[x];
    p[y] = x;
    return true;
  }
};


int main(void)
{
  LL n,m;
  cin >> n >> m;
  UnionFind uf(n+1);
  REP(i,m) {
    LL x,y,z;
    cin >> x >> y >> z;
    uf.unite(x,y);
  }
  LL answer = 0;
  FOR(i,1,n+1) {
    if(uf.root(i) == i) ++answer;
  }
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <vector>
#include <queue>
#include <set>
#include <iostream>
#include <iomanip>
using namespace std;
typedef long long LL;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

LL p = 1E9+7;

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

    vector<LL> count(N+2, 0);
    
    LL min_range = 0;
    LL max_range = 0;
    FOR(i, 1, N+2){
        min_range += i - 1;
        max_range += N - (i - 1);

        count[i] = max_range - min_range + 1;
    }

    LL ans = 0;
    FOR(i, K, N+2){
        ans = (ans + count[i])%p;
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4836
#include <cstdio>
#include <cstdlib>
  
int main(){
 int n;
 scanf("%d",&n);
   
 int ans = 100000;
 for(int i = 0;i < n;i++){
  ans += (double)ans * 0.05;
  if(ans % 1000 > 0) ans = ans - (ans % 1000) + 1000;
 }
 printf("%d\n",ans);
 return 0;
}

Measured memory_bytes: 2564
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main(void) {
	int K, S;
	cin >> K >> S;
	int ans = 0;
	for (int x = 0; x <= K; x++) {
		for (int y = 0; y <= K; y++) {
			int z = S - x - y;
			if (0 <= z && z <= K) {
				ans++;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

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

	
int main(void)
{
	int M,D;
	scanf("%d %d",&M,&D);
	int ans=0;
	int i,j;
	for(j=4;j<=M;j++){
		for(i=2;i<10;i++)
		{
			if(i*2==j && i*10+2<=D) ans++;
			if(i*3 ==j && i*10+3 <= D)ans++;
			if(i*4 ==j && i*10+4 <= D)ans++;
			if(i*5 ==j && i*10+5 <= D)ans++;
			if(i*6 ==j && i*10+6 <= D)ans++;
			if(i*7 ==j && i*10+7 <= D)ans++;
			if(i*8 ==j && i*10+8 <= D)ans++;
			if(i*9 ==j && i*10+9 <= D)ans++;
		}
	}
	printf("%d",ans);
	return 0;
}
	



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

using namespace std;

int cnt[10004];
int main() {
    int n;
    cin>>n;
    
    for(int x=1; x<=100; x++){
        for(int y=1; y<=100; y++){
            for(int z=1; z<=100; z++){
                int w = x*x+y*y+z*z+x*y+y*z+z*x;
                if(w>n){
                    continue;
                }
                cnt[w]++;
                
            }
        }
    }
    for(int k=1; k<=n; k++){
    cout<<cnt[k]<<endl;
    }
}

Measured memory_bytes: 3548
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
typedef long double ld;
const ll INF = 1e+14;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef complex<ld> Point;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ld, ld> LDP;
typedef pair<ll, ll> LP;
#define fr first
#define sc second
#define all(c) c.begin(),c.end()
#define pb push_back
 
void Yes(){
	cout<<"Yes"<<endl;
	exit(0);
}
 
void No(){
	cout<<"No"<<endl;
	exit(0);
}
 
 
int main(){
  
  ll N;
  cin>>N;
  vector<ll> a(N);
  for(ll i=0;i<N;i++){
    cin>>a[i];
  }
  
  sort(a.begin(),a.end());
  reverse(a.begin(),a.end()); //大きい順に並べ替え
  
  bool ans=false;
  
  if(N%3==0){
    
    
    ll g=N/3;
    ll h=N-N/3;
    ll j=a[0]^a[g];   
   
    if(j==a[h]){
      
      if(a[0]==a[g-1]){
        if(a[g]==a[h-1]){
          if(a[h]==a[N-1]){
            ans=true;
          }
        }
      }
    }
  }
  else{
    if(a[0]==0&&a[0]==a[N-1])
      ans=true;
  }
  if(ans){
    cout<<"Yes"<<endl;
  }
  
  else
    cout<<"No"<<endl;
}
            

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

using namespace std;

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

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

int gcd(int a, int b) {
    if (b == 0) {
        return a;
    } else {
        return gcd(b, a % b);
    }
}

int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, x;
    ll ans = 0;
    cin >> n >> x;
    vector<ll> a(n);
    rep (i, n) {
        cin >> a[i];
    }
    if (a[0] > x) {
        ans += a[0] - x;
        a[0] = x;
    }
    rep (i, n - 1) {
        int t = a[i] + a[i + 1];
        if (t > x) {
            ans += t - x;
            a[i + 1] -= t - x;
        }
    }
    cout << ans << endl;
    
    return 0;
}



Measured memory_bytes: 1024
n_x = []

while True:
    n, x = map(int, input().split())
    if n == x == 0:
        break
    else:
        n_x.append((n, x))

for n, x in n_x:
    ans = 0
    for i in range(1, n-1):
        for j in range(i+1, n):
            for k in range(j+1, n+1):
                if i + j + k == x:
                    ans += 1
    print(ans)


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

int main(){
    int A,B;
    string S;
    
    cin >> A >> B;
    cin >> S;

    bool flg=true;
    for(int i=0;i<A;i++){
        if(S[i]=='-') flg=false;
    }
    if(S[A]!='-') flg=false;
    for(int i=A+1;i<A+B+1;i++){
        if(S[i]=='-') flg=false;
    }

    if(flg) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}


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

    int i=1;
    int res = 1;
    while(i*i <= N) {
        res = i*i;
        i++;
    }

    cout << res << endl;
    return 0;
}

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

using namespace std;

typedef long long ll;

#define REP(i, a, b) for (i = a; i < b; i++)
#define REP_ITER(it, v) for (it = v.begin(); it != v.end(); it++)

#define FASTIO                   \
    ios::sync_with_stdio(false); \
    cin.tie(0)

#define TEST(test) \
    int test;      \
    cin >> test;   \
    while (test--)

#define cll(a, b) cin >> a >> b
#define YES cout << "YES\n"
#define NO cout << "NO\n"

#define vi vector<int>
#define vi_iterator vector<int>::iterator

#define si set<int>
#define si_iterator set<int>::iterator

double pi = 2 * acos(0.0);
int i, j;
int main()
{
    FASTIO;
    ll n, a, b;
    cin >> n >> a >> b;
    if (n < 2 && a != b)
    {
        cout << 0 << endl;
    }
    else if (n < 2 && a == b)
    {
        cout << 1 << endl;
    }
    else if (n == 2 && a <= b)
    {
        cout << 1 << endl;
    }
    else if (n == 2 && a > b)
    {
        cout << 0 << endl;
    }
    else if (a > b)
    {
        cout << 0 << endl;
    }
    else
    {
        ll diff = (b * (n - 2) - a * (n - 2)) + 1;
        cout << diff << endl;
    }
}

Measured memory_bytes: 3644
#include<cstdio>
#include<cstdlib>
#include<algorithm>
#include<iostream>
#include<queue>
#include<vector>
#include <bitset>
#include <cmath>
#include <limits>
#include <iostream>
#include<map>
#include<tuple>
using namespace std;
#define INF 11000000000
#define MAX 110000
#define MOD 1000000007
typedef long long ll;
typedef pair<int,int> P;
typedef pair<pair<int,int>,int> p;
typedef pair< pair<int,int>, int> p; 
#define bit(n,k) ((n>>k)&1) /*nのk bit目*/
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)


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



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(a,b,c) for(int a=b;a<=c;a++)
#define per(a,b,c) for(int a=b;a>=c;a--)
#define pb push_back
#define mk make_pair
#define pii pair<int,int>
#define fi first
#define se second
#define mem(a,b) memset(a,b,sizeof(a))
#define inf 0x3f3f3f3f
#define ls(x) (x<<1)
#define rs(x) (ls(x)|1)
#define eps 1e-11
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef double db;
const int mod = 998244353;
const int N = 1e6 + 5;
const int M = 1e3 + 5;
ll gcd(ll a,ll b){ return b?gcd(b,a%b):a; }
ll lcm(ll a,ll b){ return a*b/gcd(a,b); }
inline ll qsm(ll x,ll y){ ll res=1; while(y){if(y&1) res=res*x%mod;
x=x*x%mod; y>>=1;} return res; }
int n, m, k, c;
char s[N];
vector<int> ans;

int main(){
    scanf("%d%d%d",&n,&k,&c);
    scanf("%s",s+1);
    int cnt=0;
    vector<int> a;
    per(i,n,1){
        if(cnt<k&&s[i]=='o'){
            a.pb(i);
            i-=c;
            ++cnt;
        }
    }
    cnt=0;
    rep(i,1,n){
        if(cnt<k&&s[i]=='o'){
            if(a[k-cnt-1]==i) ans.pb(i);
            ++cnt;
            i+=c;
        }
    }
    for(auto x:ans) printf("%d\n", x);
    return 0;
}
/*

*/
//
//                            _ooOoo_
//                           o8888888o
//                           88" . "88
//                           (| -_- |)
//                           O\  =  /O
//                        ____/`---'\____
//                      .'  \|     |//  `.
//                     /  \|||  :  |||//  \
//                    /  _||||| -:- |||||-  \
//                    |   | \  -  /// |   |
//                    | \_|  ''\---/''  |   |
//                    \  .-\__  `-`  ___/-. /
//                  ___`. .'  /--.--\  `. . __
//               ."" '<  `.___\_<|>_/___.'  >'"".
//              | | :  `- \`.;`\ _ /`;.`/ - ` : | |
//              \  \ `-.   \_ __\ /__ _/   .-` /  /
//         ======`-.____`-.___\_____/___.-`____.-'======
//                            `=---='
//        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
//                     佛祖保佑      永无BUG


Measured memory_bytes: 3444
N,K=map(int,input().split())
A=list(map(int,input().split()))
A.sort()
MOD=10**9+7
fan=[1]*(N+1)
for i in range(2,N+1):
    fan[i]=fan[i-1]*(i)%MOD
ans=0
def comb(a,b):
    return fan[a]*pow(fan[b],MOD-2,MOD)*pow(fan[a-b],MOD-2,MOD)%MOD
for i in range(N-K+1):
    ans=ans+comb(N-i-1,K-1)*(A[N-1-i]-A[i])
    ans%=MOD
print(ans)

Measured memory_bytes: 14416
x, a, b = map(int, input().split())
A =0
B =0

if x<a:
    A = a-x
elif a<x:
    A = x-a
if x<b:
    B = b-x
elif b<x:
    B = x-b
if A<B:
    print("A")
else:
    print("B")


Measured memory_bytes: 2940
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <vector>
using namespace std;

int main(){
  int D, G;
  cin >> D >> G;

  vector<int> p;
  vector<int> c; // ボーナス点を得たときにiからどれだけ点を得ていたか
  for(int i=0;i<D;i++){
    int tmpP, tmpC;
    cin >> tmpP >> tmpC;
    p.push_back(tmpP);

    tmpC += tmpP * 100 * (i+1);
    c.push_back(tmpC);
  }

  int result = 10000;
  int last = pow(2,D);
  for(unsigned int i=0;i<last-1;i++){
    //cout <<"step " << i << endl;

    int tmpNum = 0;
    int tmpG = G;
    vector<int> tmpP = p;
    for(int j=D-1;j>=0;j--){
      if((i >> j) % 2 == 1){ // ボーナスを使う
        tmpG -= c[j];
        tmpNum += p[j];
        tmpP.erase(tmpP.begin()+j);
      }
    }


    for(int j=tmpP.size()-1;j>=0;j--){
      //cout <<"step " << j << endl;

      while(tmpG > 0 && tmpP[j] > 0){
        tmpP[j]--;
        tmpG -= 100*(j+1);
        tmpNum++;
      }

    }


    if(tmpG <= 0){
      if(result > tmpNum){
        result = tmpNum;
      }
    }
  }

  if(result > accumulate(p.begin(),p.end(),0)){
    result = accumulate(p.begin(),p.end(),0);
  }

  cout << result << endl;


  return 0;
}


Measured memory_bytes: 892
package main

import (
  "fmt"
)

func main() {
  var h, w int 
  fmt.Scan(&h, &w)
  res := make([]string, 0)
  for i := 0; i < h; i++ {
    var s string 
    fmt.Scan(&s)
    for j := 0; j < w; j++ {
      if s[j] == '#' {
        res = append(res, s)
        break
      }
    }
  }
  h = len(res)
  res2 := make([]string, 0)
  for j := 0; j < w; j++ {
    s := ""
    for i := 0; i < h; i++ {
      s += string(res[i][j])
    }
    for i := 0; i < h; i++ {
      if s[i] == '#' {
        res2 = append(res2, s)
        break
      }
    }
  }
  w = len(res2)
  for j := 0; j < h; j++ {
    for i := 0; i < w; i++ {
      fmt.Print(string(res2[i][j]))
    }
    fmt.Print("\n")
  }
}

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

using namespace std;
typedef long long int lld;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define trav(a,v) for(auto a:v)

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int H,W;
  cin>>H>>W;
  string grid[H];
  lld DP[H][W];
  rep(i,0,H){
    cin>>grid[i];
  }
  DP[0][0]=0;
  rep(i,0,H){
    rep(j,0,W){
      if(i>0 || j>0){
      DP[i][j]=10000000000;
      if(i>0){
	DP[i][j]=min(DP[i][j],DP[i-1][j]+((grid[i-1][j]=='#')&&(grid[i][j]=='.')));
      }
      if(j>0){
	DP[i][j]=min(DP[i][j],DP[i][j-1]+((grid[i][j-1]=='#')&&(grid[i][j]=='.')));
      }
      }
    }
  }
  cout<<(DP[H-1][W-1]+(grid[H-1][W-1]=='#'))<<endl;
  return 0;
}

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

int N,M;
char a[510][510],b[510][510];

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

    int i,j;
    for (i=1; i<=N; i++)
        for (j=1; j<=M; j++){
            cin >> a[i][j];
            b[i][j]=a[i][j];
        }

    for (i=1; i<=M; i+=2)
        for (j=2; j<N; j++)
            a[j][i]='#';

    for (i=2; i<=M; i+=2)
        for (j=2; j<N; j++)
            b[j][i]='#';

    for (j=1; j<=M; j++)
        a[1][j]=b[N][j]='#';

    for (i=1; i<=N; i++){
        for (j=1; j<=M; j++)
            cout << a[i][j];
        cout << "\n";
    }

    cout << "\n";

    for (i=1; i<=N; i++){
        for (j=1; j<=M; j++)
            cout << b[i][j];
        cout << "\n";
    }
    return 0;
}


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

int main(){
  int x, a;
  cin >> x >> a;
  if(x<a) cout << 0 << endl;
  else cout << 10 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string.h>
#include <stack>
#include <queue>
#include <algorithm>
#include <climits>
#include <cmath>
#include <map>
#include <set>
#define REP(i,n) for(ll i=0;i<(n);i++)
#define MOD 1000000007
#define int long long
#ifdef int
const long long INF = LLONG_MAX / 10;
#else
const int INF = 1010101010;
#endif
using namespace std;
typedef long long ll;
typedef vector<vector<ll>> mat;
typedef pair<int, int> P;
//typedef pair<double, double> P;

int N;
int a[202020];
int pos[202020];

signed main()
{
    cin >> N;
    REP(i,N) {
        cin >> a[i+1];
        pos[a[i+1]] = i + 1;
    }

    int ans = 0;
    set<int> se;
    se.insert(0);
    se.insert(N+1);
    for (int i=1; i<=N; i++) {
        se.insert(pos[i]);
        auto it = se.find(pos[i]);
        --it;
        int left = *it;
        ++it; ++it;
        int right = *it;
        ans += i * (pos[i] - left) * (right - pos[i]);
    }

    cout << ans << endl;
}


Measured memory_bytes: 12800
#include<iostream>
using namespace std;
int main()
{

int a,b,c,x;
int ans=0;
cin>>a>>b>>c>>x;
for(int i=0;i<=a;i++)
for(int j=0;j<=b;j++)
for(int k=0;k<=c;k++)
    if(500*i+100*j+50*k==x) ans++;
cout<<ans;

system("pause");
return 0;
}

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

using namespace std;

using ll=long long;
int n; 
ll f(vector<ll>& a) {
    ll sum = a[0];
    assert(sum != 0);
    ll cost = 0;
    for (int i = 1; i < n; i++) {
        if (sum > 0) {
            sum += a[i];
            ll d = max(sum, -1ll) - (-1);
            sum -= d;
            cost += d;
        } else {
            sum += a[i];
            ll d = 1 - min(sum, 1ll);
            sum += d;
            cost += d;
        }
    }
    return cost;
}

void solve() {
    cin >> n;
    vector<ll> a(n);
    for (auto& x: a) {
        cin >> x;
    }
    ll res = 1ll<<60;
    if (a[0] > 0) {
        res = min(res, f(a));
        ll d = a[0] + 1;
        a[0] = -1;
        res = min(res, d+f(a));
    } else if (a[0] == 0) {
        a[0] = 1;
        res = min(res, 1+f(a));
        a[0] = -1;
        res = min(res, 1+f(a));
    } else {
        res = min(res, f(a));
        ll d = 1 - a[0];
        a[0] = 1;
        res = min(res, d+f(a));
    }
    cout << res;
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    cout << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cassert>
#include <complex>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <sstream>
#include <ctime>
#include <cctype>
#include <set>
#include <map>
#include <queue>
#include <bitset>
#include <deque>
#include <stack>
#include <memory.h>
using namespace std;
#define ll long long 
string ans="ABC";
string to_String(int n)  
{  
    int m=n;  
    int i=0,j=0;  
    char s[100];  
    char ss[100];  
    while(m>0)  
    {  
        s[i++]= m%10 + '0';  
        m/=10;  
    }  
    s[i]='\0';  
    i=i-1;  
    while(i>=0)  
    {  
        ss[j++]=s[i--];  
    }  
    ss[j]='\0';  
    return ss;  
}
int main()
{
	int n;
	cin>>n;
	ans+=to_String(n);
	cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(vector<T> &x) {
	int n = x.size();
	rep(i,n) {
		cout << x[i];
		if (i!=n-1) cout<<" ";
		else cout << endl;
	}
}

template<typename T>
void print(vector<vector<T>> &x, int n, int m) {
	rep(i,n) {
		rep(j,m) {
			cout << x[i][j] << " ";
		}
		cout << endl;
	}
}

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; }

template< int mod >
struct ModInt {
	int x;

  	ModInt() : x(0) {}

	ModInt(int64_t y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}

	ModInt &operator+=(const ModInt &p) {
		if((x += p.x) >= mod) x -= mod;
		return *this;
	}

	ModInt &operator-=(const ModInt &p) {
		if((x += mod - p.x) >= mod) x -= mod;
		return *this;
	}

	ModInt &operator*=(const ModInt &p) {
		x = (int) (1LL * x * p.x % mod);
		return *this;
	}

	ModInt &operator/=(const ModInt &p) {
		*this *= p.inverse();
		return *this;
	}

	ModInt operator-() const { return ModInt(-x); }

	ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }

	ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }

	ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }

	ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }

	bool operator==(const ModInt &p) const { return x == p.x; }

	bool operator!=(const ModInt &p) const { return x != p.x; }

	ModInt inverse() const {
		int a = x, b = mod, u = 1, v = 0, t;
		while(b > 0) {
		t = a / b;
		swap(a -= t * b, b);
		swap(u -= t * v, v);
		}
		return ModInt(u);
	}

	ModInt pow(int64_t n) const {
		ModInt ret(1), mul(x);
		while(n > 0) {
		if(n & 1) ret *= mul;
		mul *= mul;
		n >>= 1;
		}
		return ret;
	}

	friend ostream &operator<<(ostream &os, const ModInt &p) {
		return os << p.x;
	}

	friend istream &operator>>(istream &is, ModInt &a) {
		int64_t t;
		is >> t;
		a = ModInt< mod >(t);
		return (is);
	}

	static int get_mod() { return mod; }
};

using modint = ModInt< MOD >;

constexpr int M = 2333;


int main(int argc, char const *argv[]) {
	int n,m;
	cin>>n>>m;
	vector<int> s(n), t(m);
	rep(i,n) cin>>s[i];
	rep(i,m) cin>>t[i];

	vector<vector<modint>> dp(M, vector<modint>(M, 0));
	vector<vector<modint>> sum(M+1, vector<modint>(M+1, 0));
	dp[0][0] = 1;

	for (int i = 1; i <= n; ++i) {
		for (int j = 1; j <= m; ++j) {
			if (s[i-1]==t[j-1]) dp[i][j] += sum[i-1][j-1]+1;
			sum[i][j] = dp[i][j]+sum[i][j-1]+sum[i-1][j]-sum[i-1][j-1];
		}
	}

	// print(dp,n+1,m+1);
	modint ans = 0;
	for (int i = 0; i <= n; ++i) for (int j = 0; j <= m; ++j) ans += dp[i][j];
	cout << ans << endl;
	return 0;
}

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

int main() {
  string S;
  cin >> S;
  int N=S.size();
  vector<int> pos(N);
  for (int i=0;i<N;i++){
    if (S[i]=='R'){
      if (S[i+1]=='L'){
        pos[i]=i;
      }
      else {
        continue;
      }
    }
    else {
      if (S[i-1]=='R'){
        pos[i]=i;
      }
      else {
        if (S[pos[i-1]]=='R'){
          pos[i]=pos[i-1]+1;
        }
        else {
          pos[i]=pos[i-1]-1;
        }
      }
    }
  }
  for (int i=N-1;i>=0;i--){
    if (S[i]=='R'&&S[i+1]=='R'){
      if (S[pos[i+1]]=='R'){
        pos[i]=pos[i+1]+1;
      }
      else {
        pos[i]=pos[i+1]-1;
      }
    }
  }
  vector<int> ans(N,0);
  for (int i=0;i<N;i++){
    ans[pos[i]]++;
  }
  for (int i=0;i<N;i++){
    cout << ans[i];
    if (i!=N-1){
      cout << ' ';
    }
    else {
      cout << endl;
    }
  }
}    

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
const long long maxn=305;
const long long inf=0x3f3f3f3f;
long long n;
long long a[maxn][maxn],ans=0;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	cin>>n;
	for(long long i=1;i<=n;i++)
		for(long long j=1;j<=n;j++)
			cin>>a[i][j];
	for(long long i=1;i<=n;i++)
	{
		for(long long j=i+1;j<=n;j++)
		{
			long long flag=0;
			for(long long k=1;k<=n;k++)
			{
				if(i!=k&&j!=k)
				{
					if(a[i][j]>a[i][k]+a[k][j])
					{
						cout<<"-1"<<endl;
						return 0;
					}
					if(a[i][j]==a[i][k]+a[k][j])
					{
						flag=1;
						break;
					}
				}
			}
			if(flag==0)
				ans+=a[i][j];
		}
	}
	cout<<ans<<endl;
	return 0;
}




Measured memory_bytes: 1024
m,n=map(int,input().split())
mod=1000000007

x=bin(n)[2:]
lst=[m for i in range(len(x))]
for i in range(1,len(x)):
    lst[i]=lst[i-1]**2
    lst[i]%=mod

sm=1
for i,b in enumerate(x):
    if b=="1":
        sm*=lst[len(x)-1-i]
        sm%=mod

print(sm)


Measured memory_bytes: 5604
import math
from functools import reduce
from collections import deque
import sys
sys.setrecursionlimit(10**7)

def s(generator, splitter, mapper):
    return [ mapper(s) for s in generator().split(splitter) ]

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

# 改行区切りの入力をn行読み込んで数値リストにして返します。
def get_nums_n(n):
    return [ int(input()) for _ in range(n)]

n,l = get_nums_l()

if (l <= 0 and (l+n-1) >= 0):
    print(sum(range(l, l+n)))
elif (l+n-1) < 0:
    print(sum(range(l, l+n-1)))
else:
    print(sum(range(l+1, l+n)))

Measured memory_bytes: 38384
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char s[500010];
long long a[500010]={},ans,num;
int main(){
    int n;
    
    scanf("%s",s);
    n=strlen(s);
    num=0;
    for(int i=0;i<n;i++){
        if(s[i]=='<'){
            num++;
        }
        else{
            num=0;
        }
        a[i+1]=max(a[i+1],num);
    }
    for(int i=n-1;i>=0;i--){
        if(s[i]=='>'){
            num++;
        }
        else{
            num=0;
        }
        a[i]=max(a[i],num);
    }
    for(int i=0;i<=n;i++){
        ans+=a[i];
    }
    printf("%lld\n",ans);
}

Measured memory_bytes: 4608
#include <iostream>  
using namespace std;  
int a,b,X,Y,S;
int maximum = 0;

int tax(int a, int b){
	return (b*(100+a))/100;
}

int solve (){
	maximum = 0;
	for (int i=1; i<S; ++i){
		for (int j=i; j<S; ++j){
			if (tax(X,i)+tax(X,j) == S)
				maximum = max(maximum, tax(Y,i)+tax(Y,j));
		}
	}
	return maximum;
	
}

int main()  
{     
	while (cin >> X >> Y >> S && X > 0){
		cout << solve() << endl;
	}        
	
	
	return 0;  
}  

Measured memory_bytes: 3092
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
 
using namespace std;
using namespace __gnu_pbds;

#define debug(s) cout << #s << " = " << s << endl
#define all(v) (v).begin(), (v).end()
#define mem(a,val) memset(a, val, sizeof a)
 
#define INF 1e15
#define ff first
#define ss second
typedef long long ll;

typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;

void min_self(ll &a, ll b) {
  a = min(a, b);
}
void max_self(ll &a, ll b) {
  a = max(a, b);
}

ll dp[100010];
int weight[110], value[110];

int main() {
  int n, w;
  scanf("%d%d", &n, &w);
  for (int i = 0; i < n; ++i) scanf("%d%d", &weight[i], &value[i]);
  int sum_value = 0;
  for (int i = 0; i < n; ++i) {
    sum_value += value[i];
  }
  for (int i = 0; i <= sum_value; ++i) dp[i] = INF;
  dp[0] = 0;
  // dp[i] - minimum weight to get value i
  for (int item = 0; item < n; ++item) {
    for (int value_already = sum_value - value[item]; value_already >= 0; --value_already) {
      min_self(dp[value_already + value[item]], dp[value_already] + weight[item]);
    }
  }
  ll ans = 0;
  for (int i = 0; i <= sum_value; ++i) {
    if (dp[i] <= w) max_self(ans, 1LL * i);
  }
  printf("%lld\n", ans);
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define space ' '
typedef long long ll;
typedef long double ld;
const long double PI = 3.14159265358979323846;

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

    string s;
    cin >> s;
    int n = s.size();
    if (n == 2 && s[0] == s[1]) {
        cout << 1 << space << 2 << endl;
        return 0;
    }
    pair<int, int> ans = { -1, -1 };
    for (int i = 0; i < n - 2; ++i) {
        unordered_map<char, int> occurs;
        occurs[s[i]] += 1;
        occurs[s[i + 1]] += 1;
        occurs[s[i + 2]] += 1;
        if (occurs[s[i]] > 1 || occurs[s[i + 1]] > 1 || occurs[s[i + 2]] > 1) {
            ans.first = i + 1;
            ans.second = i + 3;
            break;
        }
    }
    cout << ans.first << space << ans.second << endl;

    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
using LL = long long;
const LL LINF = 1e18;
const double EPS = 1e-10;
using namespace std;
#define COUT(v) cout<<(v)<<endl
#define CIN(n)  int(n);cin >> (n)
#define LCIN(n) LL(n);cin >> (n)
#define SCIN(n) string(n);cin >> (n)
#define YES(n) cout<<((n)? "YES" : "NO")<<endl
#define Yes(n) cout<<((n)? "Yes" : "No")<<endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) <<endl

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

#define FOREACH(x,a) for(auto& (x) : (a) )

#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<LL,LL>
#define I vector<int>
#define pb(v) push_back(v)
#define V vector
#define rt return
#define rmsame(a) sort(ALL(a)),a.erase(unique(ALL(a)), a.end())
#define ENDL cout<<endl

typedef string::const_iterator State;
class PalseError {};
class Edge{
public:
    int from,to,value;
    Edge(LL a,LL b,LL c){
        from = a;
        to = b;
        value = c;
    }
    Edge(LL a,LL b){
        from = a;
        to = b;
    }
};



int main(){
    SCIN(str);
    LL ans = LINF;
    REP(a,str.size()-2){
        string s = str.substr(a,3);
        ans = min(ans,(LL)abs(753-stoi(s)));
    }
    COUT(ans);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include <list>
#include<stack>
#include<queue>
#include <vector>
#include <set>
#include <map>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include <functional>
#include"time.h"
using namespace std;

#define FOR(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define REP(i,n) FOR((i),0,(n))
#define LL long long
#define CLR(a) memset((a),0,sizeof(a))
#define SZ(x) (int((x).size()))
#define dump(x)  cerr << #x << " = " << (x) << endl
#define WAITING(str) int str;std::cin>>str;
#define DEBUGING(str) cout<<str<<endl
const int INF = (1 << 30);

//毎回変える定数
#define N_MAX 200


//変数
string s;
vector<int> len;
vector<int>ans;


//サブ関数
//入力
void input() {
	cin >> s;
	char tmp = s[0];

	int length = s.size();
	len.push_back(length);
	FOR(i,1,length){
		if (tmp == s[i]) {
			continue;
		}
		else {
			tmp = s[i];
			len.push_back(max(i, length - i));
		}
	}
}


//計算
void calc() {
	
}


//出力
void output() {
	int ans = len[0];
	REP(i, (int)len.size()) {
		ans = min(ans, len[i]);
	}
	cout << ans << endl;
}

//デバッグ
void debug() {
	int N;
	cin >> N;
}


//メイン関数
int main() {

	input();
	calc();
	output();
	debug();

	return 0;
}


Measured memory_bytes: 768
//-------------
//include
//-------------
#include <map>
#include <list>
#include <cmath>
#include <vector>
#include <string>
#include <cctype>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
//-------------
//typedef
//-------------
typedef  long long LL;
typedef  vector<int> VI;
typedef  vector<double> VD;
typedef  string STR;
typedef  pair<int, int> PII;
typedef  vector<int, int> VII;
typedef  map<string, int> MSI;
//-------------
//utillty
//-------------
#define ALL(a)  (a).begin(),(a).end()
#define MK make_pair
#define PB push_back
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())
#define COUT(a) cout<<a<<endl
#define POW2(a) pow(a, 2.0)
//-------------
//repetition
//-------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//-------------
//debug
//-------------
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define dumpl(c) REP(i,SZ(c))cerr<<#c<<i<<"="<<(c[i])<<endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const int MOD = 1000000007;
int main()
{
	int a,b,c;
	cin >> a >> b >> c;
	if (a == b)
	{
		COUT(c);
	}
	else if(a == c)
	{
		COUT(b);
	}
	else if (b == c)
	{
		COUT(a);
	}

#ifdef _DEBUG
	while(1);
#endif // _DEBUG

	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,sse3,sse4,popcnt,abm,mmx")

//#include<bits/stdc++.h>
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <bitset>
#include <cstdio>
#include <limits>
#include <vector>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <fstream>
#include <numeric>
#include <sstream>
#include <cassert>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>

#define _USE_MATH_DEFINES
#define ll long long
#define ins Not Needed Thing
#define ull unsigned long long
#define ld long double
#define Accepted 0
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mp make_pair
#define sz(x) (int)(x.size())
#define all(x) x.begin(),x.end()
#define F first
#define S second
#define SORRY FUL Accepted 
#define SpeedForce ios_base::sync_with_stdio(0), cin.tie(0)
#define Toktama Kazakhstan 

using namespace std;

const double eps = 0.000001;
const ld pi = acos(-1);
const int maxn = 1e7 + 9;
const int mod = 1e9 + 7;
const ll MOD = 1e18 + 9;
const ll INF = 1e18 + 123;
const int inf = 2e9 + 11;
const int mxn = 1e6 + 9;
const int N = 3e3 + 123;                                          
const int PRI = 555557;
const int pri = 997;

int tests = 1;
int n, timer;
string a, b;
ll ans = 1;

inline void Solve () {
	//easy
	cin >> n >> a >> b;
	int last = 0;
	for (int i = n - 1; i >= 0; i --) {
		if (a[i] != b[i]) {
			i --;
			if (last == 0)
				ans = ans * 6 % mod;
			else if (last == 1)
				ans = ans * 2 % mod;
			else	
				ans = ans * 3 % mod;
			last = 2;
		} else {
			if (last == 0)	
				ans = ans * 3 % mod;
			else if (last == 1)
				ans = ans * 2 % mod;
			last = 1;
		}
	}
	cout << ans << '\n';
}

int main () {
	SpeedForce;
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);	
	// cin >> tests;
	while(tests --) {
		Solve ();
		// Ee Zadrot
	}

	return Accepted; 
}

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


int main(){
    string s;
    cin >> s;
    s[3]='8';
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int main(){
	long long a,b,c,t;
	scanf("%lld%lld%lld",&a,&b,&c);
	t=c-a-b;
	if(t<0){
		printf("No\n");
	}
	else{
		if(t*t>4*a*b){
			printf("Yes\n");
		}
		else{
			printf("No\n");
		}
	}
	return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
    char c=0;
    int flag=0;
    while(cin >> c)
    {
        if(c=='C')
            flag=1;
        if(c=='F'&&flag==1)
        {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
# coding: utf-8
from collections import defaultdict


def solve(*args: str) -> str:
    t = int(args[0])
    NABCD = [tuple(map(int, nabcd.split())) for nabcd in args[1:]]

    ret = []
    for n, a, b, c, d in NABCD:
        ABC = ((2, a), (3, b), (5, c))
        dp = defaultdict(lambda: n*d)
        stack = [(n, 0)]
        while stack:
            rem, cost = stack.pop()
            if min(dp[0], dp[rem]) <= cost:
                continue

            dp[rem] = cost
            dp[0] = min(dp[0], cost+rem*d)

            if 0 < rem:
                for x, y in ABC:
                    l, h = rem//x, -(-rem//x)
                    stack.append((l, d*abs(l*x-rem)+cost+y*(0 < l)))
                    stack.append((h, d*abs(h*x-rem)+cost+y))

        ret.append(str(dp[0]))

    return '\n'.join(ret)


if __name__ == "__main__":
    print(solve(*(open(0).read().splitlines())))


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

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

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

	int l, n;
	cin >> l >> n;

	vector<int> x(n);

	for (int &X : x) {
		cin >> X;
	}

	int res = l;

	for (int i = 0, last = x[n - 1]; i < n; i++) {
		res = min(last - x[i], res);
		last = x[i] + l;
	}

	cout << res;

	return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<cmath>
using namespace std;
int n;
void print(int n)
{
    if(n)
    {
        if(n%2==0)
        {
            print(n/-2);
            cout<<0;
        }
        else if(n%2==-1)
        {
            print(n/-2+1);
            cout<<1;

        }
        else if(n%2==1)
        {
            print(n/-2);
            cout<<1;
        }
    }
    else return;
}
int main()
{
    cin>>n;
    if(n==0)
        cout<<0;
    else
        print(n);
}


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

#define LL long long

int main() {
    ios::sync_with_stdio(0), cin.tie(0);
    
    LL a, b, c, d; cin >> a >> b >> c >> d;
    cout << max(a * c, max(a * d, max(b * d, b * c)));    
}

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

int main()
{
	char str[20];
	int length, i;

	scanf( "%s", str );
	length = strlen( str );

	for ( i = length - 1 ; i > -1 ; i-- )
	{
		printf( "%c", str[i] );
	}

	printf("\n");

	return 0;
}

Measured memory_bytes: 524
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main(){
    let mut v = read_vec::<u64>();
    v.sort();
    println!("{}",v[0]+v[1]);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long
#define endl '\n'
using namespace std;
unsigned gcd(unsigned a, unsigned b) {
    while (1) {
        if (a < b) swap(a, b);
        if (!b) break;
        a %= b;
    }
    return a;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, m;
    cin >> n >> m;
    string s, t;
    cin >> s >> t;
    ll l = n * m / gcd(n, m);
    ll g = gcd(n, m);
    for (int k = 0; k < g; k++) {
        if (s[k * n / g] != t[k * m / g]) {
            cout << -1 << endl;
            return 0;
        }
    }
    cout << l << endl;
    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
  int64_t power = 1;
  int64_t d = pow(10, 9) + 7;
  for (int i = 1; i <= N; i++) {
    power *= i;
    while (power >= d) {
      power %= d;
    }
  }
  cout << power << endl;
  return 0;
}

Measured memory_bytes: 3616
using System;
using System.Linq;
namespace aizu
{
    class OnlineJudge
    {
        static void Main()
        {
            string input;
            while((input = Console.ReadLine()) != "0") {
                int[] cards = input.Split().Select(q => int.Parse(q)).ToArray();
                int total = cards.Where(q => q > 1 && q < 10).Sum() + cards.Count(q => q >= 10 && q <= 13) * 10;
                int aceCount = cards.Count(q => q == 1);
                int[] pattern = new int[aceCount + 1];
                for(int i=0;i <= aceCount;++i){
                    pattern[i] = i * 11 + total + aceCount - i;
                }
                Console.WriteLine(pattern.Max(q => q > 21 ? 0 : q));
            }
        }
    }
}

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


int main(){
	int h,w,a,b;
	cin >> h >> w >> a >> b;
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			if((i<b)^(j<a))
				cout<<1;
			else
				cout<<0;
		}
		cout<<"\n";
	}
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define INF 999999999
#define ll long long
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

bool paircomp(const P& a, const P& b){
  return a.first < b.first;
}

int main(){
  int n, m;
  cin >> n >> m;
  vector<int> a(n);
  vector<P> b(m);
  ll sum = 0;
  int num = 0;
  bool b_end = false;
  REP(i,n){
    cin >> a[i];
  }
  REP(i,m){
    cin >> b[i].second >> b[i].first;
  }
  sort(a.begin(),a.end());
  sort(b.begin(),b.end(),paircomp);
  int x = n-1;
  int y = m-1;

  while(num < n){
    if(b_end || (a[x] > b[y].first)){
      sum += a[x];
      x--;
      num++;
    }
    else{
      sum += (ll)min(b[y].second, n-num) * (ll)b[y].first;
      num += b[y].second;
      if(y == 0) b_end = true;
      else y--;
    }
  }
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <cstdlib>
using namespace std;
#define REP(i,n) for(int i = 0;i < (int)(n);i++)

int main() {
	long long n, a[5];
	cin >> n;
	REP(i, 5) {
		cin >> a[i];
	}
	sort(a,a+5);
	cout << (n+a[0]-1) / a[0] + 4;
	return(0);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define MOD 1000000007
#define ff first
#define ss second
#define pb push_back
#define N 505

#define mod 998244353

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

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

ll bexp(ll a, ll b)
{
	ll res = 1;
	while(b)
	{
		if(b & 1)
		{
			res = res * a % mod;
		}
		a = a * a % mod;
		b >>= 1;
	}
	return res % mod;
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n;
	cin >> n;
	map<ll, ll> mi;
	ll a[n];
	for (int i = 0; i < n; ++i)
	{
		cin >> a[i];
		mi[a[i]]++;
	}
	// cout << mi.size() << "\n";
	int f = 0;
	if(mi[0] == n)
	{
		cout << "Yes\n";
		return 0;
	}

	if(n % 3 != 0)
	{
		cout << "No\n";
		return 0;
	}

	// if(mi.size() == 2)
	// {
	// 	ll k1 = mi.begin()->ff, l1 = mi.begin()->ss,
	// 	k2 = mi.rbegin()->ff, l2 = mi.rbegin()->ss;
	// 	if(l2 == 2 * l1 && l1 == 0)
	// 		f = 1;
	// 	else if(l1 == 2 * l2 && l2 == 0)
	// 		f = 1;
	// }
	// else if(mi.size() == 3)
	// {
	vector<int> b;
	for(auto e : mi)
	{
		for (int i = 0; i < e.ss / (n / 3); ++i)
		{
			b.pb(e.ff);
		}
	}
	if(b.size() == 3 && (b[0] ^ b[1] ^ b[2]) == 0)
	// 	f = 1;
	// // }

	// if(f)
		cout << "Yes\n";
	else
		cout << "No\n";
	 //  vector<int> all;
		// for (auto& p : mi) {
		// for (int i = 0; i < p.second / (n / 3); i++) {
		//   all.push_back(p.first);
		// }
		// }
		// if (all.size() == 3 && (all[0] ^ all[1] ^ all[2]) == 0) {
		// cout << "Yes" << '\n';
		// } else {
		// cout << "No" << '\n';
		// }
	return 0;
}

Measured memory_bytes: 5760
import copy
n=int(input())
a=[]
for i in range(n):
    a.append(int(input()))
    #print(a)

a1=max(a)
temp=copy.copy(a)
temp.remove(a1)
a2=max(temp)


for i in range(n):
    if a[i]==a1:
        print(a2)
    else:
        print(a1)

Measured memory_bytes: 14560