akhauriyash/Code-Regression huggingface dataset:
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
//#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//const int mod = 1e9 + 7;
const int N = 1200000;
vector < int > v;
int x[N], y[N];
int prime(int x){
    for (int i = 2; i * i <= x; i++){
        if (x % i == 0) return 0;
    }
    return 1;
}
int binpow(int x, int y, int mod){
    int res = 1;
    while(y){
        if (y % 2) res = res * x % mod;
        x = x * x % mod;
        y /= 2;
    }
    return res;
}
const int K = 2;
const int base = 6495109;
map < vector < int >, int > t;
int p[N][K], h[N][K], invp[N][K], m[K], d[N];
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    int n;
    cin >> n;
    string s;
    cin >> s;
    int cnt = 0;
    int x = 1e9 + 1e8 + 6537;
    for (int i = x; cnt < K; i++){
        if (prime(i)){
            m[cnt] = i;
            cnt++;
        }
    }
    for (int i = 0; i < K; i++){
        p[0][i] = 1;
        invp[0][i] = 1;
        int x = binpow(base, m[i] - 2, m[i]);
        for (int j = 1; j < N; j++){
            p[j][i] = p[j - 1][i] * base % m[i];
            invp[j][i] = invp[j - 1][i] * x % m[i];
        }
    }
    for (int j = 0; j < K; j++){
        int c = 0;
        for (int i = 0; i < n; i++){
            if (s[i] == '<'){
                c++;
                h[i][j] = (i != 0) * h[i - 1][j];
            }
            else if(s[i] == '>'){
                c--;
                h[i][j] = (i != 0) * h[i - 1][j];
            }
            else if(s[i] == '+'){
                if (c >= 0) h[i][j] = ((i != 0) * h[i - 1][j] + p[c][j]) % m[j];
                else h[i][j] = ((i != 0) * h[i - 1][j] + invp[-c][j]) % m[j];
            } else{
                if (c >= 0) h[i][j] = ((i != 0) * h[i - 1][j] - p[c][j] + m[j]) % m[j];
                else h[i][j] = ((i != 0) * h[i - 1][j] - invp[-c][j] + m[j]) % m[j];
            }
            d[i] = c;
        }
    }
    vector < int > q1;
    for (int j = 0; j < K; j++){
        q1.pb(h[n - 1][j]);
    }
    int ans = 0;
    t[q1]++;
    for (int i = 0; i < n; i++){
        vector < int > q2;
        for (int j = 0; j < K; j++){
            q2.pb(h[i][j]);
        }
        ans += t[q2];
        for (int j = 0; j < K; j++){
            int y;
            if (d[i] > 0) y = p[d[i]][j];
            else y = invp[-d[i]][j];
            q2[j] = (q1[j] * y + q2[j] + m[j]) % m[j];
        }
        t[q2]++;
    }
    cout << ans;
}


Measured memory_bytes: 104212
#!/usr/bin/env python3
# coding: utf-8

class Dice() :
    rightlist = ((-1,3,1,4,2,-1),
                 (2,-1,5,0,-1,3),
                 (4,0,-1,-1,5,1),
                 (1,5,-1,-1,0,4),
                 (3,-1,0,5,-1,2),
                 (-1,2,4,1,3,-1))

    def __init__(self, data):
        self.label = data

    def get_up(self):
        return self.label[0]

    def get_rightdata(self, up, front):
        upidx = self.label.index(up);
        fridx = self.label.index(front)
        return self.label[self.rightlist[fridx][upidx]]


dicedata = input().split()
count = int(input())
queslist = []
[queslist.append(input().split()) for i in range(count)]

newdice = Dice(dicedata)

[print(newdice.get_rightdata(queslist[i][0], queslist[i][1])) for i in range(count)]



Measured memory_bytes: 5608
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
long long w[101010];
long long x[101010],mx[101010],mx2[101010];
int main()
{
	int n,i;
	long long c,sum,tmp,ans;
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	scanf("%d%lld",&n,&c);
	for(i=1;i<=n;i++)
		scanf("%lld%lld",&x[i],&w[i]); 
	x[n+1]=c;
	tmp=0;
	for(i=n;i>=1;i--)
	{
		tmp=tmp-(x[i+1]-x[i])+w[i];
		mx[i]=max(mx[i+1],tmp);
		mx2[i]=max(mx2[i+1],tmp-(c-x[i]));
//		printf("%d %lld\n",i,mx[i]);
	}
	ans=mx[1];
	sum=0;
	for(i=1;i<=n;i++)
	{
		sum=sum-(x[i]-x[i-1])+w[i];
//		printf("%d %lld %lld\n",i,sum,mx[i+1]);
		ans=max(ans,sum);
		ans=max(ans,sum+mx2[i+1]);
		ans=max(ans,sum+mx[i+1]-x[i]);
	}
	printf("%lld\n",ans);
 	return 0;
}


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

using ll = long long;
using vi = vector<int>;
using vi2 = vector<vector<int>>;
#define MP(a,b) make_pair((a),(b))
#define MT(...) make_tuple(__VA_ARGS__)

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

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl;

#define DCOUT(x,n) cout << fixed << setprecision(n) << (x) << endl;

#define sz(x) (int)(x).size()
#define HOGE cout << "hoge" << endl;

template<typename T>inline istream& operator>>(istream&i,vector<T>&v)
{REP(j,sz(v))i>>v[j];return i;}

const int INF = 1e9;

int gcd (ll a, ll b){
    if(a<b) swap(a,b);
    if(a%b==0){
        return b;
    }
    
    return gcd(a%b,b);
}
    
