akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main()
{
	long a[200000];
	long b[200000];
	long x,y,i,n,m;
	scanf("%ld %ld", &n, &m);
	for (i = 0; i < m; i++) {
		a[i] = 0;
		b[i] = 0;
	}
	for (i = 0; i < m; i++) {
		scanf("%ld %ld", &x, &y);
		if (x == 1) {
			a[y-1] = 1;
		}
		if (y == n)
			b[x-1] = 1;
	}
	for (i = 0; i < m; i++) {
		if (a[i] == b[i]&&a[i] == 1) {
			printf("POSSIBLE");
			return 0;
		}
	}
	printf("IMPOSSIBLE");
	return 0;

}

Measured memory_bytes: 3328
def solve(A, B, C, X, Y):
    ret = float("inf")
    for a_num in range(X + 1):
        ab_num = 2 * (X - a_num)
        price = min(
            a_num * A + max(0, Y - ab_num // 2) * B + ab_num * C,
            a_num * A + max(ab_num, 2 * Y) * C
        )
        ret = min(ret,price)
    return ret

if __name__ == "__main__":
    A, B, C, X, Y = map(int, input().split())
    print(solve(A, B, C, X, Y))

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

/*
int main() {
  long long int a;
  cin >> a;
  long long int ans = 0;
  long long int c,d,e,f,g,h;
  for(int i = 0;i < 5;i++){
    long long int b;
    cin >> b;
    if(a&b == 0){
      ans += a/b;
      a = b;
    }else{
      ans += a/b+1;
      a = a%b;
    }
  }
  cout << ans << endl;
}
*/

int main(){
  long long int a;
  cin >> a;
  long long int b[5];
  long long int min;
  for(int i = 0;i < 5;i++){
    cin >> b[i];
    if(i == 0){
      min = b[i];
    }else{
      if(b[i] < min){
        min = b[i];
      }
    }
  }
  long long int ans = 0;
  ans = 5;
  if(a%min == 0){
    ans += a/min-1;
  }else{
    ans += a/min;
  }
  cout << ans << endl;
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math,O3")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define fastio ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
#define fr(i,a,b) for(int i=a;i<=b;i++)
#define input(a) for(auto &t:a){cin>>t;}
#define maxe(a,b,c) max(a,max(b,c))
#define eb emplace_back
#define em emplace
#define print(x) cout<<x<<endl;
#define fill(a,val) memset(a,val,sizeof(a))
#define in(k) int k;cin>>k
#define edl cout<<"\n"
#define ll  long long
#define ld  long double
#define mp  make_pair
#define ff  first
#define ss  second
#define pii pair<ll,ll>
#define sq(x) ((x)*(x))
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
const ll mod=1e9+7;
signed main()
{
    //cout<<fixed<<setprecision(20);
    fastio;
    double k,a,b;cin>>k>>a>>b;
    double p=(b/k)-ceil((a/k));
    if(p>=0)
    cout<<"OK";
    else
    cout<<"NG";
    //printclock;
    return 0;
}

Measured memory_bytes: 3744
from functools import lru_cache

def main():
    n,m = map(int,input().split())
    import numpy as np
    ans = np.ones(n+1,dtype=int)*-1
    ans[0] = 1
    mod = 10**9+7
    for _ in range(m):
        a = int(input())
        ans[a]=0
    if ans[1]!=0:
        ans[1]=1
    for i in range(2,n+1):
        if ans[i]!=0:
            ans[i] = (ans[i-1]+ans[i-2])%mod
    print(ans[-1])
        

if __name__ == "__main__":
    main()

Measured memory_bytes: 21760
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    int n;
    cin >> n;
    int a[n];
    int cnt[n];
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        cnt[i] = 0;
    }
    ll mod = 1e9 + 7;
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        cnt[a[i]]++;
    }
    if(n % 2 == 0) {
        for (int i = 0; i < n; i++) {
            if (i % 2 == 1) {
                if (cnt[i] != 2) {
                    cout << ans << endl;
                    return 0;
                }
            } else {
                if (cnt[i] != 0) {
                    cout << ans << endl;
                    return 0;
                }
            }
        }
    } else {
        if (cnt[0] != 1) {
            cout << ans << endl;
            return 0;
        }
        for (int i = 1; i < n; i++) {
            if (i % 2 == 0) {
                if (cnt[i] != 2) {
                    cout << ans << endl;
                    return 0;
                }
            } else {
                if (cnt[i] != 0) {
                    cout << ans << endl;
                    return 0;
                }
            }
        }
    }
    ans = 1;
    for (int i = 0; i < n / 2; i++) {
        ans *= 2;
        ans %= mod;
    }
    cout << ans << endl;


    return 0;
}


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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int64 n = s.size();
    int64 ans = n * (n - 1) / 2 + 1;
    vector<int64> cnt(26,0);
    REP(i,n){
        cnt[s[i]- 'a']++;
    }
    REP(i,26){
        ans -= cnt[i] * (cnt[i] - 1) / 2;
    }
    ANS(ans);
    return 0;
}

Measured memory_bytes: 720
package main

import (
	"bufio"
	"fmt"
	"os"
)

var (
	in = bufio.NewReader(os.Stdin)
)

func main() {
	var n, red, blue int
	_, _ = fmt.Scanf("%d", &n)
	slice := readString()
	for _, val := range slice {
		if string(val) == "R" {
			red++
		} else {
			blue++
		}
	}
	if red > blue {
		fmt.Printf("Yes")
	} else {
		fmt.Printf("No")
	}
}

