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

typedef long long int ll;
#define pb push_back
#define ff first
#define ss second
#define INF 1999999999
#define MODA 1000000007
#define PI 3.1415926535897932384626433
//cout << fixed << setprecision(2);


int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin >> n;
    vector<ll> v(n);
    for(int i = 0; i < n; i++){
        cin >> v[i];
    }
    
    sort(v.begin(), v.end());
    for(int i = 0; i < n; i++){
        if(v[i] == 0){
            cout << 0 << endl;
            exit(0);
        }
    }
    __int128_t lim = 1000000000000000000, mul = 1;
    for(int i = 0; i < n; i++){
        mul *= v[i];
        if(mul > lim){
            cout << -1 << endl;
            exit(0);
        }
    }
    cout << (ll)mul << endl;
    return 0;
}


Measured memory_bytes: 4348
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

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

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

    vector<vector<int>> dp1(n+2, vector<int>(t, 0));
    for(int i=0; i<n; i++){
        for(int j=0; j<t; j++){
            dp1[i+1][j] = dp1[i][j];
            if(j - a[i] >= 0) chmax(dp1[i+1][j], dp1[i][j - a[i]] + b[i]);
        }
    }

    vector<vector<int>> dp2(n+2, vector<int>(t, 0));
    for(int i=0; i<n; i++){
        for(int j=0; j<t; j++){
            dp2[i+1][j] = dp2[i][j];
            if(j - a[n-1-i] >= 0) chmax(dp2[i+1][j], dp2[i][j - a[n-1-i]] + b[n-1-i]);
        }
    }

    int ans = 0;
    for(int i=1; i<=n; i++){
        for(int j=0; j<t; j++){
            int head = dp1[i-1][j];
            int tail = dp2[n-i][t-1-j];
            chmax(ans, head + tail + b[i-1]);
        }
    }

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

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

long long sum, len;
int m;
long long c, d;

signed main () {
	scanf("%d", &m);
	for (int i = 0; i < m; ++i) {
		scanf("%lld %lld", &d, &c);
		sum += c * d;
		len += c;
	}
	printf("%lld\n", len - 1 + (sum - 1) / 9);
}


Measured memory_bytes: 3816
#include <bits/stdc++.h>
 