int main(){
    ll N;
    cin >> N;
    vector<string> s(N);
    REP(i,N){
        cin >> s[i];
        sort(s[i].begin(),s[i].end());
    }
    
    sort(s.begin(),s.end());
    s.push_back("");
    
    vector<ll> num;
    ll count = 1;
    
    REP(i,N){
        if(s[i]!=s[i+1]){
            num.push_back(count);
            count = 1;
        }
        else count ++ ;
    }
    
    ll ans = 0;
    REP(i,num.size()){
        ans += num[i]*(num[i]-1)/2;
    }
    
    cout << ans << endl;
}

Measured memory_bytes: 9072
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = 1000000007;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

template<typename T>
vector<T> gen_v(size_t a) { return vector<T>(a); }
template<typename T, typename ...Ts>
auto gen_v(size_t a, Ts... ts) { return vector<decltype(gen_v<T>(ts...))>(a, gen_v<T>(ts...)); }
template<typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }
template<typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v) { for (auto &e : t) fill_v(e, v); }

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

	int N, M; cin >> N >> M;
	vector<vector<int>> G(N);
	vector<int> a(M), b(M); rep(i, 0, M) {
		cin >> a[i] >> b[i];
		a[i]--, b[i]--;
		G[a[i]].push_back(b[i]);
		G[b[i]].push_back(a[i]);
	}
	int Q; cin >> Q;
	vector<int> v(Q), d(Q), c(Q); rep(i, 0, Q) {
		cin >> v[i] >> d[i] >> c[i];
		v[i]--;
	}

	auto dp = gen_v<int>(N, 11);

	vector<int> ans(N);

	rrep(i, 0, Q) {
		using T = tuple<int, int>;
		queue<T> q;
		q.emplace(d[i], v[i]);
		while (q.size()) {
			int d, v; tie(d, v) = q.front(); q.pop();
			if (dp[v][d] != 0)continue;
			if (ans[v] == 0)ans[v] = c[i];
			rep(e, 0, d + 1)
				dp[v][e] = c[i];
			if (d == 0)continue;
			for (auto x : G[v])
				q.emplace(d - 1, x);
		}
	}

	rep(i, 0, N) {
		cout << ans[i] << endl;
	}




	return 0;
}

Measured memory_bytes: 24692
#include<bits/stdc++.h>
#define dbug printf("I am here\n");
#define Fast ios_base::sync_with_stdio(false); cin.tie(0);
#define vs              v.size()
#define sot(v)        sort(v.begin(),v.end())
#define rev(v)        reverse(v.begin(),v.end())
#define ii                pair<int, int>
#define int              long long
#define ull              unsigned long long
#define pb              push_back
#define mpp          make_pair
#define Okay         0
#define pi               3.14159

const int inf = 1e6;
const int cont = 1e18;
using namespace std;

void solve(){
    int n;
    int a, b, c,d;
    cin>>a>>b>>c>>d;
    int x = max(a*c , b*d);
    int y = max(a*d, b*c);
   cout<<max(x,y);
}

int32_t main() {
   Fast;
//   int tst;
//   cin>>tst;
//   while(tst--)
    solve();
    return Okay;
}



Measured memory_bytes: 3656
#include <stdio.h>
#include <iostream>
#include <string.h>
using namespace std;
string str;
long long int ans;
int f[105];

void fun(int t,int len)
{
    if(t == len)
    {
      //  for(int i=0;i<len;i++)
       //     cout<<f[i]<<" ";
       // cout<<endl;
        long long int sum = str[0]-'0',kk=0,fl =0;
        for(int i=1;i<len;i++)
        {
            if(f[i] == 0){
                fl += sum;
                sum = str[i]-'0';
               // cout<<sum<<" ";
               kk = 1;
            }else{
               kk=0;
               sum = sum*10+(str[i]-'0');
            }
        }
        if(kk == 1 || kk==0&&f[len-1]==1) fl+=sum;
        //cout<<"****"<<fl<<" "<<sum<<" "<<kk<<endl;
        ans+= fl;
        return ;
    }
    f[t]=1;
    fun(t+1,len);
    f[t]=0;
    fun(t+1,len);

}
int main()
{
    memset(f,0,sizeof(f));
    cin>>str;
    ans = 0;
    int len = str.length();
    f[0]=1;
    fun(1,len);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
c = [list(map(int,input().split())) for _  in range(3)]
d = set()
e = set()
f = set()
g = set()
for i in range(3):
    d.add(c[i][0] - c[i][1])
    e.add(c[i][1] - c[i][2])
    f.add(c[0][i] - c[1][i])
    g.add(c[1][i] - c[2][i])
if len(d) == len(e) == len(f) == len(g) == 1:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 9104
/************************************************************
	> File Name: a.cpp
	> Author: TSwiftie
	> Mail: 2224273204@qq.com 
	> Created Time: Mon 09 Dec 2019 05:59:44 PM CST
************************************************************/

#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <iomanip>
//#include <unordered_map>
#define lowbit(x) (x&-x)
#define lc (o<<1)
#define rc (o<<1|1)
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const int INF = 0x3f3f3f3f;
const int MAXN = 1e5+5;
const int MAXM = 2e5+5;
const int MOD = 1e9+7;
const int dir[4][2] = {1,0,-1,0,0,1,0,-1};
const double PI = acos(-1.0);
const double EXP = 1e-8;
int main(void){
	int a, b, c;
	while(~scanf("%d%d%d",&a,&b,&c)){
		if(a+b+c>=22)
			printf("bust\n");
		else
			printf("win\n");
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
using namespace std;
int main()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);

	freopen("output.txt", "w", stdout);
#endif

	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

	ll n;
	cin >> n;

	for (ll i = -118; i <= 119; i++)
	{
		for (ll j = -119; j <= 118; j++)
		{
			if ((pow(i, 5) - pow(j, 5)) == n)
			{
				cout << i << " " << j;
				return 0;
			}
		}
	}

}



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

int ab(int x){
  return (x>0)?x:-x;
}

int main(){
  int tt;
  cin >> tt;
  for(int times=0; times<tt; ++times){
    int m,n;
    cin >>m >>n;

    int sqsum=m*m+n*n;
    //printf("sqsum=%d\n", sqsum);

    bool prime=true;
    for(int i=-141; i<=141; ++i){
      for(int j=-141; j<=141; ++j){
        if( (i==0&&j==0) || (ab(i)==1&&j==0) || (i==0&&ab(j)==1) || (i==m&&j==n)|| (i==-n&&j==m)|| (i==-m&&j==-n)|| (i==n&&j==-m)  ) continue;

        int tmp=i*i+j*j;

        if(sqsum%(i*i+j*j)==0 && ((i*m+j*n)%tmp==0)&&((i*n-j*m)%tmp==0)){
          prime=false;
          //printf("i=%d, j=%d\n", i, j);
          break;
        }
      }
      if(!prime) break;
    }

    if(prime) printf("P\n");
    else printf("C\n");

  }
}

Measured memory_bytes: 1120
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>

using namespace std;

int main() {
	string S;
	cin >> S;
	int a = 0, b = 0, c = 0;
	for (int i = 0; i < 3; i++) {
		if (S[i] == 'a') a++;
		else if (S[i] == 'b') b++;
		else if (S[i] == 'c') c++;
	}
	if (a == 1 && b == 1 && c == 1) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3564
// doot diddly donger cuckerino Hahahahahah


#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx")
#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace __gnu_cxx;
using namespace std;

using ll = long long;
using ld = long double;
using pll = pair<ll, ll>;
using vi = vector<int>;

template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

const ld PI = acos(-1);

template <typename T> inline T mini(T& x, T y) { return x = min(x, y); }
template <typename T> inline T maxi(T& x, T y) { return x = max(x, y); }
mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());

class BCanYouSolveThis {
public:
  
  void solve(std::istream& cin, std::ostream& cout) {
    int n, m, c;
    cin >> n >> m >> c;
    vector<int> b(m);
    for (int i = 0; i < m; ++i) {
      cin >> b[i];
    }
    int ans = 0;
    for (int i = 0; i < n; ++i) {
      int tot = c;
      for (int j = 0; j < m; ++j) {
        int x;
        cin >> x;
        tot += x * b[j];
      }
      if (tot > 0) ++ans;
    }
    cout << ans << '\n';
  }
};

int32_t main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
	BCanYouSolveThis solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 3608
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

ll mod(ll a){
  return (a % 1000000007);
}

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


int main(){
  string a = large; string b = small;
  
  rep(i,3){
    string s; cin >> s;
    
    rep(j,26){
      if(s[0] == b[j]) cout << a[j];
    }
    
  }
}
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using pint = pair<int, int>;
using ll = long long;
using ull = unsigned long long;
using vll = vector<long long>;
using pll = pair<ll, ll>;
#define FOR(i, begin, end) \
    for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) \
    for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define VREP(s, ite) for (auto ite = s.begin(); ite != s.end(); ++ite)