func readString() string {
	s, _, _ := in.ReadLine()
	return string(s)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define int long long

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

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

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

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

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int n, a, b;
    cin >> n >> a >> b;
    vector<int> x(n);
    REP(i, n) cin >> x[i];
    int ans = 0;
    REP(i, n-1){
        ans += min(a * (x[i+1]-x[i]), b);
    }

    cout << ans << endl;
}


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

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> s(m), c(m);
    rep(i,m) {
        cin >> s[i] >> c[i];
        s[i]--;
    }
    vector<int> ans(n,-1);
    rep(i,m) {
        if(n != 1 && s[i] == 0 && c[i] == 0) {
            cout << -1 << endl;
            return 0;
        }
        if(ans[s[i]] == -1) ans[s[i]] = c[i];
        else if(ans[s[i]] != c[i]){
            cout << -1 << endl;
            return 0;
        }
    }
    rep(i,n) {
        if(n != 1 && ans[0] == -1) ans[0] = 1;
        if(ans[i] == -1) ans[i] = 0;
        cout << ans[i];
    }
    cout << endl;
}

Measured memory_bytes: 3616
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner sc= new Scanner(System.in);
		String str=sc.nextLine();
		int length=str.length();
		boolean result= true ;
		if(length >=2 &&length<=26){
			for(int i=0;i<length;i++){
				char c=str.charAt(i);
				for(int j=i+1;j<length;j++){
				if (c==str.charAt(j))
				{result=false;}
			        }
		            }				
	                 }
		else result=false;
        if(result==true)
        {System.out.println("yes");}
        else {System.out.println("no");}
}
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define repi(i,x) for(auto i=(x).begin(),i##_fin=(x).end();i!=i##_fin;i++)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define solve(a) ((a)?"Yes":"No")
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef pair<int , int> Pi;
typedef vector<Pi> VPi;
typedef vector<long long> V;
typedef vector<V> VV;
typedef pair<long long , long long> P;
typedef vector<P> VP;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<60;
const int INF = 1<<30;
const double PI=acos(-1);
int main(){
	int h,w;
	//int ans=0;
	cin >>h>>w;
	int n;
	cin>>n;
	Vi a(n);
	rep(i,n){
		cin>>a[i];
	}
	int at=0;
	char ins;
	VVi ans(h,Vi(w,0));
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(i%2==0){
				ans[i][j]=at+1;
				

			}else{
				ans[i][w-j-1]=at+1;
			}
			a[at]--;
			if(a[at]==0){
				at++;
			}
		}
	}
	rep(i,h){
		rep(j,w){
			cout<<ans[i][j];
			if(j==w-1){
				cout<<endl;
			}else{cout<<" ";}
		}
		//cout<<ans[i]<<endl;
	}
	//cout<<ans<<endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define ll long long int
#define dbg(x) cout<<"( "<<#x<<" -> "<<x<<" )"<<endl;
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    string s;
    cin>>s;
    if (n%2==1)
    printf("No\n");
    else
    {
        int c=0;
        for (int i=0;i<n/2;i++)
        {
            if (s.at(i)==s.at(i+n/2))
            c++;
        }
        if (c==n/2)
        printf("Yes\n");
        else
        printf("No\n");
    }
    return 0;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define pb push_back
using namespace std;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef long long ll;
typedef unsigned long long ull;

int main() {
  int x,a,b;
  cin>>x>>a>>b;
  int da=abs(x-a);
  int db=abs(x-b);
  if(da>db) cout<<"B"<<endl;
  else cout<<"A"<<endl;
}

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

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

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

using namespace std;

typedef int64_t ll;
typedef double dbl;
typedef vector<bool> Vb;
typedef vector<char> Vc;
typedef vector<double> Vd;
typedef vector<int> Vi;
typedef vector<ll> Vl;
typedef vector<string> Vs;
typedef vector<vector<int>> VVi;
typedef vector<vector<ll>> VVl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;

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

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


int main()
{
	int n;
	vector<pii> s;

	cin >> n;
	REP(i, n)
	{
		int a; cin >> a;
		s.PB(pii(a, i + 1));
	}

	sort(ALL(s));

	REP(i, n)
		cout << s[i].second << " ";
	cout << endl;

}


Measured memory_bytes: 1780
#include <bits/stdc++.h>
typedef long long ll;
#define mod 1000000007
using namespace std;
ll n,m,memo[1005][1005];
char arr[1005][1005];
int solve(int i,int j)
{
//    cout << i << ' ' << j << endl;
     if (i >= n || j >= m || arr[i][j] == '#')
         return 0;
     if(i == n-1 && j == m-1)
         return 1;
     if(~memo[i][j])
         return (memo[i][j] % mod);
     ll ans = solve(i+1,j);
     ans = (ans + solve(i, j + 1))% mod;
     memo[i][j] = ans;
     return (ans%mod);
}
int main()
{
    cin >> n >> m;
    memset(memo,-1,sizeof memo);
    for(int i = 0;i<n;i++)
        for(int j = 0;j<m;j++)
            cin >> arr[i][j];
    cout << solve(0,0)%mod;
    return 0;
}

Measured memory_bytes: 9216
#include <iostream>
#include <math.h>
#include <string.h>
#include <vector>
#include <algorithm>
#include <stack>



using namespace std;