using namespace std;
#define sz(x) (int)(x).size()
#define pb push_back
#define all(x) (x).begin(),(x).end()
#define ll long long
const int N=3e5+5,MOD=1e9+7;
 
 
bool vis[5005];
int n;
int main()
{	
 	
 	scanf("%d",&n);

 	std::vector<int> dp(n),a(n);
 	for(int i=0;i<n;i++){
 		scanf("%d",&a[i]);
 		if(i-1 >= 0)dp[i]=dp[i-1]+abs(a[i]-a[i-1]);
 		if(i-2 >= 0)dp[i]=min(dp[i],dp[i-2]+abs(a[i]-a[i-2]));
 	}
 	printf("%d\n",dp[n-1] );
}
 

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define repr(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
const ll mod = 1e9 + 7;

int main() {
  int n, k, s;
  cin >> n >> k >> s;
  rep(i, k) cout << s << " ";
  rep(i, n - k) cout << (s + 1) % 1000000000 << " ";
  cout << endl;
  return 0;
}

Measured memory_bytes: 1280
#include"bits/stdc++.h"
using namespace std;
#define REP(k,m,n) for(int (k)=(m);(k)<(n);(k)++)
#define rep(i,n) REP((i),0,(n))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using tp3 = tuple<int, int, int>;
using Mat = vector<vector<ll>>;
constexpr int INF = 1 << 28;
constexpr ll INFL = 1ll << 60;
constexpr int dh[4] = { 0,1,0,-1 };
constexpr int dw[4] = { -1,0,1,0 };
bool isin(const int H, const int W, const int h, const int w) {
    return 0 <= h && h < H && 0 <= w && w < W;
}
template<typename T>
T minch(T& l, T r) {
    return l = min(l, r);
}
template<typename T>
T maxch(T& l, T r) {
    return l = max(l, r);
}
template<typename T>
void output(const T& val) {
    cout << val << endl;
}
template<typename T>
void output(const vector<T>& vec, const bool newline = false) {
    for (const T& val : vec)cout << val << (newline ? '\n' : ' '); cout << endl;
}
template<typename T>
void output(const vector<vector<T>>& mat) {
    for (const auto& row : mat)output(row);
}
// ============ template finished ============

vector<vector<int>> join(vector<string>& s, vector<int> sp) {
    const int H = s.size(), W = s.front().size(), M = sp.size() + 1;
    vector<vector<int>> res(M, vector<int>(W, 0));
    int D = 0;
    rep(h, H) {
        rep(w, W)if (s[h][w] == '1')res[D][w]++;
        if (find(sp.begin(), sp.end(), h) != sp.end())D++;
    }
    return res;
}

bool safe(vector<vector<int>>& table, int K) {
    for (auto& row : table)for (auto& col : row)if (col > K)return false;
    return true;
}

int judge(vector<vector<int>>& table, const int K) {
    const int H = table.size(), W = table.front().size();
    int res = 0;
    vector<int> buffer(H, 0);
    rep(w, W) {
        bool safe = true;
        rep(h, H) {
            buffer[h] += table[h][w];
            if (buffer[h] > K) {
                safe = false;
                break;
            }
        }
        if (!safe) {
            rep(h, H)buffer[h] = table[h][w];
            res++;
        }
    }

    return res;
}

int main()
{
    int H, W, K;
    cin >> H >> W >> K;
    vector<string> s(H);
    rep(i, H)cin >> s[i];

    int res = INF;
    rep(tway, 1 << (H - 1)) {
        vector<int> sp;
        int way = tway;
        rep(h, H - 1) {
            if (way & 1)sp.push_back(h);
            way >>= 1;
        }
        auto table = join(s, sp);
        if (!safe(table, K))continue;
        minch(res, (int)sp.size() + judge(table, K));
    }
    output(res);
    return 0;
}


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

int main(void)
{
	ios_base::sync_with_stdio(0);
	int n, m;
	cin >> n >> m;
	vector<int> a(n + 2, 0);
	for(int i = 0; i < m; i++) {
                int u, v;
                cin >> u >> v;
                a[u]++;
                a[v + 1]--;
	}
	int ans = 0;
	for(int i = 1; i <= n; i++) {
                a[i] += a[i - 1];
                if(a[i] == m)
                        ans++;
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 640
_,*s=open(0)
b,q='.'*101,range(101)
for i,s in enumerate(s):
  a=[i]
  for x,y,z,c in zip(b,'.'+s,s,q):
    a+=min(c+(x=='.'>z),a[-1]+(y=='.'>z)),
  b,q=s,a[1:]
print(a[-2])

Measured memory_bytes: 3060
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		String s1=sc.next();
		String s2=sc.next();
		int[][] g=new int[s1.length()+1][s2.length()+1];
		for(int i=0;i<s1.length()+1;i++){
			g[i][0]=i;
		}
		for(int j=1;j<s2.length()+1;j++){
			g[0][j]=j;
		}
		for(int i=1;i<s1.length()+1;i++){
			for(int j=1;j<s2.length()+1;j++){
				if(s1.substring(i-1,i).equals(s2.substring(j-1,j))){
					g[i][j]=g[i-1][j-1];
				}else{
					if(g[i-1][j]<=g[i][j-1] && g[i-1][j]<=g[i-1][j-1]){
						g[i][j]=g[i-1][j]+1;
					}else if(g[i][j-1]<=g[i-1][j] && g[i][j-1]<=g[i-1][j-1]){
						g[i][j]=g[i][j-1]+1;
					}else{
						g[i][j]=g[i-1][j-1]+1;
					}
				}
			}
		}
		System.out.println(g[s1.length()][s2.length()]);
	}
}


Measured memory_bytes: 68288
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e15;

const ll N=2e5+10;
vector<map<ll,ll>> si(N),dp(N);
vector<set<ll>> G(N);
ll n;

ll mpow(ll x, ll n) {
  ll ans=1;
  while(n>0) {
    if(n&1) {
      ans=ans*x%mod;
    }
    x=x*x%mod;
    n>>=1;
  }
  return ans;
}

vector<ll> tfact(1e7+1);
void fact(ll n) {
  for(ll i=0;i<=n;i++) {
    if(i==0) {
      tfact[i]=1;
    }
    else {
      tfact[i]=tfact[i-1]*i%mod;
    }
  }
}

ll dfs1(ll f, ll ff) {
  if(si[f][ff]) return si[f][ff];
  ll res=0;
  for(auto p:G[f]) {
    if(p==ff) continue;
    res+=dfs1(p,f);
  }
  if(ff) si[ff][f]=n-res-1;
  return si[f][ff]=res+1;
}

ll dfs2(ll f,ll ff) {
  if(dp[f][ff]) return dp[f][ff];
  ll res=1;
  if(dp[f][0]) {
    res=dp[f][0];
    (res*=mpow(dfs2(ff,f),mod-2)*tfact[dfs1(ff,f)]%mod)%=mod;
    (res*=mpow(tfact[dfs1(f,0)-1],mod-2))%=mod;
  }
  else {
    for(auto p:G[f]) {
      if(p==ff) continue;
      (res*=dfs2(p,f)*mpow(tfact[dfs1(p,f)],mod-2)%mod)%=mod;
    }
  }
  (res*=tfact[dfs1(f,ff)-1])%=mod;
  return dp[f][ff]=res;
}

ll dfs3(ll f) {
  queue<ll> q;
  q.push(f);
  while(q.size()) {
    ll n=q.front();
    q.pop();
    dfs2(n,0);
    for(auto p:G[n]) {
      if(dp[p][0]) continue;
      q.push(p);
    }
  }
}

int main() {
  cin >> n;
  for(ll i=0;i<n-1;i++) {
    ll a,b;
    cin >> a >> b;
    G[a].insert(b);
    G[b].insert(a);
  }
  fact(N);
  dfs3(1);
  for(ll i=1;i<=n;i++) {
    cout << dfs2(i,0) << endl;
  }
}

Measured memory_bytes: 202368
#include<bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
const int inf=1e9;
const ll Inf=1e18;
const int N=2e5+10;
const int mod=0;
int gi() {
    int x=0,o=1;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
template<typename T> bool chkmax(T &a,T b) { return a<b?a=b,1:0; };
template<typename T> bool chkmin(T &a,T b) { return a>b?a=b,1:0; };
int add(int a,int b) { return a+b>=mod?a+b-mod:a+b; }
int sub(int a,int b) { return a-b<0?a-b+mod:a-b; }
void inc(int &a,int b) { a=(a+b>=mod?a+b-mod:a+b); }
void dec(int &a,int b) { a=(a-b<0?a-b+mod:a-b); }
int n,m,col[N];
bool flag=0;
vector<int> E[N];
void dfs(int u,int c) {
    col[u]=c;
    for(int v:E[u]) {
        if(col[v]==col[u]) flag=0;
        else if(col[v]==-1) dfs(v,c^1);
    }
}
int main() {
    cin>>n>>m;
    for(int i=1,u,v;i<=m;i++) u=gi(),v=gi(),E[u].pb(v),E[v].pb(u);
    int cnt=0,cnt1=0,cnt2=0;
    for(int i=1;i<=n;i++) if(E[i].empty()) cnt++;
    memset(col,-1,sizeof(col));
    for(int i=1;i<=n;i++)
        if(col[i]==-1&&!E[i].empty()) {
            flag=1;dfs(i,0);
            flag?cnt2++:cnt1++;
        }
    ll ans=2ll*n*cnt-1ll*cnt*cnt+1ll*cnt1*cnt1+1ll*cnt1*cnt2+1ll*cnt2*cnt1+2ll*cnt2*cnt2;
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 12672
// ~/Remember,remember the 6th of March

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const double PI = acos(-1.0);
const double  EPS = 1e-8;
const ll MOD = 1000000007;
const int N = 100000 + 7;

int main()
{
    set<int>st;
    for(int i=1;i<10;i++)
        for(int j=1;j<10;j++)
            st.insert(i*j);
    int n;
    cin>>n;
    if(st.find(n)==st.end())
        puts("No");
    else
        puts("Yes");
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

class Program
{
    static void Main(string[] args)
    {
        new Program().Calc();
    }

    Scanner cin;

    public Program() { }

    void Calc()
    {
        cin = new Scanner();

        int n = cin.nextInt();

        int gcd = cin.nextInt();

        for (int i = 1; i < n; ++i)
        {
            int a = cin.nextInt();

            gcd = Gcd(a, gcd);
        }

        Console.WriteLine(gcd);
    }

    int Gcd(int n, int m)
    {
        int r;
        if (n > m)
        {
            int t = m;
            m = n;
            n = t;
        }
        while ((r = m % n) != 0)
        {
            m = n;
            n = r;
        }
        return n;
    }

}

class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 18144
#include <bits/stdc++.h>
using namespace std;
const long long mod = pow(10, 9) + 7;
const long long MOD = 998244353;
const long long INF = 1LL << 60;
const int inf = pow(10, 9) + 7;
template <class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template <class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
int divCeil(int A, int B) {return (A + (B - 1)) / B;}
long long divCeil(long long A, int B) {return (A + (B - 1)) / B;}
long long divCeil(int A, long long B) {return (A + (B - 1)) / B;}
long long divCeil(long long A, long long B) {return (A + (B - 1)) / B;}

int F(long long A, long long B)
{
  return max(log10(A), log10(B)) + 1;
}

int main()
{
  long long N;
  cin >> N;
  
  long long A, B;
  for (long long i = 1; i * i <= N; i++)
  {
    if (N % i == 0)
    {
      A = i;
      B = N / A;
    }
  }
  
  int ans = F(A, B);
  
  cout << ans << endl;
}

Measured memory_bytes: 640
N=int(input())
A=list(map(int,input().split()))

ans=1
x=y=0
c=A[0]

for i in range(1,N):
    if c < A[i]:
        x=1
    elif c>A[i]:
        y=1
    
    if x==1 and y==1:
        ans+=1
        x=y=0
    
    c=A[i]

print(ans)

Measured memory_bytes: 20132
N = int(input())
a = list(map(int, input().split()))
sum = 0
for i in a:
    sum += i
mean = sum / len(a)
min = 100
for i in range(len(a)):
    if min == abs(mean - a[i]):
        continue
    if min > abs(mean - a[i]):
        min = abs(mean - a[i])
        ans = i
print(ans)


Measured memory_bytes: 3060
import java.util.Arrays;
import java.util.Scanner;

public class Main {

	private static Scanner in;

    private static int n;
    private static int[] a;
    private static long[][] dp;

    public static void main(String[] args) {
        in = new Scanner(System.in);
        n = in.nextInt();
        a = new int[n];
        
        dp = new long[n][n];
        
        for(int i=0; i<n; i++) {
        	for(int j=0; j<n; j++) {
        		dp[i][j]=dp[i][j]=-1;
        	}
        }

        for(int i=0; i<n; i++) a[i] = in.nextInt();

        
//        for(int left=0; left<n; left++) {
//    		dp[left][left] = new long[] {a[left], -1*a[left]};
//        }
        
//        for(int length=2; length<=n; length++) {
//        	for(int left=0; left<n; left++) {
//            	for(int who=0; who<=1; who++) {
//                	int right = left+length-1;
//                	if (right>=n) continue;
//                	if (who==0) {
//                        dp[left][right][who]=Math.max(a[left]+dp[left+1][right][1-who], a[right]+dp[left][right-1][1-who]);
//                    } else {
//                        dp[left][right][who]=Math.min(-1*a[left]+dp[left+1][right][1-who], -1*a[right]+dp[left][right-1][1-who]);
//                    }
//            	}
//            }
//        }
        
//        System.out.println(dp[0][n-1][0]);
        
        System.out.println(solve(0, n-1, 0));

    }
    
    private static long solve(int left, int right, int who) {
        if (left==right) {
            if (who==0) return a[left];
            else return -1*a[left];
        } 
        
        if (dp[left][right]!=-1) return dp[left][right];

        if (who==0) {
            return dp[left][right]=Math.max(a[left]+solve(left+1, right, 1-who), a[right]+solve(left, right-1, 1-who));
        } else {
            return dp[left][right]=Math.min(-1*a[left]+solve(left+1, right, 1-who), -1*a[right]+solve(left, right-1, 1-who));
        }

    }

}


Measured memory_bytes: 132172
#include<iostream>
#include<cstring>
#include<string> 
using namespace std;
int main(){
	string str1,str2;
	cin>>str1>>str2;
	int len1=str1.length();
	int len2=str2.length();
	for(int i=0,j=0,num=1;num<=len1+len2;num++){
		if(num%2==1){
			cout<<str1[i];i++;
		}
		else {
			cout<<str2[j];j++;
		}
	}
	return 0;
} 

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const int MOD = 1000000007;
/* テンプレートここまで */

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

  map<ll, ll> mp;

  REP(i, N){
    ll A;
    cin >> A;
    mp[A] += 1;
  }

  vector<ll> x(2, 0);
  ll cur = 0;
  ll ans;

  for(auto i = mp.rbegin(); i != mp.rend(); i++){
    if(i->second >= 4 && cur == 0){
      ans = i->first * i->first;
      cout << ans << endl;
      return 0;
    }else if (cur < 2 && i->second >= 2){
      x.at(cur) = i->first;
      cur++;
    }
  }

  ans = x.at(0) * x.at(1);
  cout << ans << endl;
}


Measured memory_bytes: 6528
def gcd(l):
    if len(l) == 1:
        return l[0]

    v = gcd2(l[0], l[1])
    for i in range(2, n):
        v = gcd2(v, l[i])

    return v


def gcd2(a, b):
    if b == 0:
        return a

    return gcd2(b, a % b)


n, s = map(int, input().split())
x = list(map(int, input().split()))

x = [abs(xi - s) for xi in x]
print(gcd(x))


Measured memory_bytes: 14480
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n,m = sc.nextInt()
  val a = Array.fill(n,3)(sc.nextLong())
  val a1 = a.map(ai=>ai(0)+ai(1)+ai(2)).sortWith((x,y)=>(x>y)).take(m).sum
  val a2 = a.map(ai=>ai(0)+ai(1)-ai(2)).sortWith((x,y)=>(x>y)).take(m).sum
  val a3 = a.map(ai=>ai(0)-ai(1)+ai(2)).sortWith((x,y)=>(x>y)).take(m).sum
  val a4 = a.map(ai=>ai(0)-ai(0)-ai(2)).sortWith((x,y)=>(x>y)).take(m).sum
  val a5 = a.map(ai=>(-1)*ai(0)+ai(1)+ai(2)).sortWith((x,y)=>(x>y)).take(m).sum
  val a6 = a.map(ai=>(-1)*ai(0)+ai(1)-ai(2)).sortWith((x,y)=>(x>y)).take(m).sum
  val a7 = a.map(ai=>(-1)*ai(0)-ai(1)+ai(2)).sortWith((x,y)=>(x>y)).take(m).sum
  val a8 = a.map(ai=>(-1)*ai(0)-ai(1)-ai(2)).sortWith((x,y)=>(x>y)).take(m).sum
  println(Array(a1,a2,a3,a4,a5,a6,a7,a8).max)
}

Measured memory_bytes: 34716
k, n = gets.split.map(&:to_i)
a = gets.split.map(&:to_i).sort
ans = 10 ** 9

n.times do |start|
  goal = start == 0 ? n - 1 : start - 1
  tmp = k - (a[start] - a[goal]).abs
  tmp = a[goal] - a[start] if start == 0
  ans = tmp if ans > tmp
  # p [start, goal, tmp]
end
p ans

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

int a, b, c, d, e, x, y, z, h, w;
int sum = 0;
void input()
{
    cin >> a >> b >> c >> d >> e;
    sum += a + b + c + d + e;
}

void solve()
{
    sum += a % 10 == 0 ? 0 : 10 - a % 10;
    sum += b % 10 == 0 ? 0 : 10 - b % 10;
    sum += c % 10 == 0 ? 0 : 10 - c % 10;
    sum += d % 10 == 0 ? 0 : 10 - d % 10;
    sum += e % 10 == 0 ? 0 : 10 - e % 10;

    int m = 10;
    if (a % 10 != 0)
    {
        m = min(m, a % 10);
    }
    if (b % 10 != 0)
    {
        m = min(m, b % 10);
    }
    if (c % 10 != 0)
    {
        m = min(m, c % 10);
    }
    if (d % 10 != 0)
    {
        m = min(m, d % 10);
    }
    if (e % 10 != 0)
    {
        m = min(m, e % 10);
    }

    if (m == 10)
    {
        cout << sum << endl;
    }
    else
    {
        cout << sum - (10 - m) << endl;
    }
}
int main()
{
    input();
    solve();
}

Measured memory_bytes: 256
# (c) midandfeed
n = int(input())
	
for i in range(1, n+1):
	x = i
	if (x%3==0) or (x%10==3):
		print(" {}".format(x), end='')
	else:
		temp = x
		while(temp>0):
			if (temp%10==3):
				print(" {}".format(x), end='')
				break
			else:
				temp = temp//10
print()
	

Measured memory_bytes: 7856
//#define __USE_MINGW_ANSI_STDIO 0
#include <iostream>
#include <bits/stdc++.h>
using namespace std;

#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;

#define boost ios::sync_with_stdio(0); cin.tie(0)

#define fi first
#define se second

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

const int N = 1e6 + 5;

/***************************************************************************/

string S;
int F[N];

int main() {

	boost;
	int n; cin>>n;
	cin>>S; S = '_' + S;

	for(int i=1; i<=n; i++) {
		F[i] = F[i-1] + (S[i] == 'E');
	}

	int ans = n;
	for(int i=1; i<=n; i++) {
		ans = min(ans, i-1-F[i-1] + F[n]-F[i]);
	}

	cout<<ans<<"\n";
	
	return 0;
}

Measured memory_bytes: 1900
#include "bits/stdc++.h"
using namespace std;

#define Rep(i,n) for(int i=0;i<n;i++)
#define For(i,n1,n2) for(int i=n1;i<n2;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define RREP(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,n1,n2) for(ll i=n1;i<n2;i++)
#define put(a) cout<<a<<"\n";
#define all(a)  (a).begin(),(a).end();
#define SORT(a) sort((a).begin(),(a).end())
#define TDARRAY(int,a,n,m) vector<vector<int>> a(n,vector<int>(m,0));
#define oorret 0
#define oor(x) [&](){try{x;} catch(const out_of_range& oor){return oorret;} return x;}()

typedef long long ll;
typedef pair<int, int> P;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){if(a>b){a=b;return 1;}return 0;}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){if(a<b){a=b;return 1;}return 0;}