#define FI first
#define SE second
#define ALL(v) v.begin(), v.end()
#define endl "\n"
#define ciosup  \
    cin.tie(0); \
    ios::sync_with_stdio(false);
#define eb emplace_back
#define vint vector<int>
constexpr ll INF = 1e15 + 7LL;
constexpr ll MOD = 1e9 + 7LL;
template <typename T>
istream &operator>>(istream &is, vector<T> &v) {
    for (int i = 0; i < v.size(); ++i) {
        is >> v[i];
    }
    return is;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v) {
    if (v.size() == 0) return os;
    for (int i = 0; i < v.size() - 1; ++i) {
        os << v[i] << " ";
    }
    os << v[v.size() - 1];
    return os;
}

bool judge(vll& a, double val, ll k) {
    ll cnt = 0;
    REP(i, a.size()) {
        ll now = floor((double)a[i] / val);
        cnt += now;
    }
    if (cnt <= k) {
        return true;
    } else {
        return false;
    }
}

void solve() {
    ll n, k;
    cin >> n >> k;
    vll a(n);
    cin >> a;
    ll maxv = 0;
    REP(i, n) {
        maxv = max(maxv, a[i]);
    }
    double lo = 0.01, hi = maxv + 1.0;
    while (hi - lo > 1e-4) {
        double mid = (hi + lo) / 2.;
        if (judge(a, mid, k)) {
            hi = mid;
        } else {
            lo = mid;
        }
    }
    cout << (ll)floor(lo) + 1 << endl;
}

int main() {
    char tmp;
    while (cin >> tmp) {
        cin.putback(tmp);
        solve();
    }
}


Measured memory_bytes: 4896
#include<bits/stdc++.h>
#define ALL(c) begin(c), end(c)
using namespace std;
using ll = long long;
using ld = long double;

const int N = 1e6+6;


set<int> g[N];

int u[N];
void go(int v, int &sz){
	if(u[v]) return ;
	u[v] = 1;
	++sz;
	for(int i : g[v]) go(i, sz);
}

int main(){
	//freopen("input.txt","r",stdin); //freopen("output.txt","w",stdout);
	ios::sync_with_stdio(0);cin.tie(0);//cout.precision(12);cout<<fixed;
	
	int n, m;
	
	cin>>n>>m;
	for(int k=0,i,j;k<m;++k){
		cin>>i>>j;
		g[i].insert(j);
		g[j].insert(i);
	}
	
	int ans = 0;
	for(int i=1;i<=n;++i) if(!u[i]){
		int sz = 0;
		go(i,sz);
		ans = max(ans, sz);
	}
	
	cout<<ans<<endl;
	
	
	return 0;
}


Measured memory_bytes: 76244
//Atcoder
import java.io.*;
import java.util.*;

public class Main {