int main() {
    int n;
    cin>>n;
    int h[n];
    for(int i=0;i<n;i++){
        cin>>h[i];
    }
    int max=0;
    int ans=0;
    for(int i=0;i<n;i++){
        if(max<=h[i]){
            max=h[i];
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <tr1/unordered_map>
#define debug(x) (cout << "#x = " << (x) << endl)
#define lowbit(x) (x & -x)
#define Set(x, i) memset(x, i, sizeof x)
#define R register
#define For( i, j, k ) for(R int i = (j); i <= (k); ++i)
#define Rep( i, j, k ) for(R int i = (j); i >= (k); --i)
#define Cross( i, j, k ) for(R int i = (j); i; i = (k))
typedef long long ll;
using namespace std;
const ll N = 100011;
const ll INF = 5e16;

namespace IO {

	#define dd ch = getchar()
	inline ll read() {
		ll x = 0; bool f = 0; char dd;
		for (; !isdigit (ch); dd) f ^= (ch == '-');
		for (; isdigit (ch); dd)  x = x * 10 + (ch ^ 48);
		return f? -x: x;
	}
	#undef dd

	inline void write ( ll x ) {
		if (x < 0) putchar ('-'), x = -x;
		if (x > 9) write (x / 10); putchar (x % 10 | 48);
	}

	inline void wrn ( ll x ) { write(x); putchar (' '); }

	inline void wln ( ll x ) { write(x); putchar ('\n'); }

	inline void wlnn ( ll x, ll y ) { wrn(x); wln (y); }

}

using namespace IO;

namespace Cesare {
	
	const ll M = 1011;
	
	ll H, W, A, B, pos, V[M], mp[M][M];
	
	struct Node {
		ll id, c;
		inline bool operator < ( const Node &b ) {
			return id < b.id;
		}
	};
	
	vector <Node> V1, V2;
	
	int main() {
		H = read(), W = read();
		A = read(), B = read(); 
		For ( i, 1, B ) For ( j, 1, W ) mp[i][j] = 1;
		For ( i, 1, H ) For ( j, 1, A ) mp[i][j] ^= 1;
		for (int i = 1; i <= H; ++i, puts("")) 
			For ( j, 1, W ) putchar(mp[i][j] | 48);
		return 0;
	}
	
}

int main()
{
	return Cesare :: main();
}

/*

*/



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

using namespace std;
typedef long long ll;

ll N,D,A;
vector<ll> X,H,P;
vector<pair<ll,ll>> v;

int main(){
    ll c = 0;
    cin >> N >> D >> A;
    for(int i=0;i<N;i++){
        ll x,h;
        cin >> x >> h;
        v.push_back(make_pair(x,h));
        P.push_back(0);
    }
    sort(v.begin(),v.end());
    for(auto &e : v){
        X.push_back(e.first);
        H.push_back(e.second);
    }
    ll t = H[0] / A;
    if(H[0]%A != 0) t++;
    c += t;
    t *= A;
    P[0] -= t;
    ll ind = upper_bound(X.begin(),X.end(),X[0]+2*D) - X.begin();
    if(ind < N) P[ind] += t;
    for(int i=1;i<N;i++){
        P[i] += P[i-1];
        if(H[i] + P[i] <= 0) continue;
        H[i] += P[i];
        t = H[i] / A;
        if(H[i]%A != 0) t++;
        c += t;
        t *= A;
        P[i] -= t;
        ll ind = upper_bound(X.begin(),X.end(),X[i]+2*D) - X.begin();
        if(ind < N) P[ind] += t;
    }
    cout << c << endl;
    return 0;
}

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

int main() {
    long long n, ans=0;
    cin >> n;
    for(int i=1; i<=n; i++) {
        ans+=i;
        if(i%3==0) ans-=i;
        if(i%5==0) ans-=i;
        if(i%15==0) ans+=i;
    }
    cout << ans;
}

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

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define EXIST(m,v) (m).find((v)) != (m).end()
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

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

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

void Main(){
    int n;
    cin >> n;
    int ac = 0;
    int wa = 0;
    int tle = 0;
    int re = 0;
    REP(i, n) {
        string s;
        cin >> s;
        if (s == "AC") ac++;
        if (s == "WA") wa++;
        if (s == "TLE") tle++;
        if (s == "RE") re++;
    }
    cout << "AC x " << ac << en;
    cout << "WA x " << wa << en;
    cout << "TLE x " << tle << en;
    cout << "RE x " << re << en;
    return;
}

int main(void){
    cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t) Main();
    return 0;
}


Measured memory_bytes: 3656
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int k,x,i,j;
    cin>>k>>x;
    for(i=x-(k-1);i<=x;i++)
    {
        cout<<i<<" ";
    }
    for(j=x+1;j<=x+(k-1);j++)
    {
        cout<<j<<" ";
    }
}





Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
ll mm=1000000000;ll MM=mm+7;
#define rep(i, n) for(int i=0;i<n;i++)
 
int n;
VI x(9);
VI y(9);

double dist(int i,int j){
  double dx=x.at(i)-x.at(j);
  double dy=y.at(i)-y.at(j);
  return sqrt(dx*dx+dy*dy);
}

int main(){
  cin >> n;
  for(int i=1;i<=n;i++) cin >> x.at(i) >> y.at(i);
  VI v(n);
  for(int i=0;i<n;i++) v.at(i)=i+1;
  double sum=0;
  do{
    for(int i=0;i<n-1;i++) sum+=dist(v.at(i),v.at(i+1));
    }while(next_permutation(v.begin(),v.end()));
   int times=1;
  for(int i=2;i<=n;i++) times*=i;
  cout << fixed <<setprecision(8) << sum/times << endl;
  
}

Measured memory_bytes: 256
N = int(input())

dices = []
for i in range(N):
    d_1, d_2 = [int(i) for i in input().split()]
    dices.append((d_1,d_2))
    
flag = False

counter = 0
for d in dices:
    if d[0] == d[1]:
        counter += 1
    else :
        counter = 0
    if counter >= 3:
        flag = True
        break
        
if flag:
    print('Yes')
else :
    print('No')

Measured memory_bytes: 9192
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>
#include <deque>
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;
using vi = vector<int>;
using vll = vector<ll>;
ll mod = 1e9 + 7;
ll llmax = 10000000000000000000ll;
using namespace std;
using Graph = vector<vector<int>>;
Graph G;
const int AMAX = 100000;
/*int cnt_digit(ll N)
{
	int digit = 0;

	while (N > 0)
	{
		N /= 10;
		digit++;
	}
	return digit;
}



int n;
vll a;

ll solve(bool isp)
{
	ll sum = 0ll;
	ll ret = 0ll;

	for (int i = 0; i < n; i++)
	{
		sum += a[i];
		if (isp and sum <= 0)
		{
			ret += -sum + 1;
			sum = 1ll;
		}
		if (not isp and sum >= 0)
		{
			ret += sum + 1;
			sum = -1ll;
		}
		isp ^= 1;
	}
	return ret;
}

*/


/*
 * 最大公約数計算
 */
int gcd(int a, int b)
{
	if (b == 0) {
		return a;
	}
	else {
		return gcd(b, a % b);
	}
}

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

	int size = s.size();
	char f = s.at(0);
	char l = s.at(size - 1);
	cout << f << size - 2 << l << endl;
	
	
	return 0;

	


}