int n,m;

class UnionFind{
private:
    vector<int> par,height,size;
public:
    UnionFind(int n){
        par.resize(n);
        REP(i,n){
            par[i] = i;
        }
        height.resize(n,0);
        size.resize(n,1);
    }
    int root(int x){
        if(par[x]==x){
            return x;
        }else{
            par[x] = root(par[x]);
            return par[x];
        }
    }
    bool same(int x,int y){
        return root(x)==root(y);
    }
    void unite(int x,int y){
        x = root(x);
        y = root(y);
        if(x==y)return;
        if(height[x]<height[y]){
            par[x]=y;
            size[y]+=size[x];
        }else{
            par[y]=x;
            size[x]+=size[y];
            if(height[x]==height[y])height[x]++;
        }
    }
    int cnt(int x){
        x=root(x);
        return size[x];
    }
};

int main(){
    cin >> n >> m;
    vector<int> k(n);
    vector<vector<int>> l(n);
    vector<int> la(m);
    UnionFind  uf(m);
    REP(i,n){
        cin >> k[i];
        l[i].resize(k[i]);
        REP(j,k[i]){
            cin >> l[i][j];
            l[i][j]--;
            la[l[i][j]] = 1;
        }
    }
    REP(i,n){
        REP(j,k[i]-1){
            uf.unite(l[i][j],l[i][j+1]);
        }
    }
    bool flag = true;
    int head = uf.root(l[0][0]);
    
    REP(i,n){
        if(head!=uf.root(l[i][0])){
            flag = false;
        }
    }
    if(flag){
        put("YES");
    }else{
        put("NO");
    }
    return 0;
}