	static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            try {
                br = new BufferedReader(new InputStreamReader(System.in));
                st = new StringTokenizer(br.readLine());
            } catch (Exception e){e.printStackTrace();}
        }

        public String next() {
            if (st.hasMoreTokens()) return st.nextToken();
            try {st = new StringTokenizer(br.readLine());}
            catch (Exception e) {e.printStackTrace();}
            return st.nextToken();
        }

        public int nextInt() {return Integer.parseInt(next());}

        public long nextLong() {return Long.parseLong(next());}

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

        public String nextLine() {
            String line = "";
            if(st.hasMoreTokens()) line = st.nextToken();
            else try {return br.readLine();}catch(IOException e){e.printStackTrace();}
            while(st.hasMoreTokens()) line += " "+st.nextToken();
            return line;
        }
    }

    static class Pair implements Comparable<Pair> {
        String s;
        int v;
        int idx;
        public Pair(String s, int v, int idx) {
            this.s = s;
            this.v = v;
            this.idx = idx;
        }
        @Override
        public int compareTo(Pair p) {
            if(this.s.compareTo(p.s) == 0) {
                return p.v - this.v;
            }
            return (this.s.compareTo(p.s) < 0) ? -1 : 1;
        }
    }

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

        int n = sc.nextInt();
        Pair[] a = new Pair[n];
        for(int i=0;i<n;i++) {
            String[] s = sc.nextLine().split(" ");
            a[i] = new Pair(s[0], Integer.parseInt(s[1]), i+1);
        }
        Arrays.sort(a);

        for(int i=0;i<n;i++) pw.println(a[i].idx);

        pw.close();
    }
}


Measured memory_bytes: 21332
k, n = map(int, input().split())
a = list(map(int, input().split()))

space = []
for i in range(n - 1):
    s = a[i + 1] - a[i]
    space.append(s)
space.append(k +a[0] - a[n - 1])

print(k - max(space))


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

int main(){
  string s;
  cin >> s;
  for(int i = 0; i < (1 << 3); i++){
    bitset<3> p(i);
    int count = s[0] - '0';
    for(int j = 0; j < 3; j++){
      if(p[j]) count += (s[j + 1] - '0');
      else count -= (s[j + 1] - '0');
    }
    if(count == 7){
      cout << s[0];
      for(int k = 0; k < 3; k++){
        if(p[k]) cout << '+' << s[k + 1];
        else cout << '-' << s[k + 1];
      }
      break;
    }
  }
  cout << "=7" <<  endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
    long n;
    scanf("%ld",&n);
    long a[n];
    long e=0;
    for(long i=0;i<n;i++)scanf("%ld",&a[i]);
    for(long i=1;i<n;i++){
        if(a[i]<a[i-1]){
            e+=a[i-1]-a[i];
            a[i]=a[i-1];
        }
    }
    printf("%ld",e);
    return 0;    
}

Measured memory_bytes: 5316
#!/usr/bin/ python3.8
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
N, M = map(int, read().split())
x = M * (M - 1) // 2
x += N * (N - 1) // 2
print(x)

Measured memory_bytes: 2940
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
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.LinkedList;
import java.util.ListIterator;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.TreeSet;
 
public class Main {

	public static void main(String[] args) throws IOException {
		try (Scanner sc = new Scanner(System.in)) {
			final int N = sc.nextInt();
			final int A = sc.nextInt();
			
			System.out.println((N % 500) <= A ? "Yes" : "No");
			
			
		}
	}
	
	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;
 
		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}
 
		private void getLine() throws IOException {
			while (!hasNext()) {
				tok = new StringTokenizer(br.readLine());
			}
		}
 
		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}
 
		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}
 
		public int nextInt() throws IOException {
			return Integer.parseInt(next());
		}
 
		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}
 
		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}
 
		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for (int i = 0; i < n; i++) {
				ret[i] = this.nextInt();
			}
			return ret;
		}
 
		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for (int i = 0; i < n; i++) {
				ret[i] = this.nextLong();
			}
			return ret;
		}
 
		public void close() throws IOException {
			br.close();
		}
	}
}

Measured memory_bytes: 21332
#include <bits/stdc++.h>
using namespace std;
 const double PI=3.14159265358979323846;
int main() {
  double A,B,H,M;cin>>A>>B>>H>>M;
  double h=30*H+0.5*M;
  double m=6*M;
  double d=0;
  if(m>=h)d=m-h;
  else d=m+360-h;
  d=2.0f*PI/360.0f*d;
  cout<<fixed<<setprecision(16);
  cout<<sqrt(A*A+B*B-2.0f*A*B*cos(d))<<endl;;
}

Measured memory_bytes: 4228
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
int main()
{
    long long n,m,h[100005],i,a,b;
    cin>>n;
    for(i=-120; i<=120; i++)
    {
        for(int j=-120; j<=120; j++)
        {
            a=pow(i,5);
            b=pow(j,5);
            if((a-b)==n)
            {
                cout<<i<<" "<<j<<'\n';
                return 0;
            }
        }
    }
}



Measured memory_bytes: 4052
<?php
	
	$output = array();

	while( true ) {
		$data = trim( fgets( STDIN ) );
		if( "0" == $data ) { break; }

		$nums = str_split( $data );
		array_push( $output, array_sum( $nums ) );
	}
	print implode( "\n", $output );
?>

Measured memory_bytes: 6912
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int W = sc.nextInt();
		int H = sc.nextInt();
		int x = sc.nextInt();
		int y = sc.nextInt();
		int r = sc.nextInt();

		int north = y + r;
		int south = y - r;
		int east = x + r;
		int west = x - r;

		if((H - north >= 0) && (W - east >= 0)
				&& (south >= 0) && (west >= 0)) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

	}
}


Measured memory_bytes: 26376
import java.util.Scanner;
public class Main
{
	public static void main(String[] args)
	{
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int i = scan.nextInt();
		int result = 0;
		if(i==1 && N==1)
			result = 1;
		else	
			result = (N-i)+1; 
		System.out.println(result);
	}
}

Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
 
#define REP(i,s,n) for(int i=s;i<n;++i)
#define rep(i,n) REP(i,0,n)
#define SORT(c) sort((c).begin(),(c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
 