Measured memory_bytes: 256
import sys

MOD = 10 ** 9 + 7

def main():
    n, m = [int(s) for s in input().split()]
    print(solve(m, n))

def solve(m, n):
    factors = list(get_prime_factors(m))
    h = max((c for f, c in factors), default=0)

    table = dict()
    table[1] = [1 for _ in range(h + 1)]

    i = 1
    while i < n:
        j = n & (i - 1)
        table[i * 2] = [0 for _ in range(h + 1)]
        if n & i != 0 and j != 0:
            table[i + j] = [0 for _ in range(h + 1)]
        for x in range(h + 1):
            for y in range(h + 1 - x):
                table[i * 2][x + y] = (table[i * 2][x + y] + table[i][x] * table[i][y]) % MOD
                if n & i != 0 and j != 0:
                    table[i + j][x + y] = (table[i + j][x + y] + table[i][x] * table[j][y]) % MOD

        if n & i == 0:
            del table[i]
        if n & i != 0 and j != 0:
            del table[i]
            del table[j]

        i *= 2

    ans = 1
    for f, c in factors:
        ans = ans * table[n][c] % MOD
    return ans

def get_prime_factors(n):
    import itertools

    m = n
    for i in itertools.count(2):
        if i * i > m:
            break

        c = 0
        while True:
            x, y = divmod(m, i)
            if y != 0:
                break
            c += 1
            m = x
        if c != 0:
            yield i, c

    if m != 1:
        yield m, 1


main()


Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int n;
int main(){
	string s;
	set<string> ss;
	set<string>::iterator it;
	std::ios::sync_with_stdio(false);
	cin>>n;
	getline(cin,s);
	for(int i=1;i<=n;++i){
		getline(cin,s);
		ss.insert(s);
	}
	cout<<ss.size();
	return 0;
}

Measured memory_bytes: 19144
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int N ,A ,B;
    cin >> N >> A >> B;
    if (A*N>=B){
        std::cout << B << std::endl;
    }
    else{
        std::cout << A*N << std::endl;
    }
    
}

Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

typedef long long ll;

#define MOD 1000000007

class Comb{
private:
  ll *fac,*finv,*inv;
public:
  Comb(){
    fac = new ll[1000000];
    finv = new ll[1000000];
    inv = new ll[1000000];
    fac[0] = 1;
    for(int i=1;i<1000000;i++){
      fac[i] = i*fac[i-1];
      fac[i] %= MOD;
    }
    inv[1] = 1;
    for(int i=2;i<1000000;i++){
      inv[i] = MOD-inv[MOD%i]*(MOD/i)%MOD;
    }
    finv[0] = 1;
    for(int i=1;i<1000000;i++){
      finv[i] = inv[i]*finv[i-1];
      finv[i] %= MOD;
    }
  }
  ll calc(ll n,ll k){
    ll c = fac[n];
    c *= finv[k];c %= MOD;
    c *= finv[n-k];c %= MOD;
    return c;
  }
};

ll gcd(ll x,ll y){
  if(x%y == 0) return y;
  else return gcd(y,x%y);
}
int main(){
  int h,w;
  cin >> h >> w;
  char s[h][w];
  vector<int> graph[h*w];
  int convert[h][w];
  ll ans = 0;
  int temp = 0;
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      cin >> s[i][j];
      convert[i][j] = temp;
      temp++;
    }
  }
  ll dist[temp][temp];
  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      if(s[i][j] == '#') continue;
      if(0 <= i-1 && s[i-1][j] == '.'){
        graph[convert[i][j]].push_back(convert[i-1][j]);
      }
      if(0 <= j-1 && s[i][j-1] == '.'){
        graph[convert[i][j]].push_back(convert[i][j-1]);
      }
      if(i+1 < h && s[i+1][j] == '.'){
        graph[convert[i][j]].push_back(convert[i+1][j]);
      }
      if(j+1 < w && s[i][j+1] == '.'){
        graph[convert[i][j]].push_back(convert[i][j+1]);
      }
    }
  }

  for(int i=0;i<h*w;i++){
    for(int j=0;j<h*w;j++){
      dist[i][j] = MOD;
    }
  }

  for(int i=0;i<h*w;i++){
    dist[i][i] = 0;
    for(int j=0;j<graph[i].size();j++){
      dist[i][graph[i][j]] = 1;
    }
  }

  for(int k=0;k<h*w;k++){
    for(int i=0;i<h*w;i++){
      for(int j=0;j<h*w;j++){
        dist[i][j] = min(dist[i][j],dist[i][k]+dist[k][j]);
      }
    }
  }
  for(int i=0;i<h*w;i++){
    for(int j=0;j<h*w;j++){
      if(dist[i][j] == MOD) continue;
      ans = max(ans,dist[i][j]);
    }
  }

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


Measured memory_bytes: 1536
import sys

N = int(sys.stdin.readline())
V = list(map(int,sys.stdin.readline().split()))
C = list(map(int,sys.stdin.readline().split()))

ans = 0

for i in range(N):
  if V[i] > C[i]:
    ans += V[i]
    ans -= C[i]

print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<stdio.h>
using namespace std;

int main(){
  for (int i = 1; i <= 9; i++) {
    for (int j = 1; j <= 9; j++) {
      printf("%dx%d=%d\n", i, j, i * j);
    }
  }
  return 0;
}

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