Measured memory_bytes: 7680
import sys
def fastio():
    from io import StringIO
    from atexit import register
    global input
    sys.stdin = StringIO(sys.stdin.read())
    input = lambda : sys.stdin.readline().rstrip('\r\n')
    sys.stdout = StringIO()
    register(lambda : sys.__stdout__.write(sys.stdout.getvalue()))
fastio()

INF = 10**20
MOD = 10**9 + 7
I = lambda:list(map(int,input().split()))
# from math import gcd
from math import ceil
from collections import defaultdict as dd, Counter
from bisect import bisect_left as bl, bisect_right as br

n, = I()
print(int(n ** 0.5) ** 2)

Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
const long long MD=1e9+7;
long long n,dp[100005],pre[100005],ans;
vector<int> v;
string str;
long long qpow(long long b,long long exp) {
    long long ret=1;
    while (exp!=0) {
        if (exp%2==1) {ret*=b; ret%=MD;}
        b*=b; b%=MD;
        exp/=2;
    }
    return ret;
}
int main() {
    cin>>str; n=str.size();
    for (int i=0; i<n; i++) {
        if (str[i]=='1') v.push_back(n-i-1);
    }
    v.push_back(0);
    dp[0]=1;
    for (int i=1; i<=n; i++) dp[i]=qpow(3,i-1);
    for (int i=1; i<=n; i++) {pre[i]=pre[i-1]+dp[i]; pre[i]%=MD;}
    ans+=pre[n-1];
    for (int i=0; i<v.size()-1; i++) {
        ans+=((dp[v[i+1]+1]*qpow(2,i))%MD); ans%=MD;
    }
    cout<<(1+(2*ans)%MD)%MD<<'\n';
}