typedef long long ll;
typedef pair<int, int> ii;

int main() {

	int n;
	while(cin >> n, n){
		vector<string> s(n);
		rep(i, n) cin >> s[i];
		int ans = 0;
		rep(i, n-1){
			if(s[i][1] == s[i+1][1]) ans++;
		}
		cout << ans << endl;
	}

	return 0;
}

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

int main(){
  string s;
  cin >> s;
  long long int s0 = 0, s1 = 0;
  rep(i,s.size(),0){
    if(s[i] == '0') s0++;
    else s1++;
  }
  long long int ans = min(s0, s1) * 2;
  cout << ans << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
#include <tuple>
using namespace std;

int main()
{
	int M, T, P, R, m, t, p, j;
	while (cin >> M >> T >> P >> R, M || T || P || R) {
		vector< vector< pair<int, int> > > data(T + 1, vector< pair<int, int> >(P + 1, pair<int, int>(0,0)));
		vector< tuple<int, int, int> > score(T + 1);
		for (int i = 0; i < R; i++) {
			cin >> m >> t >> p >> j;
			if (j == 0) {
				data[t][p].first = m + data[t][p].second * 20;
				get<0>(score[t])--;
			}
			else {
				data[t][p].second++;
			}
		}
		for (int i = 1; i <= T; i++) {
			int sco = 0,pena = 0;
			for (int j = 0; j <= P; j++) {
				if (data[i][j].first) {
					sco--;
					pena += data[i][j].first;
				}
			}
			score[i] = tuple<int, int, int>(get<0>(score[i]),pena,-i);
		}
		sort(score.begin() + 1, score.end());
		tuple<int, int, int> temp = score[1];
		cout << -get<2>(score[1]);
		for (int i = 2; i <= T; i++) {
			if (get<0>(temp) == get<0>(score[i]) && get<1>(temp) == get<1>(score[i])) {
				cout << "=";
			}
			else {
				cout << ",";
			}
			cout << -get<2>(score[i]);
			temp = score[i];
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3076
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pf push_front

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define mp make_pair
#define fi first
#define se second
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
double pi = 3.141592653589793;
ll mod = 1000000007;
ll INF = 1000000001;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;



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

Measured memory_bytes: 256
//
//  main.cpp
//  zero
//
//  Created by 叶金炜 on 2019/4/2.
//  Copyright © 2019 okstal. All rights reserved.
//

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string.h>
#include <string>
#define pi acos(-1)
using namespace std;
int main()
{
    double a[1007];
    int n;
    while(cin>>n&&n!=0)
    {
        double m=0;
        for(int i=1;i<=n;i++){cin>>a[i];m+=a[i];}
        m/=n;
        double x=0;
        for(int i=1;i<=n;i++)x+=(a[i]-m)*(a[i]-m);
        x/=n;
        x=sqrt(x);
        printf("%.6lf\n",x);
    }
    return 0;
}



Measured memory_bytes: 3216
def f():
    H, W, A, B = map(int, input().split())
    
    for _ in range(B):
        X = ['0'] * A + ['1'] * (W-A)
        print(''.join(X))
    
    for _ in range(H-B):
        X = ['1'] * A + ['0'] * (W-A)
        print(''.join(X))

    

    
f()

    

Measured memory_bytes: 39792
fn main() {
 let mut i=input();
 let mut c=1;
 while i!=0{
  println!("Case {}: {}", c,i);
  i=input();
  c+=1
 }
}
fn input()->u32 {
 let mut b=String::new();
 let s=std::io::stdin();
 s.read_line(&mut b).unwrap();
 b.trim().parse().unwrap()
}



Measured memory_bytes: 5044
#include<cstdio>
#include<iostream>
#include<queue>
#include<string>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<set>
#include<cstdlib>
#include<stack>
#include<ctime>
#include<map>
#include<list>
using namespace std;

int a[205];

int main()
{
	int n,ans=0;
	scanf("%d",&n);
	for(int i=1; i<=2*n; i++) scanf("%d",&a[i]);
	sort(a+1,a+2*n+1);
	for(int i=1; i<=n; i++)
	{
		ans+=a[i*2-1];
	}
	printf("%d\n",ans);
 	return 0;
}


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

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define INF 1000000007LL
#define all(x) x.begin(),x.end()
#define rep(i,a,b) for(i=a;i<=b;i++)

#define cil(a,b) ( ((a)%(b) == 0)?((a)/(b)):((a)/(b)+1) )

typedef long long ll;
typedef double db;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
typedef vector<pii> vii;

ll mypow(ll a, ll b) { if(b == 0) return 1; ll temp=mypow(a,b/2); temp=(temp*temp)%INF; if(b%2 == 1) temp=(a*temp)%INF; return temp; }
int mygcd(int a, int b) { if(b==0) return a; return mygcd(b,a%b); }
int cntBits(ll a) { int ret=0; while(a>0) { ret++; a/=2; } return ret; }

ll ans[100010][2];

int main()
{
	ios::sync_with_stdio(0);
	int tt=1,tcase; 
	//cin >> tt;
	rep(tcase,1,tt)
	{
		int n; cin >> n;
		vll v(n+1);
		for(int i=1;i<=n;i++) cin >> v[i];	
		ans[1][0]=v[1]; ans[1][1]=-v[1];
		for(int i=3;i<=n;i++)
		{
			ans[i-1][0]=max(-v[i-1]+ans[i-2][1], v[i-1]+ans[i-2][0]);
			ans[i-1][1]=max(v[i-1]+ans[i-2][1], -v[i-1]+ans[i-2][0]);
		}
		cout << max(-v[n]+ans[n-1][1], v[n]+ans[n-1][0]) << "\n";
	}
	return 0;
}


Measured memory_bytes: 2560
#include<stdio.h>

int main(void){

	int a, b, c, k, ans;

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

	if(a >= k){
		ans = k;
	}
	else if(a < k && a + b >= k){
		ans = a;
	}
	else
		ans = a - (k - a - b);

	printf("%d", ans);

	return 0;
}

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

using namespace std;
typedef long long ll;

#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, a, b) for (int i = (a); i < (b); ++i)
#define all(a) (a).begin(), (a).end()
#define all2(a, b) (a).begin(), (a).begin() + (b)
#define debug(vari) cerr << #vari << " = " << (vari) << endl;

int main()
{
    int r, g, b, n;
    cin >> r >> g >> b >> n;
    int ans = 0;

    rep(i, n + 1)
    {
        rep(j, n + 1)
        {
            if ((n - (i * r + j * g)) % b == 0 && (n - (i * r + j * g)) >= 0)
            {
                ans++;
            }
        }
    }
    cout << ans << endl;
    return (0);
}


Measured memory_bytes: 3596
n,m = map(int,input().split())
a = list(map(int, input().split()))
ord = []
summ = sum(a)
isSmallThan = True
for j in range(m):
  ord.append(max(a))
  a.remove(max(a))
for k in range(m):
  if ord[k]/summ >= 1/(4*m):
    isSmallThan = True
  else:
    isSmallThan = False
    break
print('Yes' if isSmallThan else 'No')


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

typedef long long ll;

using namespace std;

const int N = 595959;
const int K = 16;

int n, ans;
int v[N];
int cnt[N];
vector<int> vec;
int dp[1 << K];

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cin >> n;
    for (int i = 0; i < n - 1; i++)
    {
        int a, b, c;
        cin >> a >> b >> c;
        v[a] ^= c, v[b] ^= c;
    }
    for (int i = 0; i < n; i++)
    {
        cnt[v[i]]++;
    }
    ans += cnt[0];
    cnt[0] = 0;
    for (int i = 0; i < 16; i++)
    {
        ans += cnt[i] / 2;
        if (cnt[i] % 2) vec.push_back(i);
    }
    //fill(dp, dp + (1 << vec.size()), N);
    dp[0] = 0;
    for (int mask = 1; mask < (1 << vec.size()); mask++)
    {
        for (int submask = mask; submask; submask = mask & (submask - 1))
        {
            int x = 0;
            for (int i = 0; i < vec.size(); i++) if ((1 << i) & submask) x ^= vec[i];
            if (x == 0) dp[mask] = max(dp[mask], dp[mask - submask] + 1);
        }
    }
    cout << n - ans - dp[(1 << vec.size()) - 1];
}


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

int main(){
  ll n, a, b;
  cin >> n >> a >> b;
  if(abs(a-b)%2 == 0){
    cout << abs(a-b) /2 << endl;
  }else{
    ll ans = min(min(a-1,n-a),min(b-1,n-b));
    ans += abs(a-b) /2 +1;
    cout << ans << endl;
  }
}

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

int gcd(int a, int b){
    int tmp, r;
    if(a<b){
        tmp = a;
        a = b;
        b = tmp;
    }
    r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}


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

    Sum = 0;
    for(int i=1; i<=K; i++){
        for(int j=1; j<=K; j++){
            for(int k=1; k<=K; k++){
                Sum += gcd(gcd(i, j), k);
            }
        }
    }
    cout << Sum << endl;
    return 0;
}

Measured memory_bytes: 3624
import java.io.*;

public class Main {

    public static void main(String[] args) {

        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));

        try {

            int cnt = 1;
            final int END = 0;
            
            while (true) {
                String line = reader.readLine();
                int num = Integer.parseInt(line);
                
                if (num == END) {
                    break;
                } else {
                    System.out.println("Case " + cnt + ": " + num);
                    cnt++;
                }
            }

        } catch (IOException e) {

            e.printStackTrace();

        }
    }

}