int32_t main(){

   int n, p = 2019;
   string s;
   cin >> s;
   n = (int)(s.size());

   long long ans = 0;

      vector<int> a(n);
      int pw = 1;
      for (int i = n-1; i >= 0; --i)
      {
         a[i] = (s[i]-'0');
         a[i] *= pw;
         a[i] %= p;
         pw *= 10;
         pw %= p;
      }

      map<int, int> freq;
      freq[0] = 1;

      int sum = 0;
      for (int i = 0; i < n; ++i)
      {
         sum += a[i];
         sum %= p;
         if(freq.count(sum)){
            ans += freq[sum];
         }  
         freq[sum]++;
      }

   cout<<ans;

   return 0;
}


Measured memory_bytes: 4364
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<math.h>
using namespace std;
const int maxn=4;
int n,num[maxn][maxn];
int a[4],b[4];
int main(){
	int i,j,k;
	for(i=1;i<=3;i++){
		for(j=1;j<=3;j++)
			scanf("%d",&num[i][j]);
	}
	int flag1=1,flag2,sum=0;
	for(i=0;i<=num[1][1];i++){
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));
		flag2=1;
		a[1]=i;b[1]=num[1][1]-i;
		a[2]=num[1][2]-b[1];
		a[3]=num[1][3]-b[1];
		b[2]=num[2][1]-a[1];
		b[3]=num[3][1]-a[1];
		for(j=1;j<=3;j++){
			if(a[j]<0){
				flag2=0;
				break;
			}
			if(b[j]<0){
				flag2=0;
				break;
			}
		}
		for(j=2;j<=3;j++){
			for(k=2;k<=3;k++){
				if(num[j][k]!=a[k]+b[j])
					flag2=0;
			}
		}
		if(flag2==0){
			sum++;
		}
	}
	if(sum==num[1][1]+1)
		flag1=0;
	if(flag1)
		printf("Yes\n");
	else
		printf("No\n");
	return 0;
} 

Measured memory_bytes: 128
import math as m

# f = open('input', 'r')
# P = list(map(lambda x: float(x)/100, f.readline().split()))
# Q = list(map(lambda x: float(x)/100, f.readline().split()))
P = list(map(lambda x: float(x)/100, input().split()))
Q = list(map(lambda x: float(x)/100, input().split()))


def calc(x):
    prob = [max(p*x, q*(1-x)) for p, q in zip(P, Q)]
    return sum(prob)

phi = (1 + m.sqrt(5)) / 2
l, r = 0, 1
x1, x2 = (l*phi + r)/(1 + phi), (l + r*phi)/(1 + phi)
f1, f2 = calc(x1), calc(x2)

while True:
    if f1 > f2:
        l, x1 = x1, x2
        x2 = (l + r*phi)/(1 + phi)
        f1, f2 = f2, calc(x2)
    else:
        x2, r = x1, x2
        x1 = (l*phi + r)/(1 + phi)
        f1, f2 = calc(x1), f1

    if abs(l-r) < 1e-12:
        break
print('%.12lf' % f1)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
#define res register int
#define ll long long
//#define cccgift
//#define getchar()(p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++)
//char buf[1<<21],*p1=buf,*p2=buf;
template<typename T>
inline void read(T &x)
{
    static char ch;bool f=1;
    for(x=0,ch=getchar();!isdigit(ch);ch=getchar()) if(ch=='-') f=0;
    for(;isdigit(ch);x=(x<<1)+(x<<3)+(ch^48),ch=getchar());x=f?x:-x;
}
template<typename T>
void print(T x)
{
    if (x<0) x=-x,putchar('-');
    if (x>9) print(x/10);
    putchar(x%10+48);
}
template<typename T>
inline void print(T x,char ap) {print(x);if (ap) putchar(ap);}
template<typename T>
inline void chkmax(T &x,const T &y) {x=x<y?y:x;}
template<typename T>
inline void chkmin(T &x,const T &y) {x=x<y?x:y;}
int n,tong[10][10],tot;
int main()
{
	ios::sync_with_stdio(false);
	cin>>n;
	for(res i=1;i<=n;++i) {
		int now=i%10,now1=i;
		while(now1>9) now1/=10;
		++tong[now1][now];
	}
	for(res i=1;i<=9;++i)
	  for(res j=1;j<=9;++j) tot+=tong[i][j]*tong[j][i];
	cout<<tot<<'\n';
	cout<<flush;
	return 0;
}
/* stuff you should look for
    * int overflow, array bounds
    * special cases (n=1?), set tle
    * do something instead of nothing and stay organized
*/ 

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int n;
  int i,j,k;
  int build[4][3][10]={{{}}};
  cin >> n;
  int b,f,r,v;
  for(i=0;i<n;i++){
    cin >> b >> f >> r >> v;
    build[b-1][f-1][r-1]+=v;
  }
  for(i=0;i<4;i++){
    for(j=0;j<3;j++){
      for(k=0;k<10;k++){
	cout << " ";
	cout << build[i][j][k];
      }
      cout << endl;
    }
    if(i<3)cout << "####################" << endl;
  }
  return 0;
}


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

#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,b,a) for(int i = (b) - 1; i >= (a); i--)
#define ITER(it, a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a, value) memset(a, value, sizeof(a))

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

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> PII;

const double PI = acos(-1.0);
const LL INF = 1000 * 1000 *1000 + 7;
const LL LINF = INF * (LL)INF;

const int MAX = 200200;
const int MIN = 4040;
const int MOD = 1000 * 1000 * 1000 + 7;

PII A[MAX];
int D[MIN][MIN];
int C[MIN * 2][MIN];