Measured memory_bytes: 5492
// #pragma GCC target("avx")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
// #define BEGIN_STACK_EXTEND(size) void * stack_extend_memory_ = malloc(size);void * stack_extend_origin_memory_;char * stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long long)stack_extend_memory_)&127))*16);*stack_extend_dummy_memory_ = 0;asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024));
// #define END_STACK_EXTEND asm volatile("mov %%rax, %%rsp"::"a"(stack_extend_origin_memory_));free(stack_extend_memory_);

#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
#include<unordered_map>
#include<complex>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double INF=1e+10;
const long double PI=acos(-1.0);
const int C_SIZE = 3100000;
const int UF_SIZE = 3100000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	long long pw_mod(long long a,long long b,long long M){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%M;
			a=a*a%M;
			b/=2;
		}
		return ret;
	}
	int pw_mod_int(int a,int b,int M){
		if(a<0)return 0;
		if(b<0)return 0;
		int ret=1;
		while(b){
			if(b%2)ret=(long long)ret*a%M;
			a=(long long)a*a%M;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
	int UF[UF_SIZE];
	void init_UF(int n){
		for(int i=0;i<n;i++)UF[i]=-1;
	}
	int FIND(int a){
		if(UF[a]<0)return a;
		return UF[a]=FIND(UF[a]);
	}
	void UNION(int a,int b){
		a=FIND(a);b=FIND(b);if(a==b)return;
		// if(UF[a]>UF[b])swap(a,b);
		UF[a]+=UF[b];UF[b]=a;
	}
}
// ここから編集しろ
int p[110000];
int main(){
	int a,b;scanf("%d%d",&a,&b);
	for(int i=0;i<a;i++)scanf("%d",p+i);
	std::sort(p,p+a);
	long long ret=0;
	init_C(110000);
	for(int i=0;i<=a-b;i++){
		long long ks=Comb(a-i-1,b-1);
		ret=(ret+(mod-p[i])*ks)%mod;
	}
	for(int i=b-1;i<a;i++){
		long long ks=Comb(i,b-1);
		ret=(ret+(mod+p[i])*ks)%mod;
	}
	
	printf("%lld\n",ret);
}

Measured memory_bytes: 7552
s = input()

ch1 = ''
ch2 = ''
ct1 = 0
ct2 = 0
for c in s:
	if ch1 == '':
		ch1 = c
		ct1 += 1
	elif ch1 == c:
		ct1 += 1
	elif ch2 == '':
		ch2 = c
		ct2 += 1
	elif ch2 == c:
		ct2 += 1

if ct1 == 2 and ct2 == 2:
	print('Yes')
else:
	print('No')

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;

#define INF_LL (ll)1e18

#define INF (int)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
using ll = long long;
using PII = pair<int, int>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

class LazySegTree{
private:
	int n;
	vector<ll> node, lazy;
	vector<bool> lazyFlag;
public:
	LazySegTree(vector<ll> v){
		int sz = v.size();
		n = 1; while(n < sz) n *= 2;
		node.resize(2*n-1, 0);
		lazy.resize(2*n-1, 0);
		lazyFlag.resize(2*n-1, false);
		REP(i, sz) node[i+n-1] = v[i];
		for(int i = n-2;i >= 0;i--) node[i] = node[2*i+1]+node[2*i+2];
	}

	void eval(int k, int l, int r){
		if(lazyFlag[k]){
			node[k] += lazy[k] * (r-l);
			if(r-l > 1){
				lazy[2*k+1] += lazy[k];
				lazy[2*k+2] += lazy[k];
				lazyFlag[2*k+1] = lazyFlag[2*k+2] = true;
			}
			lazy[k] = 0;
			lazyFlag[k] = false;
		}
	}

	void add(int a, int b, ll x, int k=0, int l=0, int r=-1){
		if(r < 0) r = n;
		eval(k, l, r);
		if(b <= l || r <= a) return;

		if(a <= l && r <= b){
			lazy[k] += x;
			lazyFlag[k] = true;
			eval(k, l, r);
		}else{
			add(a, b, x, k*2+1, l, (l+r)/2);
			add(a, b, x, k*2+2, (l+r)/2, r);
			node[k] = node[k*2+1] + node[k*2+2];
		}
	}

	ll query(int a, int b, int k=0, int l=0, int r=-1){
		if(r < 0) r = n;
		eval(k, l, r);

		if(b <= l || r <= a) return 0;
		if(a <= l && r <= b) return node[k];

		return query(a, b, k*2+1, l, (l+r)/2) + query(a, b, k*2+2, (l+r)/2, r);
	}
};


int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	int res = 0;
	REP(i, s.size())
		res += s[i] == '1';
	cout << res << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define null nullptr
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define pb push_back
#define mp make_pair
#define test int t; cin>>t; while(t--)
#define FAST                          \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL)

using namespace std;

typedef vector<int> vi;
typedef vector<pair<int,int>> vii;
typedef pair<int,int> pii;
typedef unordered_map<int,int> mp;

const int mod = 1e9+7;

string solve(vi &a ,int n){

    for(int x=1;x<n;x++)
        if(a[x] > a[x-1]) a[x]--;
    
    for(int x=0;x<n-1;x++){
        if(a[x] > a[x+1]) return "No";
    }

    return "Yes";

}

int32_t main(){
    FAST;
    int n;  cin >> n;
    vi a(n);    for(int x=0;x<n;x++)    cin >> a[x];

    cout << solve(a,n) << endl;

    return 0;
}


Measured memory_bytes: 1024
use std::io;
use std::str::FromStr;
use std::collections::VecDeque;

struct Monster {
    pos: u64,
    life: u64,
}

type Pair = (u64, u64);

fn input_tuple() -> (u64, u64) {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    let vec: Vec<u64> = line.split_whitespace().map(|s| s.parse().unwrap()).collect();
    (vec[0], vec[1])
}

fn input_tuple_three() -> (u64, u64, u64) {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    let vec: Vec<u64> = line.split_whitespace().map(|s| s.parse().unwrap()).collect();
    (vec[0], vec[1], vec[2])
}

fn dru(n: u64, m: u64) -> u64 {
    if n % m == 0 {
        return n / m;
    } 
    n / m + 1
}

fn main() {
    let (n, d, a) = input_tuple_three();
    let mut monsters: Vec<Monster> = Vec::new();
    for _ in 0..n {
        let (x, h) = input_tuple();
        monsters.push(Monster {pos: x, life: h});
    }

    monsters.sort_by(|x, y| x.pos.cmp(&y.pos));

    let mut sum = 0;
    let mut cache: VecDeque<Pair> = VecDeque::new();
    let mut current_count = 0;
    for i in 0..n as usize {
        while cache.len() > 0 && cache.front().unwrap().0 < monsters[i].pos {
            current_count -= cache.pop_front().unwrap().1;
        }
        if monsters[i].life < a * current_count {
            continue;
        }
        monsters[i].life -= a * current_count;
        let count = dru(monsters[i].life, a);
        sum += count;
        current_count += count;
        cache.push_back((monsters[i].pos + 2 * d, count));
    }
    println!("{}", sum);
}


Measured memory_bytes: 11332
#include <cstdio>
#include<iostream>
#include<map>
#include<algorithm>
#include<vector>
#include <cmath>
#include <iomanip>
#include <regex>
#include <queue>
#include <set>
#include <cassert>
using namespace std;
using ll = long long;
using plong = 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 long MOD = 1000000007;
class mint {
    long long x;
public:
    mint(long long x=0) : x((x%MOD+MOD)%MOD) {}
    mint operator-() const { 
      return mint(-x);
    }
    mint& operator+=(const mint& a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint& a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const  mint& a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint& a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint& a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint& a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD-2);
    }
    mint& operator/=(const mint& a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint& a) const {
        mint res(*this);
        return res/=a;
    }

    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x;
        return os;
    }
};
// MOD
const long MAX = 200020;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (long i = 2; i < MAX; 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;
    }
}