Measured memory_bytes: 31712
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct mahou{
  int tairyoku;
  int maryoku;
};
int main(){
  int hp = 0;
  int kazu = 0;
  cin >> hp >> kazu;
  struct mahou a[kazu];
  for(int i = 0;i <= kazu - 1;i++){
    cin >> a[i].tairyoku >> a[i].maryoku;
  }
  vector<int> dp(hp + 1);
  dp[0] = 0;
  for(int i = 1;i <= hp;i++){
    dp[i] = 1000000000;
  }
  for(int i = 1;i <= hp;i++){
    for(int j = 0;j <= kazu - 1;j++){
      if(i - a[j].tairyoku <= 0){
        dp[i] = min(dp[i],a[j].maryoku);
      }
      else{
        dp[i] = min(dp[i],dp[i - a[j].tairyoku] + a[j].maryoku);
      }
    }
  }
  cout << dp[hp] << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <stdint.h>
#include <queue>
#include <bitset>
#include <iomanip>

using namespace std;

#define PI 3.14159265358979323846
#define INF 1e+9
#define DIV_NUM (1000000007)



int main() {

	string S;
	cin >> S;
	string ans = "";

	for (int i = 0; i < S.length(); i++) {
		ans += 'x';
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(){
	int a[3];
	cin>>a[0]>>a[1]>>a[2];
	sort(a,a+3);
	if(a[0]+a[1]==a[2])cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
    return 0;
}


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

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

	if (s.compare("ABC") == 0)
	{
		cout << "ARC" << endl;
	}
	else
	{
		cout << "ABC" << endl;
	}

	return 0;
}

Measured memory_bytes: 3624
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.StringTokenizer;

public class Main {

	// Atcoder用のサンプルプログラム
	public static void main(String[] args) {
		try {
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			
			//line = br.readLine();
			
			int sum = 0;
			int max = 0;
			String temp = br.readLine();
			String N = temp.split(" ")[0];
			int n = Integer.parseInt(N);
			int M = Integer.parseInt(temp.split(" ")[1]);
			
			String[] Xtemp = br.readLine().split(" ");
			Integer[] X = new Integer[M]; 
			for (int i = 0;i < M;i++) {
				X[i] = Integer.parseInt(Xtemp[i]);
			}
			
			Arrays.sort(X);
			int x1=-999999;
			Integer[] sa = new Integer[M];
			for (int i = 0;i < M;i++) {
				int x2 = X[i];
				sa[i] = Math.abs(x2-x1);
				x1=x2;
			}
			Arrays.sort(sa);
			int sumFinal=0;
			for (int i = 0;i < M-n;i++) {
				sumFinal=sumFinal+sa[i];
			}
			System.out.println(sumFinal);
			
			
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
}


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

int main(){
  int x,y,z=1;
  while(z=1){
    cin >> x >> y;
    if(x==0 && y==0)break;
    if(x>=y){
      cout << y << " " <<  x << endl;
    } else{
      cout << x << " " << y << endl;
    }
  }
  return 0;
}



Measured memory_bytes: 3072
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Console = System.Console;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var r = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int ret = 0;
            bool flg = true;
            while (flg)
            {
                for (int i = 0; i < N; i++)
                {
                    if (r[i] % 2 != 0)
                    {
                        flg = false;
                        break;
                    }
                    r[i] = r[i] / 2;
                }

                if (flg)
                { 
                    ret++;
                }
            }
            Console.WriteLine(ret);
        }
    }
}

Measured memory_bytes: 13252
import sys
input = sys.stdin.readline
import numpy as np

N = int(input())
hight_list = np.array([int(item) for item in input().split()])

dp = np.full(N, hight_list.sum(), dtype='int64')
dp[0] = 0
dp[1] = abs(hight_list[1] - hight_list[0])

for i in range(2, N):
    cost1 = abs(hight_list[i-1] - hight_list[i])
    cost2 = abs(hight_list[i-2] - hight_list[i])
    dp[i] = min(dp[i-1] + cost1, dp[i-2] + cost2)
    # print(dp)

print(dp[N-1])


Measured memory_bytes: 23044
#include <iostream>
#include <complex>
#include <sstream>
#include <string>
#include <algorithm>
#include <deque>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <vector>
#include <set>
#include <limits>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <ctime>
using namespace std;
#define REP(i, j) for(int i = 0; i < (int)(j); ++i)
#define FOR(i, j, k) for(int i = (int)(j); i < (int)(k); ++i)
#define P pair<int, int>
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())
const int MAX_N = 110;
const int INF = 1e9 + 7;