int main()
{
	//freopen("in.txt","r", stdin);
	//ios::sync_with_stdio(false); cin.tie(0);

	FOR (i, 0, MIN * 2)
	{
		C[i][0] = 1;
		FOR (j, 1, min(MIN, i+1))
		{
			C[i][j] = C[i-1][j] + C[i-1][j-1];
			if (C[i][j] >= MOD) C[i][j] -= MOD;
		}
	}


	int n;
	scanf("%d", &n);
	FOR (i, 0, n)
	{
		int x, y;
		scanf("%d%d", &x, &y);
		A[i] = MP(x, y);

		D[MIN / 2 - x][MIN / 2 - y]++;
	}

	FOR (i, 0, MIN - 1)
	{
		FOR (j, 0, MIN - 1)
		{
			D[i+1][j] += D[i][j];
			D[i][j+1] += D[i][j];

			if (D[i+1][j] >= MOD) D[i+1][j] -= MOD;
			if (D[i][j+1] >= MOD) D[i][j+1] -= MOD;
		}
	}

	LL res = 0;
	FOR (i, 0, n)
	{
		res += D[A[i].first + MIN / 2][A[i].second + MIN / 2];
		res -= C[A[i].first * 2 + A[i].second * 2][A[i].first * 2];
	}

	res %= MOD;
	if (res < 0) res += MOD;

	int half = 500000004;

	res *= half;
	res %= MOD;
	cout<<res<<endl;

}


Measured memory_bytes: 191616
#include <iostream>
#include <string>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
using namespace std;

#define MOD 1000000007

using ll = long long;


int main(void) {
    long n,z,w;
    cin >> n >> z >> w;
    
    vector<long> yama;
    for(int i=0;i<n;i++){
        long x;
        cin >> x;
        yama.push_back(x);
    }
    if(n==1){
        cout << abs(yama[0] - w) << endl;
        return 0;
    }
    long ans;
    if(abs(yama[n-1]-w) >= abs(yama[n-2] - yama[n-1])){
        ans = abs(yama[n-1] - w);
    }else{
        ans = abs(yama[n-2] - yama[n-1]);
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int a,b;

  scanf("%d %d", &a, &b);

  if(a > 12){
    printf("%d\n",b);
  } else if(a < 6){
    printf("0\n");
  } else {
    printf("%d\n", b/2);
  }

  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
#include<climits>
#include<vector>
#include<utility>
#include<cmath>
#include<cstring>
#include<map>
#include<sstream>
 
using namespace std;

int N;

int main(){
  
  cin>>N;
  
int i = 1000;
  
  while((i - N) < 0){
    i += 1000;
  }
  
  cout << (i - N) << endl;
  
}


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

/**
 * @brief nの階乗（組み合わせ数）<br>
 * intで出力できるのは13まで
 */
template<typename T>
T factorial(T n) {
  if (!n)
    return 1;
  for (T i = n - 1; i > 1; --i)
    n *= i;
  return n;
}

int main() {
  int N;
  cin >> N;
  int P{}, Q{};
  for (int i{}; i < N; ++i) {
    int p;
    cin >> p;
    P *= 10;
    P += p;
  }
  for (int i{}; i < N; ++i) {
    int q;
    cin >> q;
    Q *= 10;
    Q += q;
  }

  vector<int> index(N);
  iota(index.begin(), index.end(), 1);

  int count = factorial(N);
  vector<int> numbers;
  do {
    int v{};
    for (int i{}; i < N; ++i) {
      v *= 10;
      v += index[i];
    }
    numbers.push_back(v);
  } while (next_permutation(index.begin(), index.end()));
  sort(numbers.begin(), numbers.end());

  int a{}, b{};
  for (int i{}; i < count; ++i) {
    if (numbers[i] == P) {
      a = i;
      break;
    }
  }
  for (int i{}; i < count; ++i) {
    if (numbers[i] == Q) {
      b = i;
      break;
    }
  }

  cout << abs(a - b) << endl;
  return 0;
}


Measured memory_bytes: 3764
#include <bits/stdc++.h>
//#pragma GCC optimize ("Ofast")

using namespace std;
#define ms(x,a) memset(x,a,sizeof x)
typedef long long ll;
typedef pair<int,int> pii;
const int mod=1e9+7,seed=131,MAXN=0;

int main(){
    cin.tie(0)->sync_with_stdio(0);
    int n; cin >> n;
    cout << (1000-(n%1000))%1000 << '\n';
}

Measured memory_bytes: 3656
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            StringBuilder sb = new StringBuilder();

            while (true)
            {
                int n = int.Parse(Console.ReadLine());

                if (n == 0) break;

                int[,] dp = new int[n, n];
                int max = 0;

                string input = Console.ReadLine();

                for (int j = 0; j < n; j++)
                {
                    dp[0, j] = input[j] == '.' ? 1 : 0;
                }

                for (int i = 1; i < n; i++)
                {
                    input = Console.ReadLine();

                    for (int j = 0; j < n; j++)
                    {
                        if (input[j] == '*')
                        {
                            dp[i, j] = 0;
                        }
                        else
                        {
                            dp[i, j] = 1;

                            if (j == 0) continue;

                            dp[i, j] = Math.Min(dp[i - 1, j], dp[i, j - 1]);
                            dp[i, j] = Math.Min(dp[i, j], dp[i - 1, j - 1]) + 1;
                            max = Math.Max(max, dp[i, j]);
                        }
                    }
                }
                sb.AppendLine(max.ToString());
            }
            Console.Write(sb);
        }
    }
}

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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

ll A[200005];
ll B[200005];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, M;
    cin >> N;
    REP(i, N) {
        cin >> A[i];
    }
    cin >> M;
    REP(i, M) {
        cin >> B[i];
    }

    vector<ll> v;
    REP(i, N) {
        auto it = lower_bound(B, B + M, A[i]);
        if (A[i] != *it)
            v.push_back(A[i]);
    }
    REP(i, M) {
        auto it = lower_bound(A, A + N, B[i]);
        if (B[i] != *it)
            v.push_back(B[i]);
    }
    sort(v.begin(), v.end());
    REP(i, v.size()) {
        cout << v[i] << endl;
    }
    return 0;
}


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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;