// 二項係数計算
long COM(long n, long k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main(){
    ll H,W,A,B;
    cin>>H>>W>>A>>B;    
    COMinit();
    mint res=0;
    ll height = H-A;
    for(ll i=0;i<W-B;i++){
        ll width = W-i;
        res+=COM(height-1+width-1,height-1)*COM(i+A-1,A-1);
    }
    cout<<res<<endl;
}


Measured memory_bytes: 4992
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<string>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<iostream>
#include<algorithm>
#include<unordered_map>
#include<unordered_set>
#define PI acos(-1)
#define pb push_back
#define all(x) x.begin(),x.end()
#define INF 0x3f3f3f3f
#define dd(x) cout<<#x<<" = "<<x<<","
#define de(x) cout<<#x<<" = "<<x<<"\n"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N=1e5+5;
char c[N];
int main()
{
	ll a;
	scanf("%lld",&a);
	scanf("%s",c+1);
	
	ll b=(c[1]-'0')*100+(c[3]-'0')*10+c[4]-'0';
	
	ll ans=a*b/100;
	printf("%lld",ans);
}


Measured memory_bytes: 3816
#include <bits/stdc++.h>
using namespace std;
#define dhoom ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);  
typedef long long ll;
typedef long double ld;
const ll inf = 1e18;
const int nax = 2e6 + 7;
const ll mod = 1e9 + 7;
//ll tree[4 * nax];
//9uS-22RSwk7gQqh

int main(){
	dhoom;
	int n;
	cin >> n;
	set< int > st;
	for(int i = 0 , x; i < n ;i++){
		cin >> x;
		st.insert(x);
	}
	cout << st.size() << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
  int data[20],W[10],K[10],i,j;
  
  for(i=0;i<20;i++){
    scanf("%d",&data[i]);
    if(i<10)W[i]=data[i];
    else K[i-10]=data[i];
  } 
  
  for(i=0;i<10;i++)
    for(j=1;j<10;j++)
      if(W[j-1]<W[j]){
	int a=W[j];
	W[j]=W[j-1];
	W[j-1]=a;	
      }
 
 for(i=0;i<10;i++)
   for(j=1;j<10;j++)
     if(K[j-1]<K[j]){
       int b=K[j-1];
       K[j-1]=K[j];
       K[j]=b;	
      }

 printf("%d %d\n",W[0]+W[1]+W[2],K[0]+K[1]+K[2]);
 
 return 0;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string>
#include <iostream>
#include <math.h>
#define rep(i,n) for(int i = 0; i <(n); i++)
using namespace std;
typedef long long ll;

int main(void) {
	int N, tmp = -100, cnt = 0, val, i;
	vector<int> d;
	scanf("%d", &N);
	rep(i, N) {
		scanf("%d", &tmp);
		d.push_back(tmp);
	}
	sort(d.begin(), d.end());
	tmp = -100;

	rep(i, N) {
		val = d.at(i);
		if (val != tmp) {
			tmp = val;
			cnt++;
		}
	}
	printf("%d", cnt);


	return 0;
}

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

#define FOR(a,b,c) for(int a=(b),a##_end__=(c);a<a##_end__;a++)

int main(){
    int n,a,b;
    cin >> n >> a >> b;
    puts(a-b&1?"Borys":"Alice");
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;
#define ll long long

char a[10];
int num[4];

int main(){
    for(int i=0;i<4;i++){
        scanf("%c",&a[i]);
    }

    for(int i=0;i<4;i++){
        num[i]=a[i]-'0';
    }

    if((num[0]-num[1]-num[2]-num[3])==7){
        cout<<num[0]<<"-"<<num[1]<<'-'<<num[2]<<'-'<<num[3]<<"=7"<<endl;
    }else if((num[0]-num[1]-num[2]+num[3])==7){
        cout<<num[0]<<"-"<<num[1]<<'-'<<num[2]<<'+'<<num[3]<<"=7"<<endl;
    }else if((num[0]-num[1]+num[2]-num[3])==7){
        cout<<num[0]<<"-"<<num[1]<<'+'<<num[2]<<'-'<<num[3]<<"=7"<<endl;
    }else if((num[0]-num[1]+num[2]+num[3])==7){
        cout<<num[0]<<"-"<<num[1]<<'+'<<num[2]<<'+'<<num[3]<<"=7"<<endl;
    }else if((num[0]+num[1]-num[2]-num[3])==7){
        cout<<num[0]<<"+"<<num[1]<<'-'<<num[2]<<'-'<<num[3]<<"=7"<<endl;
    }else if((num[0]+num[1]-num[2]+num[3])==7){
        cout<<num[0]<<"+"<<num[1]<<'-'<<num[2]<<'+'<<num[3]<<"=7"<<endl;
    }else if((num[0]+num[1]+num[2]-num[3])==7){
        cout<<num[0]<<"+"<<num[1]<<'+'<<num[2]<<'-'<<num[3]<<"=7"<<endl;
    }else if((num[0]+num[1]+num[2]+num[3])==7){
        cout<<num[0]<<"+"<<num[1]<<'+'<<num[2]<<'+'<<num[3]<<"=7"<<endl;
    }
    return 0;
}

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

int main(){
	int a ;
	int f,s ;
	f = s = 0 ;
	cin >> a ;
	if(a==5) f++ ;
	else if(a==7) s++ ;
	else{
		cout << "NO" << endl ;
		return 0 ;
	}
	cin >> a ;
	if(a==5) f++ ;
	else if(a==7) s++ ;
	else{
		cout << "NO" << endl ;
		return 0 ;
	}
	cin >> a ;
	if(a==5) f++ ;
	else if(a==7) s++ ;
	else{
		cout << "NO" << endl ;
		return 0;
	}
	if(f==2&&s==1) cout << "YES" << endl ;
	else cout << "NO" << endl ;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;

class Main {

    static final int MOD = 1000000007;
    static final int INF = 1 << 30;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long ans = 0;
        int N = sc.nextInt();
        int K = sc.nextInt();
        System.out.println((int)Math.pow(K-1,N-1)*K);
    }
}


Measured memory_bytes: 21844
n = int(input())
a = [int(x) for x in input().split()]
abs_a = [abs(x) for x in a]

max_index = abs_a.index(max(abs_a))
max_value = a[max_index]
judge = True if max_value > 0 else False

ans = []
for i in range(n):
  if judge and a[i] < 0:
    a[i] += a[max_index]
    ans.append((max_index+1, i+1))
  if not judge and a[i] > 0:
    a[i] += a[max_index]
    ans.append((max_index+1, i+1))

if max_value > 0:
  for i in range(n-1):
    if a[i] > a[i+1]:
      ans.append((i+1, i+2))
      a[i+1] += a[i]
else:
  for i in range(n-1, 0, -1):
    if a[i-1] > a[i]:
      ans.append((i+1, i))
      a[i-1] += a[i]

print(len(ans))
for v in ans:
  print(*v)
  

Measured memory_bytes: 9128
#include <iostream>
#include <vector>
using namespace std;
int main(void)
{
    int n = 0;
    int abs_max = 0;
    vector<int> ax;
    vector<int> ay;
    
    cin >> n;
    
    ax.reserve(n);
    ay.reserve(n);
    
    for(int i = 0; i < n; i++)
    {
        int a;
        cin >> a;
        ax[i] = a;
        ay[i] = a;
    }
    
    for(int i = 0; i < n; i++)
    {
        for(int j = i + 1; j < n; j++)
        {
            int abs_tmp = abs(ax[i] - ay[j]);
            if(abs_tmp > abs_max)
            {
                abs_max = abs_tmp;
            }
        }    
    }
    
    cout << abs_max << endl;
    
    return 0;
}


Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
x = int(input())

res = 0
for i in range(a+1):
    for j in range(b+1):
        for k in range(c+1):
            if 500 * i + 100 * j + 50 * k == x:
                res += 1

print(res)

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

using i64 = long long;

const int N = 50 + 7;

int n;
int p[N];
i64 c, d;
i64 w[N], v[N];
int q[N];
i64 f[N * N * N];
i64 ans;

int main() {
//	freopen("code.in", "r", stdin);
//	freopen("code.out", "w", stdout);

	scanf("%d%d%d", &n, &c, &d);
	scanf("%lld", w + 1);
	for (int i = 2; i <= n; ++i)
		scanf("%lld%lld", w + i, p + i);
	for (int i = n; i; --i)
		w[p[i]] += w[i], v[p[i]] += ++v[i];

	std::fill(f + 1, f + n * n * n + 1, 1ll << 60);
	for (int i = 1; i <= n; ++i)
		for (int k = std::min(d, 1ll * n); k; --k)
			for (int j = n * n * n; j >= v[i]; --j)
				f[j] = std::min(f[j - v[i]] + w[i], f[j]);

	for (int i = 1; i <= n; ++i)
		q[i] = i;
	std::sort(q + 1, q + n + 1, [](int a, int b) {
		return v[a] * w[b] < v[b] * w[a];
	});
	for (int i = 0; i <= n * n * n; ++i) {
		if (f[i] > c) continue;
		i64 x = c - f[i], y = 0, z;
		for (int j = n; j; --j)
			z = std::min(x / w[q[j]], (q[j] == 1 ? 1ll << 60 : d - std::min(d, 1ll * n))),
			y += z * v[q[j]], x -= z * w[q[j]];
		ans = std::max(ans, i + y);
	}
	printf("%lld\n", ans);

	return 0;
}


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

struct UnionFind{
  vector<int> par;
  UnionFind(int N) : par(N){
    for(int i = 0; i < N; i++){
      par[i] = i;
    }
  }
  int root(int x){
    if(par[x] == x) return x;
    return par[x] = root(par[x]);
  }
  void unite(int x, int y){
    int rx = root(x), ry = root(y);
    if(rx == ry) return;
    par[rx] = ry;
  }
  bool same(int x, int y){
    return root(x) == root(y);
  }
};

int main(){
  int N, M; cin >> N >> M;
  UnionFind tree(N);
  vector<int> a(M), b(M);
  for(int i = 0; i < M; i++){
    cin >> a[i] >> b[i];
    --a[i]; --b[i];
  }
  
  int ans = 0;
  for(int i = 0; i < M; i++){
    UnionFind tree(N);
    for(int j = 0; j < M; j++){
      if(j != i) tree.unite(a[j], b[j]);
    }
    if(!tree.same(a[i], b[i])){
      ++ans;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner

object Main {
  def read() = {
    val sc = new Scanner(System.in)
    val cubes = sc.next()
    cubes
  }

  def solve(cubes: String): Int = {
    var n1 = 0
    var n0 = 0 // 不変条件: n1 == 0 OR n2 == 0
    for (cube <- cubes){
      if(cube == '0'){
        if(n1 != 0){
          n1 = n1 - 1
        }else{
          n0 = n0 + 1
        }

      }else if (cube == '1'){
        if(n0 != 0){
          n0 = n0 - 1
        }else{
          n1 = n1 + 1
        }
      }
    }
    cubes.length - Math.max(n0, n1)
  }


  def main(args: Array[String]): Unit = {
    val cubes = read()
    println(solve(cubes))
  }
}

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

using namespace std;

typedef long long ll;

ll dp[2005][2005];

int main(){

    ll n,x;
    cin>>n>>x;

    vector<ll> a(n, 0);
    ll resp = 0;

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

    for(int i = 0; i < n; ++i){
        for(int j = 1; j < n; ++j){
            int k = (i - j >= 0)? i - j : n + i - j;
            dp[i][j] = min(dp[i][j-1], a[k]);
        }
    }

    for(int i = 1; i < n; ++i){
        ll cur = i*x;
        for(int j = 0; j < n; ++j){
            cur += dp[j][i];
        }
        //cout<<cur<<'\n';
        resp = min(resp, cur);
    }

    cout<<resp<<'\n';

}

Measured memory_bytes: 31616
#include<bits/stdc++.h>
#define lson l, mid
#define rson mid+1, r
#define PII pair<int, int>
#define Size(x) (int)(x.size())
using namespace std;
typedef long long LL;
//const int MOD = 1e9+7;
const auto INF = 0x3f3f3f3f;
const int N = 3e2+5;
int a[N][N], num[N], Next[N];
bool visit[N];

int main() {
    int n, m;
    scanf("%d%d", &n, &m);
    for(int i=1; i<=n; i++) {
        for(int j=1; j<=m; j++) {
            scanf("%d", &a[i][j]);
        }
    }
//    for(int i=1; i<=n; i++) {
//        num[a[i][1]]++;
//        Next[i] = 1;
//    }
    int maxx = INF;
    for(int T=1; T<=m; T++) {
        int temp = 0, pos = 0;
//        for(int i=1; i<=m; i++) {
//            if(temp < num[i]) {
//                temp = num[i];
//                pos = i;
//            }
//        }
        memset(num, 0, sizeof(num));
        for(int i=1; i<=n; i++) {
            for(int j=1; j<=m; j++) {
                if(!visit[a[i][j]]) {
                    num[a[i][j]]++;
                    break;
                }
            }
        }
        for(int i=1; i<=m; i++) {
            if(temp < num[i]) {
                temp = num[i];
                pos = i;
            }
        }
        maxx = min(maxx, temp);
        visit[pos] = true;
    }
    printf("%d\n", maxx);
}





Measured memory_bytes: 640
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <numeric>
#include <string>
#include <sstream>
#include <cmath>
#include <cstring>
#include <assert.h>
#include <utility>
#include <tuple>
#include <array>
#include <bitset>
#include <cstdlib>

using int64 = long long;

using namespace std;

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

    string s, t;
    cin >> s;
    cin >> t;

    if (s == t.substr(0, s.size())) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}



Measured memory_bytes: 3164