int N, M, c[MAX_N][MAX_N][2];

class C{
  public:
    int now, cost;
    bool used;
    C(int _n, int _c, bool _u){ now = _n; cost = _c; used = _u; }
    C(){}
    bool operator > (const C &c) const { return cost > c.cost; }
};

vector<int> checkSkipNext(int now){
  vector<int> tmp;
  REP(i, N) if(c[now][i][0] != INF) tmp.push_back(i);
  set<int> s;
  REP(i, tmp.size()) REP(j, N) if(c[tmp[i]][j][0] != INF) s.insert(j);
  vector<int> ret;
  for(set<int>::iterator it = s.begin(); it != s.end(); ++it) ret.push_back((*it));
  return ret;
}

int calc(){
  priority_queue<C, vector<C>, greater<C> > open;
  open.push(C(0, 0, false));
  int closed[MAX_N][2];
  REP(i, N) REP(j, 2) closed[i][j] = INF;
  while(!open.empty()){
    C tmp = open.top(); open.pop();
    int now = tmp.now, cost = tmp.cost;
    bool used = tmp.used;
    if(cost >= closed[now][used]) continue;
    closed[now][used] = cost;
    REP(type, 2){
      REP(next, N){
        if(c[now][next][type] == INF) continue;
        if(type && !used) open.push(C(next, cost + c[now][next][type], true));
        if(type == 0) open.push(C(next, cost + c[now][next][type], used));
      }
    }
  }
  return min(closed[N - 1][0], closed[N - 1][1]);
}

int main() {
  while(cin >>N >>M && N){
    REP(i, N) REP(j, N) REP(k, 2) c[i][j][k] = INF;
    REP(i, M){
      int from, to, cost; cin >>from >>to >>cost;
      --from; --to;
      c[from][to][0] = cost;
      c[to][from][0] = cost;
    }
    REP(now, N){
      vector<int> next = checkSkipNext(now);
      REP(i, next.size()) c[now][next[i]][1] = 0;
    }
    cout <<calc() <<endl;
  }
  return 0;
}

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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

typedef long long ll;
typedef pair<ll,ll> P;

ll dp[44][1<<18][2];
void modAdd(ll &a, ll b){
	a += b;
	a %= MOD;
}

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

	ll n, x, y, z;cin >> n >> x >> y >> z;
	ll tmp = 0;
	tmp |= (1 << (x - 1));
	tmp |= (1 << (x + y - 1));
	tmp |= (1 << (x + y + z- 1));

	dp[0][0][0] = 1;
	REP(i, n){
		REP(j, (1<<18)){
			REP(k, 2)if(dp[i][j][k]){
				REP(ii, 10){
					ll nxt = ((1LL << 18) - 1) & ((j << (ii + 1)) + (1LL << ii));
					ll pla = k;
					if((nxt & tmp) == tmp)pla = 1;
					modAdd(dp[i+1][nxt][pla], dp[i][j][k]);
				}
			}
		}
	}

	ll ans = 0;
	REP(i, 1<<18)modAdd(ans, dp[n][i][1]);
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 164224
n = int(input())
s = input()
res = n
W = [1 if s[0] == 'W' else 0] * n
E = [1 if s[0] == 'E' else 0] * n
for i in range(1,n):
    if s[i] == 'W':
        W[i] = W[i-1]+1
        E[i] = E[i-1]
    else:
        W[i] = W[i-1]
        E[i] = E[i-1] + 1