ll dx[2] = {-1, 1};
ll dy[2] = {-1, 1};

int main(){

    vector<ll > ABC(3, 0);
    cin >> ABC[0] >> ABC[1] >> ABC[2];
    sort(ABC.begin(), ABC.end());

    ll K;
    cin >> K;

    cout << ABC[0] + ABC[1] + pow(2, K) * ABC[2] << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>

int k;
static int antennas[5];
int max_dis = 0;
int min_dis = 124;

static const char* search_upper_distance(int k, int n) {
    for (int i = n; i < 4; i++) {
        if (abs(antennas[n]-antennas[i+1]) > k) {
            return ":(";
        }
    }
    return "Yay!";
}

int main() {
    for (int i = 0; i < 5; i++) {
        std::cin >> antennas[i]; 
    }
    std::cin >> k;
    
    for (int i = 0; i < 5; i++) {
        const char *t = search_upper_distance(k, i);
        std::string m = t;
        if (m == ":(") {
            std::cout << ":(" << std::endl;
            return 0;
        }
    }
    std::cout << "Yay!" << std::endl;
    return 0;
    
}


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

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

int N;
string S;

int main()
{
    cin >> N >> S;
    int cnt = 0;
    rep(i, N - 2)
    {
        if (S[i] == 'A' && S[i + 1] == 'B' && S[i + 2] == 'C')
        {
            cnt++;
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <map> // pair
using namespace std;
int main(){
  string A,B,C;
  cin>>A>>B>>C;
  string ans="NO";
  if(A.at(A.size()-1)==B.at(0)&&B.at(B.size()-1)==C.at(0))ans="YES";
  cout<<ans<<endl;
  }


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
using llong = long long;

llong h, w;
llong a[100][100];
llong b[100][100];
llong v[100][100];
llong u[100][100];
bool dp[26000][100][100];
llong offset = 13000;

int main() {
    cin >> h >> w;
    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            cin >> a[i][j];
        }
    }
    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            cin >> b[i][j];
        }
    }

    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            v[i][j] = a[i][j] - b[i][j];
            u[i][j] = b[i][j] - a[i][j];
        }
    }

    dp[offset][0][0] = true;
    dp[offset][0][1] = true;
    dp[offset][1][0] = true;
    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            for (int k = 0; k < 26000; k++) {
                if (dp[k][i - 1][j] == true) {
                    dp[k + v[i][j]][i][j] = true;
                    dp[k + u[i][j]][i][j] = true;
                }
                if (dp[k][i][j - 1] == true) {
                    dp[k + v[i][j]][i][j] = true;
                    dp[k + u[i][j]][i][j] = true;
                }
            }
        }
    }

    llong ans = 1ll << 60ll;
    for (int k = 0; k < 26000; k++) {
        if (dp[k][h][w] == true) {
            ans = min(ans, llabs(k - offset));
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 252416
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;

using ll = long long;
using ld = long double;
const int INF = 1e9;
const double EPS = 1e-9;
const ll MOD = 1e9 + 7;

int from[] = {0, 1, 1, 2}, to[] = {1, 0, 2, 1};

int main()
{
  int n, m;
  vector<int> c(16);
  c[0] = 1;
  for (int i = 0; i < 15; ++i)
    c[i + 1] = c[i] * 3;
  while (cin >> n >> m, n || m)
  {
    int cups = 0;
    for (int i = 0; i < 3; ++i)
    {
      int cnt;
      cin >> cnt;
      for (int j = 0; j < cnt; ++j)
      {
        int t;
        cin >> t;
        t--;
        cups += i * c[t];
      }
    }

    vector<int> check(15000000, -1);
    check[cups] = 0;

    queue<int> q;
    q = queue<int>();
    q.emplace(cups);

    while (!q.empty())
    {
      auto now_cups = q.front();
      q.pop();

      vector<int> tray(3, -1);
      int tmp = now_cups;
      for (int i = 0; i < n; ++i)
      {
        tray[tmp % 3] = i;
        tmp /= 3;
      }

      for (int i = 0; i < 4; ++i)
      {
        int from_cup = tray[from[i]], to_cup = tray[to[i]];
        if (from_cup > to_cup)
        {
          auto next_cups = now_cups + (to[i] - from[i]) * c[from_cup];
          if (check[next_cups] == -1)
          {
            q.emplace(next_cups);
            check[next_cups] = check[now_cups] + 1;
          }
        }
      }
    }
    int left = 0, right = 0;
    for (int i = 0; i < n; ++i)
      right += 2 * c[i];
    if (min(check[left], check[right]) <= m)
      cout << min(check[left], check[right]) << endl;
    else
      cout << -1 << endl;
  }

  return 0;
}



Measured memory_bytes: 61456
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll MOD=1e9+7;
int n;
ll a[200005],tot,ans;
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		tot+=a[i];
	}
	for(int i=0;i<n;i++)
	{
		tot-=a[i];
		ans=(ans+a[i]*(tot%MOD))%MOD;
		//cout<<ans<<endl;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 5136
use std::io::*;
use std::str::FromStr;
use std::cmp;
use std::collections::HashMap;
use std::collections::HashSet;
use std::char;
use std::cmp::min;
use itertools::Itertools;
use num_integer::div_floor;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn read_tuple2<T: FromStr, S: FromStr>() -> (T, S) {
    let a = read();
    let b = read();
    (a, b)
}

fn read_tuple3<T: FromStr, S: FromStr, R: FromStr >() -> (T, S, R) {
    let a = read();
    let b = read();
    let c = read();
    (a, b, c)
}

fn count_two(n: u64) -> u64 {
    fn go(count: u64, num: u64) -> u64 {
        if num % 2 == 0 {
            go(count + 1, num / 2)
        } else {
            count
        }
    }
    go(0, n)
}

fn main() {
    let (a, b, n):(u64, u64, u64) = read_tuple3();
    let x = min(n, b - 1);
    let ans = div_floor(a * x, b) - a * div_floor(x, b);
    println!("{}", ans);
}



Measured memory_bytes: 2108
#include <bits/stdc++.h>
using namespace std;
bool IsEven(string S){
  if (S.size() % 2 != 0) return false;
  bool res = true;
  for (int i = 0; i < S.size() / 2; i++){
    if (S[i] != S[i + S.size() / 2]) res = false;
  }
  return res;
}
int main(){
  string S;
  cin >> S;
  while (1){
    S = S.substr(0,S.size() - 2);
    if (IsEven(S)){
      cout << S.size();
      break;
    }
  }
}


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

typedef long long ll;
const ll mod = 1e9 + 7;

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

    vector<int> to, val;
    int r = 1;
    while(r <= n){
        int tmp = n/r;
        int reach = n/tmp;
        to.push_back(reach);
        val.push_back(tmp);
        r = reach+1;
    }

    int siz = to.size(); // O(sqrt(N)) ?

    vector<ll> cnt(siz, 1);
    for(int i = 1; i < siz; i++)    cnt[i] = to[i]-to[i-1];

    auto f = [&](int x)->int{
        return upper_bound(to.begin(),to.end(),x)-to.begin();
    };

    // memo (needless)
    vector<int> memo(siz);
    for(int i = 0; i < siz; i++)    memo[i] = f(val[i]);

    // O(sqrt(N) * K) ?
    vector<vector<ll>> dp(k, vector<ll>(siz+1, 0));
    for(int i = 0; i < siz; i++)    dp[0][i] = cnt[i];
    for(int i = 0; i+1 < k; i++){
        for(int j = 0; j < siz; j++){
            dp[i+1][0] = (dp[i+1][0] + dp[i][j]) % mod;
            dp[i+1][memo[j]] = (dp[i+1][memo[j]] - dp[i][j] + mod) % mod;
        }
        for(int j = 1; j < siz; j++){
            dp[i+1][j] += dp[i+1][j-1];
            if(dp[i+1][j] < 0)    dp[i+1][j] += mod;
            dp[i+1][j] %= mod;
        }
        for(int j = 0; j < siz; j++){
            dp[i+1][j] *= cnt[j];
            dp[i+1][j] %= mod;
        }
    }

    ll ans = 0;
    for(int i = 0; i < siz; i++)    ans += dp[k-1][i], ans %= mod;
    cout << ans << endl;

    return 0;
}


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



void solve(long long N, std::vector<long long> L){

    sort(L.begin(), L.end());

    ll ans = 0;
    for(ll i=0; i<N; i++) {
        for(ll j=i+1; j<N; j++) {
            for(ll k=j+1; k<N; k++) {
                if(L[i] != L[j] and L[j] != L[k] and L[k] != L[i]){
                if( L[i]+L[j] > L[k] ) {
                   ans ++;
                }
                }
            }
        }
    }
    cout << ans << endl;
    

}

signed main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> L(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&L[i]);
    }
    solve(N, std::move(L));
    return 0;
}


Measured memory_bytes: 3700
#include<bits/stdc++.h>
using namespace std;
#define LOCAL 0
#define lli long long int
const lli mod=1e9+7;
const lli pINF=LLONG_MAX;
const lli nINF=-LLONG_MAX;
void fast() {std::ios::sync_with_stdio(false);cin.tie(NULL);}
lli power(lli a,lli b){lli ans=1;while(b!=0){ if(b%2==1){ans*=a;ans%=mod;}b/=2;a*=a;a%=mod;} return ans;}
lli invmod(lli a) {return pow(a,mod-2);}
#define vi vector<int>
#define vlli vector<lli>
#define pb push_back
#define mp make_pair
#define F first
#define S second
const int INF=0x3f3f3f3f;
#define Pa pair<int,int>
#define si(n) scanf("%d",&n)
#define sli(n) scanf("%lld",&n)
#define printi(n) printf("%d\n",n)
#define ld long double
#define printli(n) printf("%lld\n",n)
#define all(v) v.begin(),v.end()
#define forn(i,n) for(int i=0;i<n;i++)
void print(int a[],int n){for(int i=0;i<n;i++) cout<<a[i]<<" ";}
int a[2][105];
int dp[2][105];

int main() {
    int n;
    si(n);
    
    for(int i=0;i<2;i++){
        for(int j=0;j<n;j++) si(a[i][j]);
    }
    
    dp[0][0]=a[0][0];
    
    for(int i=1;i<n;i++) dp[0][i]=dp[0][i-1]+a[0][i];
    dp[1][0]=a[1][0]+a[0][0];
    
    for(int i=1;i<n;i++) dp[1][i]=max(dp[1][i-1],dp[0][i])+a[1][i];
    
    cout<<dp[1][n-1]<<endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
num = 1
flag = 0
c=list(map(int, input().split()))
for i in c:
    if i == 0:
        flag = 1
        print("0")
if flag == 0:
    for i in c:
        num *= i
        if num > 1000000000000000000:
            print("-1")
            flag =1
            break
if flag == 0:

    print(num)

Measured memory_bytes: 21644
#include <iostream>

using namespace std;


int main(int argc, char const* argv[])
{
	int w,n;
	int a[30],b[30];
	int answer[31];

	cin >> w;

	for( int i = 0;i < 30;i++ ){
		a[i] = b[i] = 0;
		answer[i+1] = 0;
	}

	cin >> n;

	char comma;
	for( int j = 0;j < n;j++ ) cin >> a[j] >> comma >> b[j];

	int status;
	for( int i = 1;i <= w;i++ ){
		status = i;
		for( int j = 0;j < n;j++ ){
			if( a[j] == status ) status = b[j];
			else if( b[j] == status ) status = a[j];
		}
		answer[status] = i;
	}

	for( int i = 1;i <= w;i++ ) cout << answer[i] << endl;


	return 0;
}

Measured memory_bytes: 0