for i in range(n):
    cnt = W[i] + E[-1] - E[i]
    if s[i] == 'W':
        cnt -= 1
    res = min(cnt, res)
print(res)


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

int main() {
  int N, n, a, b; //a:下一桁の数字　b:各桁の数字の和　n:Nのコピー、いじる
  b = 0;
  cin >> N;
  n = N;
  for (int i = 0; i < 8; i++) {
    a = n % 10;
    b += a;
    n /= 10;
    if (n == 0) {
      break;
    }
  }
  if (N % b == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <unordered_set>

#define DEBUG
#ifdef DEBUG
#define debug_printf printf
#else
#define debug_printf 1 ? 0 : printf
#endif

using namespace std;
typedef long long int ll;
typedef vector<ll> Vl;
typedef vector<int> Vi;
typedef pair<int, int> Pi;
typedef pair<ll, ll> Pl;

#define FST first
#define SND second

#define MAX_N   (200000)                  // 10^5
#define BASE    (1000000000 + 7)          // 10^9 + 7
#define INFI    (1000000000 + 7)          // 10^9 + 7
#define INFL    (1000000000000000000 + 7) // 10^18 + 7

int N;
Pl V[MAX_N];

ll calc_min_score() {
  if (N <= 1) return 0;

  ll rmn = INFL, rmx = 0, bmn = INFL, bmx = 0;
  for (int i = 0; i < N; i++) {
    if (V[i].FST > V[i].SND) swap(V[i].FST, V[i].SND);
    rmn = min(rmn, V[i].FST);
    rmx = max(rmx, V[i].FST);
    bmn = min(bmn, V[i].SND);
    bmx = max(bmx, V[i].SND);
  }
  ll ans = (rmx - rmn) * (bmx - bmn);

  sort(V, V + N);

  int imx = -1;
  for (int i = N - 1; i > 0; i--) {
    if (V[i].SND == bmx) {
      imx = i;
      break;
    }
  }
  if (imx < 0) return ans;

  bmn = rmn;
  ll mn = V[0].SND;
  rmx = max(V[0].SND, rmx);
  ans = min(ans, (rmx - rmn) * (bmx - bmn));
  for (int i = 1; i < imx; i++) {
    mn = min(V[i].SND, mn);
    rmn = min(mn, V[i + 1].FST);
    rmx = max(V[i].SND, rmx);
    ans = min(ans, (rmx - rmn) * (bmx - bmn));
  }

  return ans;
}

void solve() {
  cout << calc_min_score() << endl;
}

int main() {
  cin >> N;
  for (int i = 0; i < N; i++) cin >> V[i].FST >> V[i].SND;

  solve();

  return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const int inf = 1e9;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;
#define rep(i, n) for (int i = 0; i < n; i++)
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = { 1, 0, -1, 0 }, dy[4] = { 0, 1, 0, -1 };
int dxx[8] = { 1, 1, 1, 0, 0, -1, -1, -1 }, dyy[8] = { -1, 0, 1, -1, 1, -1, 0, 1 };
//宣言
int par[55] = {};

//union_find
int root (int x) {
    if (par[x] == x) return x;
    return par[x] = root (par[x]);
}

void unit (int x, int y) {
    x = root (x);
    y = root (y);
    if (y != x) par[x] = y;
}

int main() {
    //入力
    int n, m;
    cin >> n >> m;
    int a[m], b[m];
    rep (i, m) {
        cin >> a[i] >> b[i];
        a[i]--, b[i]--;
    }
    int ans = 0;
    //辺を一つぬいた時どうなるか
    rep (i, m) {
        rep (j, n) par[j] = j;
        rep (j, m) {
            if (i == j) continue;
            unit (a[j], b[j]);
        }
        int cnt = 0;
        rep (j, n) if (par[j] == j) cnt++;
        if (cnt != 1) ans++;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 256
from fractions import gcd
N = int(input())
A = list(map(int, input().split()))
MOD = 10**9+7
def lcm (x,y):
  return x*y//gcd(x,y)
 
p = A[0]
for a in A[1:]:
  p = lcm(p, a)
 
ans = 0
for a in A:
  ans += p//a
print(ans % MOD)

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<long long> vll;
typedef vector<vector<long long>> vvll;
typedef pair<int,int> pii;
typedef pair<long long, int> pli;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

ll mod = 1000000007;

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

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

  ll n;
  cin >> n;

  vll p;
  map<ll,int> cnt;

  for(ll i = 2;i*i <= n;i++){
    if(n % i == 0){
      p.push_back(i);
      while(n % i == 0){
        n /= i;
        cnt[i]++;
      }
    }
  }
  if(n != 1){
    p.push_back(n);
    cnt[n]++;
  }

  int ret = 0;
  rep(i,p.size()){
    int cur = 1;
    int pcnt = cnt[p[i]];
    while(pcnt >= cur){
      ret++;
      pcnt -= cur;
      cur++;
    }
  }

  cout << ret << endl;
}

Measured memory_bytes: 3640
#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;
    if (n % 1000 == 0) {
        cout << n % 1000 << endl;
    }
    else {
        cout << 1000 - (n % 1000) << endl;
    }
    return 0;
}


Measured memory_bytes: 3620
/*input
2 3
*/
fn pow_ext(mut a: u64, mut b: u64) -> u64 {
    // MOD 1000000007
    let mut ret: u64 = 1;
    while b > 0 {
        if b % 2 == 1 {
            ret = ret * a % 1000000007;
        }
        a = a * a % 1000000007;
        b = b / 2;
    }
    ret
}

fn main() {
    let mut input = format!("");
    std::io::stdin().read_line(&mut input).expect("");
    let v: Vec<u64> = input
        .trim()
        .split_whitespace()
        .map(|x| x.parse().expect(""))
        .collect();
    println!("{}", pow_ext(v[0], v[1]));
}



Measured memory_bytes: 5036